Skip to content

Commit 557fa7b

Browse files
author
Guy Bedford
authored
deps: update to wasi@0.2.1, disable resource imports treeshaking (#139)
1 parent 678e6f4 commit 557fa7b

41 files changed

Lines changed: 606 additions & 182 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/spidermonkey-embedding-splicer/src/bindgen.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,10 @@ impl JsBindgen<'_> {
577577
);
578578

579579
uwriteln!(self.src, "\nexport class import_{name} {{");
580-
}
581580

582-
if guest_imports.contains(&import_name)
583-
|| import_name.starts_with(&self.local_package_name)
584-
{
581+
// TODO: Imports tree-shaking for resources is disabled since it is not functioning correctly.
582+
// To make this work properly, we need to trace recursively through the type graph
583+
// to include all resources across argument types.
585584
for (_, func) in functions {
586585
self.import_bindgen(
587586
import_name.clone(),
@@ -590,11 +589,7 @@ impl JsBindgen<'_> {
590589
iface_name.clone(),
591590
);
592591
}
593-
}
594592

595-
// TODO: Resource tree-shaking, which requires resource use checks against used
596-
// functions.
597-
if let Some(ty) = resource {
598593
let lower_camel = &self.resolve.types[ty]
599594
.name
600595
.as_ref()
@@ -617,9 +612,20 @@ impl JsBindgen<'_> {
617612
$resource_import${prefix}drop${lower_camel}(this[{resource_symbol}]);
618613
this[{resource_symbol}] = null;
619614
}}
620-
}}
621-
"
615+
}}
616+
"
622617
);
618+
} else if guest_imports.contains(&import_name)
619+
|| import_name.starts_with(&self.local_package_name)
620+
{
621+
for (_, func) in functions {
622+
self.import_bindgen(
623+
import_name.clone(),
624+
func,
625+
true,
626+
iface_name.clone(),
627+
);
628+
}
623629
}
624630
}
625631
}

crates/spidermonkey-embedding-splicer/src/stub_wasi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
let ty = module.types.get(ty_id).unwrap();
4343
let (params, results) = (ty.params.to_vec(), ty.results.to_vec());
4444
let mut builder = FunctionBuilder::new(params.as_slice(), results.as_slice());
45-
let args = stub(&mut builder)?;
45+
let _args = stub(&mut builder)?;
4646

4747
builder.replace_import_in_module(module, iid);
4848

test/cases/http-request/source.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { handle } from 'wasi:http/outgoing-handler@0.2.0';
2-
import { Fields, OutgoingRequest } from 'wasi:http/types@0.2.0';
1+
import { handle } from 'wasi:http/outgoing-handler@0.2.1';
2+
import { Fields, OutgoingRequest } from 'wasi:http/types@0.2.1';
33

44
const encoder = new TextEncoder();
55
const decoder = new TextDecoder();

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ suite('WASI', () => {
231231

232232
const { component } = await componentize(
233233
`
234-
import { now } from 'wasi:clocks/wall-clock@0.2.0';
235-
import { getRandomBytes } from 'wasi:random/random@0.2.0';
234+
import { now } from 'wasi:clocks/wall-clock@0.2.1';
235+
import { getRandomBytes } from 'wasi:random/random@0.2.1';
236236
237237
let result;
238238
export const run = {

test/wit/deps/cli/command.wit

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package wasi:cli@0.2.0;
1+
package wasi:cli@0.2.1;
22

3+
@since(version = 0.2.0)
34
world command {
5+
@since(version = 0.2.0)
46
include imports;
57

8+
@since(version = 0.2.0)
69
export run;
710
}

test/wit/deps/cli/environment.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@since(version = 0.2.0)
12
interface environment {
23
/// Get the POSIX-style environment variables.
34
///
@@ -7,12 +8,15 @@ interface environment {
78
/// Morally, these are a value import, but until value imports are available
89
/// in the component model, this import function should return the same
910
/// values each time it is called.
11+
@since(version = 0.2.0)
1012
get-environment: func() -> list<tuple<string, string>>;
1113

1214
/// Get the POSIX-style arguments to the program.
15+
@since(version = 0.2.0)
1316
get-arguments: func() -> list<string>;
1417

1518
/// Return a path that programs should use as their initial current working
1619
/// directory, interpreting `.` as shorthand for this.
20+
@since(version = 0.2.0)
1721
initial-cwd: func() -> option<string>;
1822
}

test/wit/deps/cli/exit.wit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
@since(version = 0.2.0)
12
interface exit {
23
/// Exit the current instance and any linked instances.
4+
@since(version = 0.2.0)
35
exit: func(status: result);
6+
7+
/// Exit the current instance and any linked instances, reporting the
8+
/// specified status code to the host.
9+
///
10+
/// The meaning of the code depends on the context, with 0 usually meaning
11+
/// "success", and other values indicating various types of failure.
12+
///
13+
/// This function does not return; the effect is analogous to a trap, but
14+
/// without the connotation that something bad has happened.
15+
@unstable(feature = cli-exit-with-code)
16+
exit-with-code: func(status-code: u8);
417
}

test/wit/deps/cli/imports.wit

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
package wasi:cli@0.2.0;
1+
package wasi:cli@0.2.1;
22

3+
@since(version = 0.2.0)
34
world imports {
4-
include wasi:clocks/imports@0.2.0;
5-
include wasi:filesystem/imports@0.2.0;
6-
include wasi:sockets/imports@0.2.0;
7-
include wasi:random/imports@0.2.0;
8-
include wasi:io/imports@0.2.0;
5+
@since(version = 0.2.0)
6+
include wasi:clocks/imports@0.2.1;
7+
@since(version = 0.2.0)
8+
include wasi:filesystem/imports@0.2.1;
9+
@since(version = 0.2.0)
10+
include wasi:sockets/imports@0.2.1;
11+
@since(version = 0.2.0)
12+
include wasi:random/imports@0.2.1;
13+
@since(version = 0.2.0)
14+
include wasi:io/imports@0.2.1;
915

16+
@since(version = 0.2.0)
1017
import environment;
18+
@since(version = 0.2.0)
1119
import exit;
20+
@since(version = 0.2.0)
1221
import stdin;
22+
@since(version = 0.2.0)
1323
import stdout;
24+
@since(version = 0.2.0)
1425
import stderr;
26+
@since(version = 0.2.0)
1527
import terminal-input;
28+
@since(version = 0.2.0)
1629
import terminal-output;
30+
@since(version = 0.2.0)
1731
import terminal-stdin;
32+
@since(version = 0.2.0)
1833
import terminal-stdout;
34+
@since(version = 0.2.0)
1935
import terminal-stderr;
2036
}

test/wit/deps/cli/run.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
@since(version = 0.2.0)
12
interface run {
23
/// Run the program.
4+
@since(version = 0.2.0)
35
run: func() -> result;
46
}

0 commit comments

Comments
 (0)