]>
git.proxmox.com Git - rustc.git/blob - debian/wasi-node
1 #!/usr/bin
/node
--experimental
-wasi
-unstable
-preview1
3 /// Simple WASI executor, adapted from the NodeJS WASI module API docs [1].
5 /// Usage: wasi-node <command> [<args> .. ]
7 /// Environment variables:
9 /// WASI_NODE_PREOPENS - optional JSON file defining the application sandbox
10 /// directory structure. See [1] for details.
12 /// WASI_NODE_ENV - optional JSON file defining the application environment.
13 /// If omitted then the process's POSIX environment is used; this may leak
14 /// information. If a clean environment is required then set this to /dev/null
15 /// or some other empty file.
17 /// [1] https://nodejs.org/api/wasi.html
20 const fs
= require('fs');
21 const { WASI
} = require('wasi');
24 // argv[1] is this script
25 var args
= process
.argv
.slice(2); // inner argv includes cmd
28 console
.warn(process
.argv
[1] + ": no command given");
33 var preopens_json
= process
.env
["WASI_NODE_PREOPENS"];
35 var preopens_data
= fs
.readFileSync(preopens_json
);
36 preopens
= preopens_data
.length
? JSON
.parse(preopens_data
) : {};
39 var env
= process
.env
;
40 var env_json
= process
.env
["WASI_NODE_ENV"];
42 var env_data
= fs
.readFileSync(env_json
);
43 env
= env_data
.length
? JSON
.parse(env_data
) : {};
46 const wasi
= new WASI({ args
: args
, env
: env
, preopens
: preopens
});
47 const importObject
= { wasi_snapshot_preview1
: wasi
.wasiImport
};
50 const wasm
= await WebAssembly
.compile(fs
.readFileSync(args
[0]));
51 const instance
= await WebAssembly
.instantiate(wasm
, importObject
);