File tree Expand file tree Collapse file tree 3 files changed +32
-11
lines changed
Plugins/PackageToJS/Templates Expand file tree Collapse file tree 3 files changed +32
-11
lines changed Original file line number Diff line number Diff line change
1
+ /* #if USE_SHARED_MEMORY */
2
+ import type { SwiftRuntimeThreadChannel } from "./runtime.js" ;
3
+ /* #endif */
4
+
1
5
export type Import = {
2
6
// TODO: Generate type from imported .d.ts files
3
7
}
@@ -65,6 +69,7 @@ export declare function instantiate(
65
69
/* #endif */
66
70
/* #if USE_SHARED_MEMORY */
67
71
memory : WebAssembly . Memory
72
+ threadChannel : SwiftRuntimeThreadChannel
68
73
/* #endif */
69
74
}
70
75
) : Promise < {
Original file line number Diff line number Diff line change @@ -27,18 +27,24 @@ export async function instantiate(
27
27
const { wasi } = options ;
28
28
/* #endif */
29
29
const instantiator = await createInstantiator ( imports , options ) ;
30
- const swift = new SwiftRuntime ( ) ;
30
+ const swift = new SwiftRuntime ( {
31
+ /* #if USE_SHARED_MEMORY */
32
+ sharedMemory : true ,
33
+ threadChannel : options . threadChannel ,
34
+ /* #endif */
35
+ } ) ;
31
36
32
37
/** @type {WebAssembly.Imports } */
33
38
const importObject = {
34
39
javascript_kit : swift . wasmImports ,
35
- /* #if IS_WASI */
40
+ /* #if IS_WASI */
36
41
wasi_snapshot_preview1 : wasi . wasiImport ,
37
- /* #if USE_SHARED_MEMORY */ env : {
42
+ /* #if USE_SHARED_MEMORY */
43
+ env : {
38
44
memory : options . memory ,
39
45
} ,
40
- /* #endif */
41
- /* #endif */
46
+ /* #endif */
47
+ /* #endif */
42
48
} ;
43
49
instantiator . addImports ( importObject ) ;
44
50
Original file line number Diff line number Diff line change @@ -37,13 +37,23 @@ Please ensure you are using Node.js v18.x or newer.
37
37
returnOnExit : false ,
38
38
} )
39
39
const dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
40
+ const module = await WebAssembly . compile ( await readFile ( path . join ( dirname , MODULE_PATH ) ) )
41
+ const options = { wasi }
42
+ /* #if USE_SHARED_MEMORY */
43
+ // @ts -ignore
44
+ const memoryType = WebAssembly . Module . imports ( module ) . find ( i => i . module === "env" && i . name === "memory" ) ?. type
45
+ const memory = new WebAssembly . Memory ( {
46
+ initial : memoryType . minimum ,
47
+ maximum : memoryType . maximum ,
48
+ shared : memoryType . shared ,
49
+ } )
50
+ options . memory = memory
51
+ /* #endif */
40
52
const { swift } = await instantiate (
41
- await readFile ( path . join ( dirname , MODULE_PATH ) ) ,
42
- { } , {
43
- wasi,
44
- /* #if USE_SHARED_MEMORY */
45
- /* #endif */
46
- }
53
+ module ,
54
+ { } ,
55
+ // @ts -ignore
56
+ options
47
57
)
48
58
swift . main ( )
49
59
}
You can’t perform that action at this time.
0 commit comments