Skip to content

Commit 725dac2

Browse files
committed
Fix redox
1 parent 4fba939 commit 725dac2

File tree

12 files changed

+52
-49
lines changed

12 files changed

+52
-49
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ jobs:
232232
- name: Prepare repository for redox compilation
233233
run: bash scripts/redox/uncomment-cargo.sh
234234
- name: Check compilation for Redox
235-
if: false # FIXME: redoxer toolchain is from ~july 2021, edition2021 isn't stabilized
236235
uses: coolreader18/redoxer-action@v1
237236
with:
238237
command: check

Cargo.lock

Lines changed: 5 additions & 17 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# REDOX START
2-
# cargo-features = ["edition2021"]
3-
# REDOX END
41
[package]
52
name = "rustpython"
63
version = "0.2.0"
@@ -49,7 +46,7 @@ once_cell = "1.13"
4946
parking_lot = "0.12"
5047
paste = "1.0.7"
5148
rand = "0.8.5"
52-
rustyline = "10.0.0"
49+
rustyline = "11"
5350
serde = "1.0"
5451
schannel = "0.1.19"
5552
static_assertions = "1.1"
@@ -131,4 +128,7 @@ lto = "thin"
131128

132129
[patch.crates-io]
133130
# REDOX START, Uncomment when you want to compile/check with redoxer
131+
# nix = { git = "https://github.com/coolreader18/nix", branch = "0.26.2-redox" }
132+
# errno = { git = "https://github.com/coolreader18/rust-errno", branch = "0.2.8-redox" }
133+
# libc = { git = "https://github.com/rust-lang/libc" }
134134
# REDOX END

stdlib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ flate2 = "1.0.23"
7777
bzip2 = { version = "0.4", optional = true }
7878

7979
# uuid
80-
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32")))'.dependencies]
80+
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32", target_os = "redox")))'.dependencies]
8181
mac_address = "1.1.3"
8282
uuid = { version = "1.1.2", features = ["v1", "fast-rng", "macro-diagnostics"] }
8383

stdlib/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod statistics;
3030
mod bz2;
3131
#[cfg(not(target_arch = "wasm32"))]
3232
pub mod socket;
33-
#[cfg(unix)]
33+
#[cfg(all(unix, not(target_os = "redox")))]
3434
mod syslog;
3535
mod unicodedata;
3636
mod zlib;
@@ -62,7 +62,8 @@ mod termios;
6262
target_os = "android",
6363
target_os = "ios",
6464
target_os = "windows",
65-
target_arch = "wasm32"
65+
target_arch = "wasm32",
66+
target_os = "redox",
6667
)))]
6768
mod uuid;
6869

@@ -138,11 +139,11 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
138139
#[cfg(unix)]
139140
{
140141
"_posixsubprocess" => posixsubprocess::make_module,
141-
"syslog" => syslog::make_module,
142142
"mmap" => mmap::make_module,
143143
}
144144
#[cfg(all(unix, not(target_os = "redox")))]
145145
{
146+
"syslog" => syslog::make_module,
146147
"resource" => resource::make_module,
147148
}
148149
#[cfg(all(unix, not(any(target_os = "ios", target_os = "redox"))))]
@@ -157,7 +158,7 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
157158
{
158159
"_scproxy" => scproxy::make_module,
159160
}
160-
#[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows", target_arch = "wasm32")))]
161+
#[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows", target_arch = "wasm32", target_os = "redox")))]
161162
{
162163
"_uuid" => uuid::make_module,
163164
}

stdlib/src/locale.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ mod _locale {
5050
ptr,
5151
};
5252

53-
#[cfg(all(unix, not(any(target_os = "ios", target_os = "android"))))]
53+
#[cfg(all(
54+
unix,
55+
not(any(target_os = "ios", target_os = "android", target_os = "redox"))
56+
))]
5457
#[pyattr]
5558
use libc::{
5659
ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABMON_1, ABMON_10, ABMON_11,

stdlib/src/mmap.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod mmap {
2727
use std::fs::File;
2828
use std::io::Write;
2929
use std::ops::{Deref, DerefMut};
30-
#[cfg(all(unix, not(target_os = "redox")))]
30+
#[cfg(unix)]
3131
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
3232

3333
fn advice_try_from_i32(vm: &VirtualMachine, i: i32) -> PyResult<Advice> {
@@ -224,6 +224,7 @@ mod mmap {
224224
end: Option<isize>,
225225
}
226226

227+
#[cfg(not(target_os = "redox"))]
227228
#[derive(FromArgs)]
228229
pub struct AdviseOptions {
229230
#[pyarg(positional)]
@@ -234,6 +235,7 @@ mod mmap {
234235
length: Option<PyIntRef>,
235236
}
236237

238+
#[cfg(not(target_os = "redox"))]
237239
impl AdviseOptions {
238240
fn values(self, len: usize, vm: &VirtualMachine) -> PyResult<(libc::c_int, usize, usize)> {
239241
let start = self
@@ -273,7 +275,7 @@ mod mmap {
273275
type Args = MmapNewArgs;
274276

275277
// TODO: Windows is not supported right now.
276-
#[cfg(all(unix, not(target_os = "redox")))]
278+
#[cfg(unix)]
277279
fn py_new(
278280
cls: PyTypeRef,
279281
MmapNewArgs {
@@ -671,6 +673,7 @@ mod mmap {
671673
Ok(())
672674
}
673675

676+
#[cfg(not(target_os = "redox"))]
674677
#[allow(unused_assignments)]
675678
#[pymethod]
676679
fn madvise(&self, options: AdviseOptions, vm: &VirtualMachine) -> PyResult<()> {

stdlib/src/socket.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ mod _socket {
5353
#[pyattr]
5454
// put IPPROTO_MAX later
5555
use c::{
56-
AF_DECnet, AF_APPLETALK, AF_INET, AF_INET6, AF_IPX, AF_UNSPEC, INADDR_ANY, INADDR_LOOPBACK,
57-
INADDR_NONE, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, IPPROTO_FRAGMENT,
58-
IPPROTO_HOPOPTS, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP,
59-
IPPROTO_IP as IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP,
60-
IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, MSG_CTRUNC,
61-
MSG_DONTROUTE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST,
62-
NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR,
63-
SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE,
64-
SO_REUSEADDR, SO_TYPE, TCP_NODELAY,
56+
AF_INET, AF_INET6, AF_UNSPEC, INADDR_ANY, INADDR_LOOPBACK, INADDR_NONE, IPPROTO_ICMP,
57+
IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_TCP,
58+
IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK,
59+
MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST,
60+
NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET,
61+
SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, TCP_NODELAY,
62+
};
63+
64+
#[cfg(not(target_os = "redox"))]
65+
#[pyattr]
66+
use c::{
67+
AF_DECnet, AF_APPLETALK, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP,
68+
IPPROTO_FRAGMENT, IPPROTO_HOPOPTS, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_NONE, IPPROTO_PIM,
69+
IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING,
6570
};
6671

6772
#[cfg(unix)]

vm/src/readline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod rustyline_readline {
6666

6767
/// Readline: the REPL
6868
pub struct Readline<H: Helper> {
69-
repl: rustyline::Editor<H>,
69+
repl: rustyline::Editor<H, rustyline::history::DefaultHistory>,
7070
}
7171

7272
impl<H: Helper> Readline<H> {
@@ -100,7 +100,7 @@ mod rustyline_readline {
100100
}
101101

102102
pub fn add_history_entry(&mut self, entry: &str) -> OtherResult<()> {
103-
self.repl.add_history_entry(entry);
103+
self.repl.add_history_entry(entry)?;
104104
Ok(())
105105
}
106106

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ pub(super) mod _os {
16851685
}
16861686

16871687
cfg_if::cfg_if! {
1688-
if #[cfg(target_os = "android")] {
1688+
if #[cfg(any(target_os = "android", target_os = "redox"))] {
16891689
Ok(Some("UTF-8".to_owned()))
16901690
} else if #[cfg(windows)] {
16911691
let cp = match fd {

vm/src/stdlib/posix.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ pub mod module {
429429
)
430430
}
431431

432+
#[cfg(not(target_os = "redox"))]
433+
const MKNOD_DIR_FD: bool = cfg!(not(target_vendor = "apple"));
434+
435+
#[cfg(not(target_os = "redox"))]
432436
#[derive(FromArgs)]
433437
struct MknodArgs {
434438
#[pyarg(any)]
@@ -437,11 +441,11 @@ pub mod module {
437441
mode: libc::mode_t,
438442
#[pyarg(any)]
439443
device: libc::dev_t,
440-
#[allow(unused)]
441444
#[pyarg(flatten)]
442-
dir_fd: DirFd<1>,
445+
dir_fd: DirFd<{ MKNOD_DIR_FD as usize }>,
443446
}
444447

448+
#[cfg(not(target_os = "redox"))]
445449
impl MknodArgs {
446450
fn _mknod(self, vm: &VirtualMachine) -> PyResult<i32> {
447451
Ok(unsafe {
@@ -473,6 +477,7 @@ pub mod module {
473477
}
474478
#[cfg(target_vendor = "apple")]
475479
fn mknod(self, vm: &VirtualMachine) -> PyResult<()> {
480+
let [] = self.dir_fd.0;
476481
let ret = self._mknod(vm)?;
477482
if ret != 0 {
478483
Err(errno_err(vm))
@@ -482,6 +487,7 @@ pub mod module {
482487
}
483488
}
484489

490+
#[cfg(not(target_os = "redox"))]
485491
#[pyfunction]
486492
fn mknod(args: MknodArgs, vm: &VirtualMachine) -> PyResult<()> {
487493
args.mknod(vm)
@@ -1568,10 +1574,8 @@ pub mod module {
15681574
SupportFunc::new("lchown", None, None, None),
15691575
#[cfg(not(target_os = "redox"))]
15701576
SupportFunc::new("fchown", Some(true), None, Some(true)),
1571-
#[cfg(not(target_os = "macos"))]
1572-
SupportFunc::new("mknod", Some(true), Some(true), Some(false)),
1573-
#[cfg(target_os = "macos")]
1574-
SupportFunc::new("mknod", Some(true), Some(false), Some(false)),
1577+
#[cfg(not(target_os = "redox"))]
1578+
SupportFunc::new("mknod", Some(true), Some(MKNOD_DIR_FD), Some(false)),
15751579
SupportFunc::new("umask", Some(false), Some(false), Some(false)),
15761580
SupportFunc::new("execv", None, None, None),
15771581
SupportFunc::new("pathconf", Some(true), None, None),

vm/src/stdlib/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ mod unix {
552552
target_os = "linux",
553553
)))]
554554
#[pyfunction]
555-
fn get_clock_info(_name: PyStrRef, vm: &VirtualMachine) -> PyResult<PyNamespace> {
555+
fn get_clock_info(_name: PyStrRef, vm: &VirtualMachine) -> PyResult<PyRef<PyNamespace>> {
556556
Err(vm.new_not_implemented_error("get_clock_info unsupported on this system".to_owned()))
557557
}
558558

0 commit comments

Comments
 (0)