Skip to content

Commit

Permalink
Bug fixes for targeting a world with resource borrows (#300)
Browse files Browse the repository at this point in the history
Expanded test cases to cover issue #299

Also, when specifying an exact semver requirement, adds that exact requirement to the generated Cargo.toml. There was mismatch before.

wit-bindgen-rust generates different bindings for borrow<> of resources, depending on whether that type is exported in the world or not. &SomeType vs SomeTypeBorrow in the generated bindings. Fixed the logic here to match that behavior. The revised test case should better cover future potential breakage.

If interested, here is some of the logic on the wit-bindgen side:
https://github.com/bytecodealliance/wit-bindgen/blob/main/crates/rust/src/interface.rs#L2203-L2225
  • Loading branch information
calvinrp authored May 22, 2024
1 parent 4841409 commit 22d9d81
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 127 deletions.
111 changes: 71 additions & 40 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
indexmap = "2.2.6"
url = { version = "2.5.0", features = ["serde"] }
wit-parser = "0.202.0"
wit-component = "0.202.0"
wasm-metadata = "0.202.0"
wit-parser = "0.208.1"
wit-component = "0.208.1"
wasm-metadata = "0.208.1"
parse_arg = "0.1.4"
cargo_metadata = "0.18.1"
cargo-config2 = "0.1.24"
Expand All @@ -99,14 +99,14 @@ rpassword = "7.3.1"
futures = "0.3.30"
bytes = "1.6.0"
which = "6.0.1"
wit-bindgen-rust = "0.24.0"
wit-bindgen-core = "0.24.0"
wit-bindgen-rust = "0.25.0"
wit-bindgen-core = "0.25.0"
tempfile = "3.10.1"
assert_cmd = "2.0.14"
predicates = "3.1.0"
wasmparser = "0.202.0"
wat = "1.202.0"
wasmprinter = "0.202.0"
wasmparser = "0.208.1"
wat = "1.208.1"
wasmprinter = "0.208.1"

[profile.release]
panic = "abort"
Expand Down
8 changes: 2 additions & 6 deletions crates/wit/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use toml_edit::DocumentMut;
use warg_crypto::signing::PrivateKey;
use warg_protocol::operator::NamespaceState;
use warg_server::{policy::content::WasmContentPolicy, Config, Server};
use wasmparser::{Chunk, Encoding, Parser, Payload, Validator, WasmFeatures};
use wasmparser::{Chunk, Encoding, Parser, Payload, Validator};

pub fn test_operator_key() -> &'static str {
"ecdsa-p256:I+UlDo0HxyBBFeelhPPWmD+LnklOpqZDkrFP5VduASk="
Expand Down Expand Up @@ -197,11 +197,7 @@ pub fn validate_component(path: &Path) -> Result<()> {
.with_context(|| format!("failed to read `{path}`", path = path.display()))?;

// Validate the bytes as either a component or a module
Validator::new_with_features(WasmFeatures {
component_model: true,
..Default::default()
})
.validate_all(&bytes)?;
Validator::new_with_features(Default::default()).validate_all(&bytes)?;

// Check that the bytes are for a component and not a module
let mut parser = Parser::new(0);
Expand Down
22 changes: 12 additions & 10 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,19 @@ impl NewCommand {

if !self.is_command() {
if let Some((resolution, world)) = target.as_ref() {
// if specifying exact version, set that exact version in the Cargo.toml
let version = if !resolution.requirement.comparators.is_empty()
&& resolution.requirement.comparators[0].op == semver::Op::Exact
{
format!("={}", resolution.version)
} else {
format!("{}", resolution.version)
};
component["target"] = match world {
Some(world) => value(format!(
"{name}/{world}@{version}",
name = resolution.name,
version = resolution.version
)),
None => value(format!(
"{name}@{version}",
name = resolution.name,
version = resolution.version
)),
Some(world) => {
value(format!("{name}/{world}@{version}", name = resolution.name,))
}
None => value(format!("{name}@{version}", name = resolution.name,)),
};
}
}
Expand Down
Loading

0 comments on commit 22d9d81

Please sign in to comment.