Skip to content

Commit

Permalink
Node.js IO & Poll implementation (bytecodealliance#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Nov 14, 2023
1 parent 74396b4 commit 8ed4096
Show file tree
Hide file tree
Showing 91 changed files with 3,273 additions and 2,067 deletions.
99 changes: 59 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ version = "0.13.2"

[workspace.dependencies]
anyhow = "1.0.75"
base64 = "0.21.4"
base64 = "0.21.5"
heck = { version = "0.4", features = ["unicode"] }
indexmap = "2.0"
js-component-bindgen = { path = "./crates/js-component-bindgen" }
structopt = "0.3.25"
structopt = "0.3.26"
tempdir = "0.3.7"
wasm-encoder = "0.35.0"
wasm-metadata = "0.10.9"
wasmparser = "0.115.0"
wasmprinter = "0.2.70"
wasmtime-environ = { version = "14.0.1", features = ["component-model"] }
wat = "1.0.77"
wit-bindgen = { version = "0.13.0" }
wit-bindgen-core = { version = "0.13.0" }
wit-component = { version = "0.16.0", features = ["dummy-module"] }
wit-parser = "0.12.1"
wasm-encoder = "0.36.2"
wasm-metadata = "0.10.11"
wasmparser = "0.116.1"
wasmprinter = "0.2.72"
wasmtime-environ = { version = "14.0.4", features = ["component-model"] }
wat = "1.0.79"
wit-bindgen = { version = "0.14.0" }
wit-bindgen-core = { version = "0.14.0" }
wit-component = { version = "0.18.0", features = ["dummy-module"] }
wit-parser = "0.13.0"
xshell = "0.2.5"

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package local:js-component-bindgen
package local:js-component-bindgen;

world js-component-bindgen {
type files = list<tuple<string, list<u8>>>
type maps = list<tuple<string, string>>
type files = list<tuple<string, list<u8>>>;
type maps = list<tuple<string, string>>;

variant instantiation-mode {
async,
Expand Down Expand Up @@ -79,7 +79,7 @@ world js-component-bindgen {
/// Generate the file structure for the transpiled of a component
/// into a JS embedding, returns the file list and imports and exports of the
/// output JS generation component
export generate: func(component: list<u8>, options: generate-options) -> result<transpiled, string>
export generate: func(component: list<u8>, options: generate-options) -> result<transpiled, string>;

export generate-types: func(name: string, options: type-generation-options) -> result<files, string>
export generate-types: func(name: string, options: type-generation-options) -> result<files, string>;
}
4 changes: 2 additions & 2 deletions crates/js-component-bindgen/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ pub fn render_intrinsics(
"),

Intrinsic::ToBigInt64 => output.push_str("
const toInt64 = val => BigInt.asIntN(64, val);
const toInt64 = val => BigInt.asIntN(64, BigInt(val));
"),

Intrinsic::ToBigUint64 => output.push_str("
const toUint64 = val => BigInt.asUintN(64, val);
const toUint64 = val => BigInt.asUintN(64, BigInt(val));
"),

Intrinsic::ToInt16 => output.push_str("
Expand Down
11 changes: 8 additions & 3 deletions crates/wasm-tools-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ impl Guest for WasmToolsJs {
None => None,
};

let encoded =
wit_component::metadata::encode(&resolve, world, string_encoding, producers.as_ref())
.map_err(|e| e.to_string())?;
let encoded = wit_component::metadata::encode(
&resolve,
world,
string_encoding,
producers.as_ref(),
Some(true),
)
.map_err(|e| e.to_string())?;

let section = wasm_encoder::CustomSection {
name: "component-type".into(),
Expand Down
20 changes: 10 additions & 10 deletions crates/wasm-tools-component/wit/wasm-tools.wit
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package local:wasm-tools
package local:wasm-tools;

interface tools {
/// Translate the WebAssembly text format to binary
parse: func(wat: string) -> result<list<u8>, string>
parse: func(wat: string) -> result<list<u8>, string>;

/// Translate the WebAssembly binary format to text
print: func(binary: list<u8>) -> result<string, string>
print: func(binary: list<u8>) -> result<string, string>;

enum string-encoding {
utf8,
Expand All @@ -14,12 +14,12 @@ interface tools {
}

/// Create a component from a core wasm binary that implements and embeds a component type
component-new: func(binary: list<u8>, adapters: option<list<tuple<string, list<u8>>>>) -> result<list<u8>, string>
component-new: func(binary: list<u8>, adapters: option<list<tuple<string, list<u8>>>>) -> result<list<u8>, string>;

/// Extract a *.wit interface from a component, optionally providing a document name to extract
component-wit: func(binary: list<u8>) -> result<string, string>
component-wit: func(binary: list<u8>) -> result<string, string>;

type producers-fields = list<tuple<string, list<tuple<string, string>>>>
type producers-fields = list<tuple<string, list<tuple<string, string>>>>;

/// Embed a WIT type into a component.
/// Only a singular WIT document without use resolutions is supported for this API.
Expand All @@ -35,7 +35,7 @@ interface tools {
metadata: option<producers-fields>
}

component-embed: func(embed-opts: embed-opts) -> result<list<u8>, string>
component-embed: func(embed-opts: embed-opts) -> result<list<u8>, string>;

variant module-meta-type {
module,
Expand All @@ -51,12 +51,12 @@ interface tools {
}

/// Extract the metadata for a component
metadata-show: func(binary: list<u8>) -> result<list<module-metadata>, string>
metadata-show: func(binary: list<u8>) -> result<list<module-metadata>, string>;

/// Append producer metadata to a component
metadata-add: func(binary: list<u8>, metadata: producers-fields) -> result<list<u8>, string>
metadata-add: func(binary: list<u8>, metadata: producers-fields) -> result<list<u8>, string>;
}

world wasm-tools {
export tools
export tools;
}
Loading

0 comments on commit 8ed4096

Please sign in to comment.