Skip to content

Commit

Permalink
Merge pull request #4 from golemcloud/update-upstream
Browse files Browse the repository at this point in the history
Update upstream
  • Loading branch information
noise64 authored Aug 26, 2024
2 parents 5f0feb4 + fad2987 commit 9ae1f0a
Show file tree
Hide file tree
Showing 52 changed files with 25,673 additions and 649 deletions.
173 changes: 87 additions & 86 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resolver = "2"

[workspace.package]
edition = "2021"
version = "1.4.0"
version = "1.4.4"

[profile.release]
codegen-units = 1
Expand All @@ -37,22 +37,24 @@ strip = true
anyhow = "1.0.86"
base64 = "0.22.1"
heck = "0.5.0"
indexmap = "2.2"
indexmap = "2.4.0"
log = "0.4.22"
semver = "1.0.23"
js-component-bindgen = { path = "./crates/js-component-bindgen" }
structopt = "0.3.26"
wasm-encoder = "0.212.0"
wasm-metadata = "0.212.0"
wasmparser = "0.212.0"
wasmprinter = "0.212.0"
wasmtime-environ = { version = "23.0.1", features = [
wasm-encoder = "0.215.0"
wasm-metadata = "0.215.0"
wasmparser = "0.215.0"
wasmprinter = "0.215.0"
wasmtime-environ = { version = "24.0.0", features = [
"component-model",
"compile",
] }
wat = "1.212.0"
wit-bindgen = "0.27.0"
wit-bindgen-core = "0.27.0"
wit-component = { version = "0.212.0", features = ["dummy-module"] }
wit-parser = "0.212.0"
wat = "1.215.0"
wit-bindgen = "0.30.0"
wit-bindgen-core = "0.30.0"
wit-component = { version = "0.215.0", features = ["dummy-module"] }
wit-parser = "0.215.0"
xshell = "0.2.6"

[dev-dependencies]
Expand Down
32 changes: 25 additions & 7 deletions crates/js-component-bindgen-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ impl Guest for JsComponentBindgenComponent {
name: String,
opts: TypeGenerationOptions,
) -> Result<Vec<(String, Vec<u8>)>, String> {
let (resolve, ids) = resolve_package(opts.wit, Some(&name))?;
let (resolve, id) = resolve_package(opts.wit, opts.features, Some(&name))?;
let world_string = opts.world.map(|world| world.to_string());
let world = resolve
.select_world(&ids, world_string.as_deref())
.select_world(id, world_string.as_deref())
.map_err(|e| e.to_string())?;

let opts = js_component_bindgen::TranspileOpts {
Expand All @@ -143,10 +143,10 @@ impl Guest for JsComponentBindgenComponent {
}

fn generate_typescript_stubs(opts: TypescriptStubOptions) -> Result<Files, String> {
let (resolve, ids) = resolve_package(opts.wit, None).map_err(|e| e.to_string())?;
let (resolve, id) = resolve_package(opts.wit, None, None).map_err(|e| e.to_string())?;
let world_string = opts.world.map(|world| world.to_string());
let world = resolve
.select_world(&ids, world_string.as_deref())
.select_world(id, world_string.as_deref())
.map_err(|e| e.to_string())?;

let files = generate_typescript_stubs(resolve, world).map_err(|e| e.to_string())?;
Expand All @@ -155,10 +155,28 @@ impl Guest for JsComponentBindgenComponent {
}
}

fn resolve_package(wit_opt: Wit, name: Option<&str>) -> Result<(Resolve, Vec<PackageId>), String> {
fn resolve_package(
wit: Wit,
features: Option<EnabledFeatureSet>,
name: Option<&str>,
) -> Result<(Resolve, PackageId), String> {
let name = name.unwrap_or("world");
let mut resolve = Resolve::default();
let ids = match wit_opt {

// Add features if specified
match features {
Some(EnabledFeatureSet::List(ref features)) => {
for f in features.into_iter() {
resolve.features.insert(f.to_string());
}
}
Some(EnabledFeatureSet::All) => {
resolve.all_features = true;
}
_ => {}
}

let id = match wit {
Wit::Source(source) => resolve
.push_str(format!("{name}.wit"), &source)
.map_err(|e| e.to_string())?,
Expand All @@ -173,5 +191,5 @@ fn resolve_package(wit_opt: Wit, name: Option<&str>) -> Result<(Resolve, Vec<Pac
Wit::Binary(_) => todo!(),
};

Ok((resolve, ids))
Ok((resolve, id))
}
10 changes: 10 additions & 0 deletions crates/js-component-bindgen-component/wit/js-component-bindgen.wit
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ world js-component-bindgen {
path(string),
}

/// Enumerate enabled features
variant enabled-feature-set {
/// Enable only the given list of features
%list(list<string>),
/// Enable all features
all,
}

record type-generation-options {
/// wit to generate typing from
wit: wit,
Expand All @@ -81,6 +89,8 @@ world js-component-bindgen {
tla-compat: option<bool>,
instantiation: option<instantiation-mode>,
map: option<maps>,
/// Features that should be enabled as part of feature gating
features: option<enabled-feature-set>,
}

record typescript-stub-options {
Expand Down
4 changes: 3 additions & 1 deletion crates/js-component-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ transpile-bindgen = []

[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
heck = { workspace = true }
log = { workspace = true }
semver = { workspace = true }
wasmparser = { workspace = true }
wasmtime-environ = { workspace = true, features = ['component-model'] }
wit-bindgen-core = { workspace = true }
wit-component = { workspace = true }
wit-parser = { workspace = true }
indexmap = { workspace = true }
base64 = { workspace = true }
wasm-encoder = { workspace = true }
Loading

0 comments on commit 9ae1f0a

Please sign in to comment.