Skip to content

Commit ddf5c9a

Browse files
committed
Compile for redox
1 parent e10a8b2 commit ddf5c9a

File tree

7 files changed

+55
-34
lines changed

7 files changed

+55
-34
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ flame = { version = "0.2", optional = true }
3232
flamescope = { version = "0.1", optional = true }
3333

3434
[target.'cfg(not(target_os = "wasi"))'.dependencies]
35-
rustyline = "=5.0.1"
35+
rustyline = "6.0"
3636

3737

3838
[dev-dependencies.cpython]
@@ -45,5 +45,9 @@ path = "src/main.rs"
4545
[patch.crates-io]
4646
# REDOX START, Uncommment when you want to compile/check with redoxer
4747
# time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" }
48-
# nix = { git = "https://github.com/AdminXVII/nix", branch = "add-redox-support" }
48+
# nix = { git = "https://github.com/AdminXVII/nix", branch = "add-redox-support" }
49+
# # following patches are just waiting on a new version to be released to crates.io
50+
# socket2 = { git = "https://github.com/alexcrichton/socket2-rs" }
51+
# rustyline = { git = "https://github.com/kkawakam/rustyline" }
52+
# libc = { git = "https://github.com/rust-lang/libc" }
4953
# REDOX END

src/shell/rustyline_helper.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use rustpython_vm::obj::objstr::PyStringRef;
22
use rustpython_vm::pyobject::{PyIterable, PyResult, TryFromObject};
33
use rustpython_vm::scope::{NameProtocol, Scope};
44
use rustpython_vm::VirtualMachine;
5-
use rustyline::{completion::Completer, highlight::Highlighter, hint::Hinter, Context, Helper};
5+
use rustyline::{
6+
completion::Completer, highlight::Highlighter, hint::Hinter, validate::Validator, Context,
7+
Helper,
8+
};
69

710
pub struct ShellHelper<'vm> {
811
vm: &'vm VirtualMachine,
@@ -162,4 +165,5 @@ impl Completer for ShellHelper<'_> {
162165

163166
impl Hinter for ShellHelper<'_> {}
164167
impl Highlighter for ShellHelper<'_> {}
168+
impl Validator for ShellHelper<'_> {}
165169
impl Helper for ShellHelper<'_> {}

vm/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ unic-common = "0.9"
6161
maplit = "1.0"
6262
bitflags = "1.1"
6363
libc = "0.2"
64-
nix = "0.15.0"
64+
nix = "0.16.0"
6565
wtf8 = "0.0.3"
6666
arr_macro = "0.1.2"
6767
csv = "1.1.1"
@@ -88,6 +88,8 @@ gethostname = "0.2.0"
8888
subprocess = "0.1.18"
8989
num_cpus = "1"
9090
socket2 = { version = "0.3", features = ["unix"] }
91+
92+
[target.'cfg(not(any(target_arch = "wasm32", target_os = "redox")))'.dependencies]
9193
dns-lookup = "1.0"
9294

9395
[target."cfg(windows)".dependencies.winapi]

vm/src/stdlib/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,10 +1424,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
14241424
"EX_PROTOCOL" => ctx.new_int(exitcode::PROTOCOL as i8),
14251425
"EX_NOPERM" => ctx.new_int(exitcode::NOPERM as i8),
14261426
"EX_CONFIG" => ctx.new_int(exitcode::CONFIG as i8),
1427-
"O_DSYNC" => ctx.new_int(libc::O_DSYNC),
14281427
"O_NONBLOCK" => ctx.new_int(libc::O_NONBLOCK),
1429-
"O_NDELAY" => ctx.new_int(libc::O_NDELAY),
1430-
"O_NOCTTY" => ctx.new_int(libc::O_NOCTTY),
14311428
"O_CLOEXEC" => ctx.new_int(libc::O_CLOEXEC),
14321429
});
14331430

@@ -1438,6 +1435,9 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
14381435
"setegid" => ctx.new_function(os_setegid),
14391436
"seteuid" => ctx.new_function(os_seteuid),
14401437
"openpty" => ctx.new_function(os_openpty),
1438+
"O_DSYNC" => ctx.new_int(libc::O_DSYNC),
1439+
"O_NDELAY" => ctx.new_int(libc::O_NDELAY),
1440+
"O_NOCTTY" => ctx.new_int(libc::O_NOCTTY),
14411441
});
14421442

14431443
// cfg taken from nix

vm/src/stdlib/select.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ use std::{io, mem};
77
type RawFd = i32;
88

99
#[cfg(unix)]
10-
use libc::{fd_set, select, timeval, FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO};
10+
use libc::{select, timeval};
1111

1212
#[cfg(windows)]
13-
use winapi::um::winsock2::{fd_set, select, timeval, WSAStartup, FD_SETSIZE, SOCKET as RawFd};
13+
use winapi::um::winsock2::{select, timeval, WSAStartup, SOCKET as RawFd};
1414

1515
// from winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141
1616
#[cfg(windows)]
1717
#[allow(non_snake_case)]
18-
mod fd_ops {
19-
use winapi::um::winsock2::{__WSAFDIsSet, fd_set, FD_SETSIZE, SOCKET};
18+
mod fdset_ops {
19+
pub use winapi::um::winsock2::{__WSAFDIsSet, fd_set, FD_SETSIZE, SOCKET};
2020

2121
pub unsafe fn FD_SET(fd: SOCKET, set: *mut fd_set) {
2222
let mut i = 0;
@@ -42,8 +42,10 @@ mod fd_ops {
4242
__WSAFDIsSet(fd as _, set) != 0
4343
}
4444
}
45-
#[cfg(windows)]
46-
use fd_ops::*;
45+
#[cfg(unix)]
46+
use libc as fdset_ops;
47+
48+
use fdset_ops::{fd_set, FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO};
4749

4850
struct Selectable {
4951
obj: PyObjectRef,

vm/src/stdlib/socket.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ struct GAIOptions {
470470
flags: i32,
471471
}
472472

473+
#[cfg(not(target_os = "redox"))]
473474
fn socket_getaddrinfo(opts: GAIOptions, vm: &VirtualMachine) -> PyResult {
474475
let hints = dns_lookup::AddrInfoHints {
475476
socktype: opts.ty,
@@ -512,6 +513,7 @@ fn socket_getaddrinfo(opts: GAIOptions, vm: &VirtualMachine) -> PyResult {
512513
Ok(vm.ctx.new_list(list))
513514
}
514515

516+
#[cfg(not(target_os = "redox"))]
515517
fn socket_gethostbyaddr(
516518
addr: PyStringRef,
517519
vm: &VirtualMachine,
@@ -609,9 +611,20 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
609611
let socket_gaierror = ctx.new_class("socket.gaierror", vm.ctx.exceptions.os_error.clone());
610612

611613
let module = py_module!(vm, "_socket", {
614+
"socket" => PySocket::make_class(ctx),
612615
"error" => ctx.exceptions.os_error.clone(),
613616
"timeout" => socket_timeout,
614617
"gaierror" => socket_gaierror,
618+
"inet_aton" => ctx.new_function(socket_inet_aton),
619+
"inet_ntoa" => ctx.new_function(socket_inet_ntoa),
620+
"gethostname" => ctx.new_function(socket_gethostname),
621+
"htonl" => ctx.new_function(socket_hton::<u32>),
622+
"htons" => ctx.new_function(socket_hton::<u16>),
623+
"ntohl" => ctx.new_function(socket_ntoh::<u32>),
624+
"ntohs" => ctx.new_function(socket_ntoh::<u16>),
625+
"getdefaulttimeout" => ctx.new_function(|vm: &VirtualMachine| vm.get_none()),
626+
"has_ipv6" => ctx.new_bool(false),
627+
// constants
615628
"AF_UNSPEC" => ctx.new_int(0),
616629
"AF_INET" => ctx.new_int(c::AF_INET),
617630
"AF_INET6" => ctx.new_int(c::AF_INET6),
@@ -620,33 +633,28 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
620633
"SHUT_RD" => ctx.new_int(c::SHUT_RD),
621634
"SHUT_WR" => ctx.new_int(c::SHUT_WR),
622635
"SHUT_RDWR" => ctx.new_int(c::SHUT_RDWR),
623-
"MSG_OOB" => ctx.new_int(c::MSG_OOB),
624636
"MSG_PEEK" => ctx.new_int(c::MSG_PEEK),
625-
"MSG_WAITALL" => ctx.new_int(c::MSG_WAITALL),
626-
"AI_ALL" => ctx.new_int(c::AI_ALL),
627-
"AI_PASSIVE" => ctx.new_int(c::AI_PASSIVE),
628637
"IPPROTO_TCP" => ctx.new_int(c::IPPROTO_TCP),
629638
"IPPROTO_UDP" => ctx.new_int(c::IPPROTO_UDP),
630639
"IPPROTO_IP" => ctx.new_int(c::IPPROTO_IP),
631640
"IPPROTO_IPIP" => ctx.new_int(c::IPPROTO_IP),
632641
"IPPROTO_IPV6" => ctx.new_int(c::IPPROTO_IPV6),
633-
"IPPROTO_NONE" => ctx.new_int(c::IPPROTO_NONE),
634642
"SOL_SOCKET" => ctx.new_int(c::SOL_SOCKET),
635643
"SO_REUSEADDR" => ctx.new_int(c::SO_REUSEADDR),
636644
"TCP_NODELAY" => ctx.new_int(c::TCP_NODELAY),
637645
"SO_BROADCAST" => ctx.new_int(c::SO_BROADCAST),
638-
"socket" => PySocket::make_class(ctx),
639-
"inet_aton" => ctx.new_function(socket_inet_aton),
640-
"inet_ntoa" => ctx.new_function(socket_inet_ntoa),
641-
"gethostname" => ctx.new_function(socket_gethostname),
642-
"htonl" => ctx.new_function(socket_hton::<u32>),
643-
"htons" => ctx.new_function(socket_hton::<u16>),
644-
"ntohl" => ctx.new_function(socket_ntoh::<u32>),
645-
"ntohs" => ctx.new_function(socket_ntoh::<u16>),
646-
"has_ipv6" => ctx.new_bool(false),
647-
"getdefaulttimeout" => ctx.new_function(|vm: &VirtualMachine| vm.get_none()),
646+
});
647+
648+
#[cfg(not(target_os = "redox"))]
649+
extend_module!(vm, module, {
648650
"getaddrinfo" => ctx.new_function(socket_getaddrinfo),
649651
"gethostbyaddr" => ctx.new_function(socket_gethostbyaddr),
652+
// non-redox constants
653+
"MSG_OOB" => ctx.new_int(c::MSG_OOB),
654+
"MSG_WAITALL" => ctx.new_int(c::MSG_WAITALL),
655+
"AI_ALL" => ctx.new_int(c::AI_ALL),
656+
"AI_PASSIVE" => ctx.new_int(c::AI_PASSIVE),
657+
"IPPROTO_NONE" => ctx.new_int(c::IPPROTO_NONE),
650658
});
651659

652660
extend_module_platform_specific(vm, &module);

0 commit comments

Comments
 (0)