Skip to content

Commit 6660b64

Browse files
committed
os.uname only on unix
1 parent 8baaa5d commit 6660b64

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ paste = "0.1"
6969
base64 = "0.11"
7070
is-macro = "0.1"
7171
result-like = "^0.2.1"
72-
uname = "0.1.1"
7372

7473
flame = { version = "0.2", optional = true }
7574
flamer = { version = "0.3", optional = true }
@@ -79,6 +78,7 @@ pwd = "1"
7978

8079
[target.'cfg(unix)'.dependencies]
8180
exitcode = "1.1.2"
81+
uname = "0.1.1"
8282

8383
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
8484
crc32fast = "1.2.0"

vm/src/stdlib/os.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use nix::pty::openpty;
2222
use nix::unistd::{self, Gid, Pid, Uid};
2323
#[cfg(unix)]
2424
use std::os::unix::io::RawFd;
25+
#[cfg(unix)]
2526
use uname;
2627

2728
use super::errno::errors;
@@ -1157,6 +1158,7 @@ fn os_urandom(size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
11571158

11581159
#[pystruct_sequence(name = "os.uname_result")]
11591160
#[derive(Debug)]
1161+
#[cfg(unix)]
11601162
struct UnameResult {
11611163
sysname: String,
11621164
nodename: String,
@@ -1165,6 +1167,7 @@ struct UnameResult {
11651167
machine: String,
11661168
}
11671169

1170+
#[cfg(unix)]
11681171
impl UnameResult {
11691172
fn into_obj(self, vm: &VirtualMachine) -> PyObjectRef {
11701173
self.into_struct_sequence(vm, vm.class("_os", "uname_result"))
@@ -1173,6 +1176,7 @@ impl UnameResult {
11731176
}
11741177
}
11751178

1179+
#[cfg(unix)]
11761180
fn os_uname(vm: &VirtualMachine) -> PyResult {
11771181
let info = uname::uname().map_err(|err| convert_io_error(vm, err))?;
11781182
Ok(UnameResult {
@@ -1274,7 +1278,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
12741278
});
12751279

12761280
let stat_result = StatResult::make_class(ctx);
1277-
let uname_result = UnameResult::make_class(ctx);
12781281

12791282
struct SupportFunc<'a> {
12801283
name: &'a str,
@@ -1363,8 +1366,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
13631366
"urandom" => ctx.new_function(os_urandom),
13641367
"isatty" => ctx.new_function(os_isatty),
13651368
"lseek" => ctx.new_function(os_lseek),
1366-
"uname" => ctx.new_function(os_uname),
1367-
"uname_result" => uname_result,
13681369

13691370
"O_RDONLY" => ctx.new_int(libc::O_RDONLY),
13701371
"O_WRONLY" => ctx.new_int(libc::O_WRONLY),
@@ -1417,6 +1418,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
14171418
#[cfg(unix)]
14181419
fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) -> PyObjectRef {
14191420
let ctx = &vm.ctx;
1421+
1422+
let uname_result = UnameResult::make_class(ctx);
1423+
14201424
extend_module!(vm, module, {
14211425
"access" => ctx.new_function(os_access),
14221426
"chmod" => ctx.new_function(os_chmod),
@@ -1437,6 +1441,8 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
14371441
"setuid" => ctx.new_function(os_setuid),
14381442
"system" => ctx.new_function(os_system),
14391443
"ttyname" => ctx.new_function(os_ttyname),
1444+
"uname" => ctx.new_function(os_uname),
1445+
"uname_result" => uname_result,
14401446
"EX_OK" => ctx.new_int(exitcode::OK as i8),
14411447
"EX_USAGE" => ctx.new_int(exitcode::USAGE as i8),
14421448
"EX_DATAERR" => ctx.new_int(exitcode::DATAERR as i8),

0 commit comments

Comments
 (0)