Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74c35de

Browse files
Support latest nightly snapshot (#246)
* Allow async main entry point with JavaScriptEventLoopThis change allows the Swift program to have an async main entry pointwhen the JavaScriptEventLoop is installed as the global executor.* Remove Wasmer WASI testsWe no longer use it in carton* Support the latest nightly snapshot* Migrate to ESM* Fix host build
1 parent68376c5 commit74c35de

File tree

21 files changed

+200
-412
lines changed

21 files changed

+200
-412
lines changed

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ jobs:
1818
# Ensure that test succeeds with all toolchains and wasi backend combinations
1919
-{ os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Node }
2020
-{ os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Node }
21-
-{ os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: Wasmer }
22-
-{ os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: Wasmer }
23-
-{ os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: Wasmer }
2421
-{ os: ubuntu-20.04, toolchain: wasm-5.7.3-RELEASE, wasi-backend: MicroWASI }
2522
-{ os: ubuntu-20.04, toolchain: wasm-5.8.0-RELEASE, wasi-backend: MicroWASI }
2623
-{ os: ubuntu-20.04, toolchain: wasm-5.9.1-RELEASE, wasi-backend: MicroWASI }
24+
-{ os: ubuntu-22.04, toolchain: wasm-DEVELOPMENT-SNAPSHOT-2024-05-02-a, wasi-backend: Node }
2725

2826
runs-on:${{ matrix.entry.os }}
2927
env:

‎IntegrationTests/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ TestSuites/.build/$(CONFIGURATION)/%.wasm: FORCE
1111
--triple wasm32-unknown-wasi\
1212
--configuration$(CONFIGURATION)\
1313
-Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor\
14-
-Xlinker --export=main\
14+
-Xlinker --export-if-defined=main -Xlinker --export-if-defined=__main_argc_argv\
15+
--static-swift-stdlib -Xswiftc -static-stdlib\
1516
$(SWIFT_BUILD_FLAGS)
1617

1718
dist/%.wasm: TestSuites/.build/$(CONFIGURATION)/%.wasm

‎IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ try test("Call Function With This") {
400400
letsetName=tryexpectFunction(getJSValue(this: cat1, name:"setName"))
401401

402402
// Direct call without this
403-
tryexpectEqual(getIsCat(),.undefined)
403+
_=tryexpectThrow(trygetIsCat.throws())
404404

405405
// Call with this
406406
letgotIsCat=getIsCat(this: cat1)

‎IntegrationTests/bin/benchmark-tests.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const{ startWasiTask}=require("../lib");
2-
const{ performance}=require("perf_hooks");
1+
import{startWasiTask}from"../lib.js";
2+
import{performance}from"perf_hooks";
33

44
constSAMPLE_ITERATION=1000000
55

‎IntegrationTests/bin/concurrency-tests.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const{ startWasiTask}=require("../lib");
1+
import{startWasiTask}from"../lib.js";
22

33
Error.stackTraceLimit=Infinity;
44

‎IntegrationTests/bin/primary-tests.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ global.objectDecodingTest = {
102102
bi:BigInt(3)
103103
};
104104

105-
const{ startWasiTask,WASI}=require("../lib");
105+
import{startWasiTask}from"../lib.js";
106106

107107
startWasiTask("./dist/PrimaryTests.wasm").catch((err)=>{
108108
console.log(err);

‎IntegrationTests/lib.js‎

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,9 @@
1-
constSwiftRuntime=require("javascript-kit-swift").SwiftRuntime;
2-
constWasmerWASI=require("@wasmer/wasi").WASI;
3-
constWasmFs=require("@wasmer/wasmfs").WasmFs;
4-
constNodeWASI=require("wasi").WASI;
5-
const{WASI:MicroWASI, useAll}=require("uwasi");
6-
7-
constpromisify=require("util").promisify;
8-
constfs=require("fs");
9-
constreadFile=promisify(fs.readFile);
1+
import{SwiftRuntime}from"javascript-kit-swift"
2+
import{WASIasNodeWASI}from"wasi"
3+
import{WASIasMicroWASI,useAll}from"uwasi"
4+
import*asfsfrom"fs/promises"
105

116
constWASI={
12-
Wasmer:({ programName})=>{
13-
// Instantiate a new WASI Instance
14-
constwasmFs=newWasmFs();
15-
// Output stdout and stderr to console
16-
constoriginalWriteSync=wasmFs.fs.writeSync;
17-
wasmFs.fs.writeSync=(fd,buffer,offset,length,position)=>{
18-
consttext=newTextDecoder("utf-8").decode(buffer);
19-
switch(fd){
20-
case1:
21-
console.log(text);
22-
break;
23-
case2:
24-
console.error(text);
25-
break;
26-
}
27-
returnoriginalWriteSync(fd,buffer,offset,length,position);
28-
};
29-
constwasi=newWasmerWASI({
30-
args:[programName],
31-
env:{},
32-
bindings:{
33-
...WasmerWASI.defaultBindings,
34-
fs:wasmFs.fs,
35-
},
36-
});
37-
38-
return{
39-
wasiImport:wasi.wasiImport,
40-
start(instance){
41-
wasi.start(instance);
42-
instance.exports._initialize();
43-
instance.exports.main();
44-
}
45-
}
46-
},
477
MicroWASI:({ programName})=>{
488
constwasi=newMicroWASI({
499
args:[programName],
@@ -53,25 +13,28 @@ const WASI = {
5313

5414
return{
5515
wasiImport:wasi.wasiImport,
56-
start(instance){
16+
start(instance,swift){
5717
wasi.initialize(instance);
58-
instance.exports.main();
18+
swift.main();
5919
}
6020
}
6121
},
6222
Node:({ programName})=>{
6323
constwasi=newNodeWASI({
6424
args:[programName],
6525
env:{},
26+
preopens:{
27+
"/":"./",
28+
},
6629
returnOnExit:false,
6730
version:"preview1",
6831
})
6932

7033
return{
7134
wasiImport:wasi.wasiImport,
72-
start(instance){
35+
start(instance,swift){
7336
wasi.initialize(instance);
74-
instance.exports.main();
37+
swift.main();
7538
}
7639
}
7740
},
@@ -88,10 +51,10 @@ const selectWASIBackend = () => {
8851
returnWASI.Node;
8952
};
9053

91-
conststartWasiTask=async(wasmPath,wasiConstructor=selectWASIBackend())=>{
54+
exportconststartWasiTask=async(wasmPath,wasiConstructor=selectWASIBackend())=>{
9255
constswift=newSwiftRuntime();
9356
// Fetch our Wasm File
94-
constwasmBinary=awaitreadFile(wasmPath);
57+
constwasmBinary=awaitfs.readFile(wasmPath);
9558
constwasi=wasiConstructor({programName:wasmPath});
9659

9760
// Instantiate the WebAssembly file
@@ -106,7 +69,5 @@ const startWasiTask = async (wasmPath, wasiConstructor = selectWASIBackend()) =>
10669

10770
swift.setInstance(instance);
10871
// Start the WebAssembly WASI instance!
109-
wasi.start(instance);
72+
wasi.start(instance,swift);
11073
};
111-
112-
module.exports={ startWasiTask,WASI};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp