Skip to content

Commit 2576321

Browse files
committed
Fix compilation on redox
1 parent 595f68b commit 2576321

File tree

7 files changed

+73
-30
lines changed

7 files changed

+73
-30
lines changed

Cargo.lock

Lines changed: 32 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ clap = "2.33"
2727
rustpython-compiler = {path = "compiler", version = "0.1.1"}
2828
rustpython-parser = {path = "parser", version = "0.1.1"}
2929
rustpython-vm = {path = "vm", version = "0.1.1"}
30-
dirs = "=2.0.1"
30+
dirs = { package = "dirs-next", version = "1.0" }
3131
num-traits = "0.2.8"
3232
cfg-if = "0.1"
3333

@@ -47,10 +47,8 @@ path = "src/main.rs"
4747

4848
[patch.crates-io]
4949
# REDOX START, Uncommment when you want to compile/check with redoxer
50-
# time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" }
51-
# nix = { git = "https://github.com/coolreader18/nix", branch = "add-redox-support" }
5250
# # following patches are just waiting on a new version to be released to crates.io
53-
# socket2 = { git = "https://github.com/alexcrichton/socket2-rs", rev = "75fe3f2fe0e3079ad9d4dfb3a19e60bea3f2f055" }
54-
# rustyline = { git = "https://github.com/kkawakam/rustyline" }
55-
# libc = { git = "https://github.com/rust-lang/libc" }
51+
# nix = { git = "https://github.com/nix-rust/nix" }
52+
# crossbeam-utils = { git = "https://github.com/crossbeam-rs/crossbeam" }
53+
# socket2 = { git = "https://github.com/alexcrichton/socket2-rs" }
5654
# REDOX END

compiler/src/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ impl<O: OutputStream> Compiler<O> {
20422042

20432043
let mut compile_element = |element| {
20442044
self.compile_expression(element).map_err(|e| {
2045-
if matches!(e.error, CompileErrorType::InvalidStarExpr) {
2045+
if let CompileErrorType::InvalidStarExpr = e.error {
20462046
self.error(CompileErrorType::SyntaxError(
20472047
"iterable unpacking cannot be used in comprehension".to_owned(),
20482048
))

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ crc32fast = "1.2.0"
101101
adler32 = "1.0.3"
102102
gethostname = "0.2.0"
103103
subprocess = "0.2.2"
104-
socket2 = { version = "0.3", features = ["unix"] }
104+
socket2 = "0.3"
105105
rustyline = "6.0"
106106
openssl = { version = "0.10", features = ["vendored"], optional = true }
107107
openssl-sys = { version = "0.9", optional = true }

vm/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)]
1010
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1111
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
12+
#![cfg_attr(
13+
target_os = "redox",
14+
feature(matches_macro, proc_macro_hygiene, result_map_or)
15+
)]
1216

1317
#[cfg(feature = "flame-it")]
1418
#[macro_use]

vm/src/stdlib/os.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,18 @@ fn os_urandom(size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
13141314
#[cfg(any(target_os = "linux", target_os = "openbsd"))]
13151315
type ModeT = u32;
13161316

1317+
#[cfg(target_os = "redox")]
1318+
type ModeT = i32;
1319+
13171320
#[cfg(target_os = "macos")]
13181321
type ModeT = u16;
13191322

1320-
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "openbsd"))]
1323+
#[cfg(any(
1324+
target_os = "macos",
1325+
target_os = "linux",
1326+
target_os = "openbsd",
1327+
target_os = "redox"
1328+
))]
13211329
fn os_umask(mask: ModeT, _vm: &VirtualMachine) -> PyResult<ModeT> {
13221330
let ret_mask = unsafe { libc::umask(mask) };
13231331
Ok(ret_mask)
@@ -1455,6 +1463,7 @@ fn os_utime(
14551463

14561464
#[cfg(unix)]
14571465
fn os_sync(_vm: &VirtualMachine) -> PyResult<()> {
1466+
#[cfg(not(target_os = "redox"))]
14581467
unsafe {
14591468
libc::sync();
14601469
}

vm/src/stdlib/socket.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@ type RawSocket = std::os::unix::io::RawFd;
3232
type RawSocket = std::os::windows::raw::SOCKET;
3333

3434
#[cfg(unix)]
35-
use libc as c;
35+
mod c {
36+
pub use libc::*;
37+
// https://gitlab.redox-os.org/redox-os/relibc/-/blob/master/src/header/netdb/mod.rs
38+
#[cfg(target_os = "redox")]
39+
pub const AI_PASSIVE: c_int = 0x01;
40+
#[cfg(target_os = "redox")]
41+
pub const AI_ALL: c_int = 0x10;
42+
// https://gitlab.redox-os.org/redox-os/relibc/-/blob/master/src/header/sys_socket/constants.rs
43+
#[cfg(target_os = "redox")]
44+
pub const SO_TYPE: c_int = 3;
45+
#[cfg(target_os = "redox")]
46+
pub const MSG_OOB: c_int = 1;
47+
#[cfg(target_os = "redox")]
48+
pub const MSG_WAITALL: c_int = 256;
49+
}
3650
#[cfg(windows)]
3751
mod c {
3852
pub use winapi::shared::ws2def::*;
@@ -667,27 +681,26 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
667681
"SHUT_WR" => ctx.new_int(c::SHUT_WR),
668682
"SHUT_RDWR" => ctx.new_int(c::SHUT_RDWR),
669683
"MSG_PEEK" => ctx.new_int(c::MSG_PEEK),
684+
"MSG_OOB" => ctx.new_int(c::MSG_OOB),
685+
"MSG_WAITALL" => ctx.new_int(c::MSG_WAITALL),
670686
"IPPROTO_TCP" => ctx.new_int(c::IPPROTO_TCP),
671687
"IPPROTO_UDP" => ctx.new_int(c::IPPROTO_UDP),
672688
"IPPROTO_IP" => ctx.new_int(c::IPPROTO_IP),
673689
"IPPROTO_IPIP" => ctx.new_int(c::IPPROTO_IP),
674690
"IPPROTO_IPV6" => ctx.new_int(c::IPPROTO_IPV6),
675691
"SOL_SOCKET" => ctx.new_int(c::SOL_SOCKET),
676692
"SO_REUSEADDR" => ctx.new_int(c::SO_REUSEADDR),
677-
"TCP_NODELAY" => ctx.new_int(c::TCP_NODELAY),
678-
"SO_BROADCAST" => ctx.new_int(c::SO_BROADCAST),
679693
"SO_TYPE" => ctx.new_int(c::SO_TYPE),
694+
"SO_BROADCAST" => ctx.new_int(c::SO_BROADCAST),
695+
"TCP_NODELAY" => ctx.new_int(c::TCP_NODELAY),
696+
"AI_ALL" => ctx.new_int(c::AI_ALL),
697+
"AI_PASSIVE" => ctx.new_int(c::AI_PASSIVE),
680698
});
681699

682700
#[cfg(not(target_os = "redox"))]
683701
extend_module!(vm, module, {
684702
"getaddrinfo" => ctx.new_function(socket_getaddrinfo),
685703
"gethostbyaddr" => ctx.new_function(socket_gethostbyaddr),
686-
// non-redox constants
687-
"MSG_OOB" => ctx.new_int(c::MSG_OOB),
688-
"MSG_WAITALL" => ctx.new_int(c::MSG_WAITALL),
689-
"AI_ALL" => ctx.new_int(c::AI_ALL),
690-
"AI_PASSIVE" => ctx.new_int(c::AI_PASSIVE),
691704
});
692705

693706
extend_module_platform_specific(vm, &module);

0 commit comments

Comments
 (0)