Skip to content

Commit 8fe65da

Browse files
committed
std: Remove the wasm_syscall feature
This commit removes the `wasm_syscall` feature from the wasm32-unknown-unknown build of the standard library. This feature was originally intended to allow an opt-in way to interact with the operating system in a posix-like way but it was never stabilized. Nowadays with the advent of the `wasm32-wasi` target that should entirely replace the intentions of the `wasm_syscall` feature.
1 parent ac21131 commit 8fe65da

File tree

11 files changed

+19
-379
lines changed

11 files changed

+19
-379
lines changed

config.toml.example

-5
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@
382382
# This is the name of the directory in which codegen backends will get installed
383383
#codegen-backends-dir = "codegen-backends"
384384

385-
# Flag indicating whether `libstd` calls an imported function to handle basic IO
386-
# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
387-
# target, as without this option the test output will not be captured.
388-
#wasm-syscall = false
389-
390385
# Indicates whether LLD will be compiled and made available in the sysroot for
391386
# rustc to execute.
392387
#lld = false

src/bootstrap/config.rs

-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ pub struct Config {
122122

123123
// libstd features
124124
pub backtrace: bool, // support for RUST_BACKTRACE
125-
pub wasm_syscall: bool,
126125

127126
// misc
128127
pub low_priority: bool,
@@ -318,7 +317,6 @@ struct Rust {
318317
save_toolstates: Option<String>,
319318
codegen_backends: Option<Vec<String>>,
320319
codegen_backends_dir: Option<String>,
321-
wasm_syscall: Option<bool>,
322320
lld: Option<bool>,
323321
lldb: Option<bool>,
324322
llvm_tools: Option<bool>,
@@ -558,7 +556,6 @@ impl Config {
558556
if let Some(true) = rust.incremental {
559557
config.incremental = true;
560558
}
561-
set(&mut config.wasm_syscall, rust.wasm_syscall);
562559
set(&mut config.lld_enabled, rust.lld);
563560
set(&mut config.lldb_enabled, rust.lldb);
564561
set(&mut config.llvm_tools_enabled, rust.llvm_tools);

src/bootstrap/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,6 @@ impl Build {
498498
if self.config.profiler {
499499
features.push_str(" profiler");
500500
}
501-
if self.config.wasm_syscall {
502-
features.push_str(" wasm_syscall");
503-
}
504501
features
505502
}
506503

src/bootstrap/test.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1811,16 +1811,6 @@ impl Step for Crate {
18111811
.expect("nodejs not configured"),
18121812
);
18131813
} else if target.starts_with("wasm32") {
1814-
// Warn about running tests without the `wasm_syscall` feature enabled.
1815-
// The javascript shim implements the syscall interface so that test
1816-
// output can be correctly reported.
1817-
if !builder.config.wasm_syscall {
1818-
builder.info(
1819-
"Libstd was built without `wasm_syscall` feature enabled: \
1820-
test output may not be visible."
1821-
);
1822-
}
1823-
18241814
// On the wasm32-unknown-unknown target we're using LTO which is
18251815
// incompatible with `-C prefer-dynamic`, so disable that here
18261816
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");

src/etc/wasm32-shim.js

+1-107
Original file line numberDiff line numberDiff line change
@@ -15,113 +15,7 @@ const buffer = fs.readFileSync(process.argv[2]);
1515
Error.stackTraceLimit = 20;
1616

1717
let m = new WebAssembly.Module(buffer);
18-
19-
let memory = null;
20-
21-
function viewstruct(data, fields) {
22-
return new Uint32Array(memory.buffer).subarray(data/4, data/4 + fields);
23-
}
24-
25-
function copystr(a, b) {
26-
let view = new Uint8Array(memory.buffer).subarray(a, a + b);
27-
return String.fromCharCode.apply(null, view);
28-
}
29-
30-
function syscall_write([fd, ptr, len]) {
31-
let s = copystr(ptr, len);
32-
switch (fd) {
33-
case 1: process.stdout.write(s); break;
34-
case 2: process.stderr.write(s); break;
35-
}
36-
}
37-
38-
function syscall_exit([code]) {
39-
process.exit(code);
40-
}
41-
42-
function syscall_args(params) {
43-
let [ptr, len] = params;
44-
45-
// Calculate total required buffer size
46-
let totalLen = -1;
47-
for (let i = 2; i < process.argv.length; ++i) {
48-
totalLen += Buffer.byteLength(process.argv[i]) + 1;
49-
}
50-
if (totalLen < 0) { totalLen = 0; }
51-
params[2] = totalLen;
52-
53-
// If buffer is large enough, copy data
54-
if (len >= totalLen) {
55-
let view = new Uint8Array(memory.buffer);
56-
for (let i = 2; i < process.argv.length; ++i) {
57-
let value = process.argv[i];
58-
Buffer.from(value).copy(view, ptr);
59-
ptr += Buffer.byteLength(process.argv[i]) + 1;
60-
}
61-
}
62-
}
63-
64-
function syscall_getenv(params) {
65-
let [keyPtr, keyLen, valuePtr, valueLen] = params;
66-
67-
let key = copystr(keyPtr, keyLen);
68-
let value = process.env[key];
69-
70-
if (value == null) {
71-
params[4] = 0xFFFFFFFF;
72-
} else {
73-
let view = new Uint8Array(memory.buffer);
74-
let totalLen = Buffer.byteLength(value);
75-
params[4] = totalLen;
76-
if (valueLen >= totalLen) {
77-
Buffer.from(value).copy(view, valuePtr);
78-
}
79-
}
80-
}
81-
82-
function syscall_time(params) {
83-
let t = Date.now();
84-
let secs = Math.floor(t / 1000);
85-
let millis = t % 1000;
86-
params[1] = Math.floor(secs / 0x100000000);
87-
params[2] = secs % 0x100000000;
88-
params[3] = Math.floor(millis * 1000000);
89-
}
90-
91-
let imports = {};
92-
imports.env = {
93-
// These are generated by LLVM itself for various intrinsic calls. Hopefully
94-
// one day this is not necessary and something will automatically do this.
95-
fmod: function(x, y) { return x % y; },
96-
exp2: function(x) { return Math.pow(2, x); },
97-
exp2f: function(x) { return Math.pow(2, x); },
98-
ldexp: function(x, y) { return x * Math.pow(2, y); },
99-
ldexpf: function(x, y) { return x * Math.pow(2, y); },
100-
sin: Math.sin,
101-
sinf: Math.sin,
102-
cos: Math.cos,
103-
cosf: Math.cos,
104-
log: Math.log,
105-
log2: Math.log2,
106-
log10: Math.log10,
107-
log10f: Math.log10,
108-
109-
rust_wasm_syscall: function(index, data) {
110-
switch (index) {
111-
case 1: syscall_write(viewstruct(data, 3)); return true;
112-
case 2: syscall_exit(viewstruct(data, 1)); return true;
113-
case 3: syscall_args(viewstruct(data, 3)); return true;
114-
case 4: syscall_getenv(viewstruct(data, 5)); return true;
115-
case 6: syscall_time(viewstruct(data, 4)); return true;
116-
default:
117-
console.log("Unsupported syscall: " + index);
118-
return false;
119-
}
120-
}
121-
};
122-
123-
let instance = new WebAssembly.Instance(m, imports);
124-
memory = instance.exports.memory;
18+
let instance = new WebAssembly.Instance(m, {});
12519
try {
12620
instance.exports.main();
12721
} catch (e) {

src/libstd/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ llvm-libunwind = ["unwind/llvm-libunwind"]
7070
# Make panics and failed asserts immediately abort without formatting any message
7171
panic_immediate_abort = ["core/panic_immediate_abort"]
7272

73-
# An off-by-default feature which enables a linux-syscall-like ABI for libstd to
74-
# interoperate with the host environment. Currently not well documented and
75-
# requires rebuilding the standard library to use it.
76-
wasm_syscall = []
77-
7873
# Enable std_detect default features for stdarch/crates/std_detect:
7974
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
8075
std_detect_file_io = []

src/libstd/sys/wasm/args.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::ffi::OsString;
22
use crate::marker::PhantomData;
33
use crate::vec;
4-
use crate::sys::ArgsSysCall;
54

65
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
76
// On wasm these should always be null, so there's nothing for us to do here
@@ -11,9 +10,8 @@ pub unsafe fn cleanup() {
1110
}
1211

1312
pub fn args() -> Args {
14-
let v = ArgsSysCall::perform();
1513
Args {
16-
iter: v.into_iter(),
14+
iter: Vec::new().into_iter(),
1715
_dont_send_or_sync_me: PhantomData,
1816
}
1917
}

0 commit comments

Comments
 (0)