Skip to content

Commit 6cb4d00

Browse files
authored
Merge pull request #22 from dhil/wasmfx-merge
Merge with upstream
2 parents f768245 + e4fa254 commit 6cb4d00

File tree

16 files changed

+289
-303
lines changed

16 files changed

+289
-303
lines changed

Cargo.lock

Lines changed: 169 additions & 221 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resolver = "2"
1818

1919
[workspace.package]
2020
edition = "2021"
21-
version = "0.28.0"
21+
version = "0.29.0"
2222
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
2323
repository = "https://github.com/bytecodealliance/wasi-rs"
2424

@@ -32,20 +32,20 @@ indexmap = "2.0.0"
3232
prettyplease = "0.2.20"
3333
syn = { version = "2.0", features = ["printing"] }
3434

35-
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.214.0" }
36-
wasm-metadata = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.214.0" }
37-
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.214.0" }
38-
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.214.0" }
39-
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.214.0" }
35+
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
36+
wasm-metadata = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
37+
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
38+
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
39+
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "v1.215.0" }
4040

41-
wit-bindgen-core = { path = 'crates/core', version = '0.28.0' }
42-
wit-bindgen-c = { path = 'crates/c', version = '0.28.0' }
43-
wit-bindgen-rust = { path = "crates/rust", version = "0.28.0" }
44-
wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.28.0' }
45-
wit-bindgen-go = { path = 'crates/go', version = '0.28.0' }
46-
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.28.0' }
47-
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.28.0' }
48-
wit-bindgen = { path = 'crates/guest-rust', version = '0.28.0', default-features = false }
41+
wit-bindgen-core = { path = 'crates/core', version = '0.29.0' }
42+
wit-bindgen-c = { path = 'crates/c', version = '0.29.0' }
43+
wit-bindgen-rust = { path = "crates/rust", version = "0.29.0" }
44+
wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.29.0' }
45+
wit-bindgen-go = { path = 'crates/go', version = '0.29.0' }
46+
wit-bindgen-csharp = { path = 'crates/csharp', version = '0.29.0' }
47+
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.29.0' }
48+
wit-bindgen = { path = 'crates/guest-rust', version = '0.29.0', default-features = false }
4949

5050
[[bin]]
5151
name = "wit-bindgen"

crates/c/tests/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn rename_option() -> Result<()> {
9494
opts.rename.push(("c".to_string(), "rename3".to_string()));
9595

9696
let mut resolve = Resolve::default();
97-
let pkgs = resolve.push_group(UnresolvedPackageGroup::parse(
97+
let pkg = resolve.push_group(UnresolvedPackageGroup::parse(
9898
"input.wit",
9999
r#"
100100
package foo:bar;
@@ -118,7 +118,7 @@ fn rename_option() -> Result<()> {
118118
}
119119
"#,
120120
)?)?;
121-
let world = resolve.select_world(&pkgs, None)?;
121+
let world = resolve.select_world(pkg, None)?;
122122
let mut files = Default::default();
123123
opts.build().generate(&resolve, world, &mut files)?;
124124
for (file, contents) in files.iter() {

crates/csharp/src/lib.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ impl WorldGenerator for CSharp {
471471
{{
472472
get
473473
{{
474-
if (Tag == OK)
474+
if (Tag == OK)
475475
return (Ok)value;
476-
else
476+
else
477477
throw new ArgumentException("expected OK, got " + Tag);
478478
}}
479479
}}
@@ -503,23 +503,23 @@ impl WorldGenerator for CSharp {
503503
504504
{access} class Option<T> {{
505505
private static Option<T> none = new ();
506-
506+
507507
private Option()
508508
{{
509509
HasValue = false;
510510
}}
511-
511+
512512
{access} Option(T v)
513513
{{
514514
HasValue = true;
515515
Value = v;
516516
}}
517-
517+
518518
{access} static Option<T> None => none;
519-
519+
520520
[MemberNotNullWhen(true, nameof(Value))]
521521
{access} bool HasValue {{ get; }}
522-
522+
523523
{access} T? Value {{ get; }}
524524
}}
525525
"#,
@@ -753,26 +753,27 @@ impl WorldGenerator for CSharp {
753753
// intended to be used non-interactively at link time, the
754754
// linker will have no additional information to resolve such
755755
// ambiguity.
756-
let (resolve, _) =
756+
let (resolve, world) =
757757
wit_parser::decoding::decode_world(&wit_component::metadata::encode(
758758
&resolve,
759759
id,
760760
self.opts.string_encoding,
761761
None,
762762
)?)?;
763+
let pkg = resolve.worlds[world].package.unwrap();
763764

764765
files.push(
765766
&format!("{world_namespace}_component_type.wit"),
766767
WitPrinter::default()
767768
.emit_docs(false)
768769
.print(
769770
&resolve,
771+
pkg,
770772
&resolve
771773
.packages
772774
.iter()
773-
.map(|(id, _)| id)
775+
.filter_map(|(id, _)| if id == pkg { None } else { Some(id) })
774776
.collect::<Vec<_>>(),
775-
false,
776777
)?
777778
.as_bytes(),
778779
);
@@ -1481,9 +1482,9 @@ impl InterfaceGenerator<'_> {
14811482
{access} class {upper_camel}: IDisposable {{
14821483
internal int Handle {{ get; set; }}
14831484
1484-
internal readonly record struct THandle(int Handle);
1485+
{access} readonly record struct THandle(int Handle);
14851486
1486-
internal {upper_camel}(THandle handle) {{
1487+
{access} {upper_camel}(THandle handle) {{
14871488
Handle = handle.Handle;
14881489
}}
14891490
@@ -1494,7 +1495,7 @@ impl InterfaceGenerator<'_> {
14941495
14951496
[DllImport("{module_name}", EntryPoint = "[resource-drop]{name}"), WasmImportLinkage]
14961497
private static extern void wasmImportResourceDrop(int p0);
1497-
1498+
14981499
protected virtual void Dispose(bool disposing) {{
14991500
if (Handle != 0) {{
15001501
wasmImportResourceDrop(Handle);
@@ -1564,7 +1565,7 @@ impl InterfaceGenerator<'_> {
15641565
15651566
[DllImport("{module_name}", EntryPoint = "[resource-new]{name}"), WasmImportLinkage]
15661567
internal static extern int wasmImportResourceNew(int p0);
1567-
1568+
15681569
[DllImport("{module_name}", EntryPoint = "[resource-rep]{name}"), WasmImportLinkage]
15691570
internal static extern int wasmImportResourceRep(int p0);
15701571
}}
@@ -1844,15 +1845,15 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
18441845
let tag = case.name.to_shouty_snake_case();
18451846
let ty = self.type_name(ty);
18461847
format!(
1847-
r#"{access} {ty} As{case_name}
1848-
{{
1849-
get
1848+
r#"{access} {ty} As{case_name}
1849+
{{
1850+
get
18501851
{{
1851-
if (Tag == {tag})
1852+
if (Tag == {tag})
18521853
return ({ty})value!;
1853-
else
1854+
else
18541855
throw new ArgumentException("expected {tag}, got " + Tag);
1855-
}}
1856+
}}
18561857
}}
18571858
"#
18581859
)
@@ -2584,8 +2585,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
25842585
uwrite!(
25852586
self.src,
25862587
"
2587-
var {array} = new {ty}[{length}];
2588-
new Span<{ty}>((void*)({address}), {length}).CopyTo(new Span<{ty}>({array}));
2588+
var {array} = new {ty}[{length}];
2589+
new Span<{ty}>((void*)({address}), {length}).CopyTo(new Span<{ty}>({array}));
25892590
"
25902591
);
25912592

crates/guest-rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Used when compiling Rust programs to the component model.
1212
"""
1313

1414
[dependencies]
15-
wit-bindgen-rust-macro = { path = "./macro", optional = true, version = "0.28.0" }
16-
wit-bindgen-rt = { path = "./rt", version = "0.28.0", features = ["bitflags"] }
15+
wit-bindgen-rust-macro = { path = "./macro", optional = true, version = "0.29.0" }
16+
wit-bindgen-rt = { path = "./rt", version = "0.29.0", features = ["bitflags"] }
1717

1818
[features]
1919
default = ["macros", "realloc"]

crates/guest-rust/macro/src/lib.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ impl Parse for Config {
149149
}
150150
let (resolve, pkgs, files) =
151151
parse_source(&source, &features).map_err(|err| anyhow_to_syn(call_site, err))?;
152-
let world = resolve
153-
.select_world(&pkgs, world.as_deref())
152+
let world = select_world(&resolve, &pkgs, world.as_deref())
154153
.map_err(|e| anyhow_to_syn(call_site, e))?;
155154
Ok(Config {
156155
opts,
@@ -161,6 +160,43 @@ impl Parse for Config {
161160
}
162161
}
163162

163+
fn select_world(
164+
resolve: &Resolve,
165+
pkgs: &[PackageId],
166+
world: Option<&str>,
167+
) -> anyhow::Result<WorldId> {
168+
if pkgs.len() == 1 {
169+
resolve.select_world(pkgs[0], world)
170+
} else {
171+
assert!(!pkgs.is_empty());
172+
match world {
173+
Some(name) => {
174+
if !name.contains(":") {
175+
anyhow::bail!(
176+
"with multiple packages a fully qualified \
177+
world name must be specified"
178+
)
179+
}
180+
181+
// This will ignore the package argument due to the fully
182+
// qualified name being used.
183+
resolve.select_world(pkgs[0], world)
184+
}
185+
None => {
186+
let worlds = pkgs
187+
.iter()
188+
.filter_map(|p| resolve.select_world(*p, None).ok())
189+
.collect::<Vec<_>>();
190+
match &worlds[..] {
191+
[] => anyhow::bail!("no packages have a world"),
192+
[world] => Ok(*world),
193+
_ => anyhow::bail!("multiple packages have a world, must specify which to use"),
194+
}
195+
}
196+
}
197+
}
198+
}
199+
164200
/// Parse the source
165201
fn parse_source(
166202
source: &Option<Source>,
@@ -182,7 +218,7 @@ fn parse_source(
182218
Err(_) => p.to_path_buf(),
183219
};
184220
let (pkg, sources) = resolve.push_path(normalized_path)?;
185-
pkgs.extend(pkg);
221+
pkgs.push(pkg);
186222
files.extend(sources);
187223
}
188224
Ok(())
@@ -192,7 +228,7 @@ fn parse_source(
192228
if let Some(p) = path {
193229
parse(p)?;
194230
}
195-
pkgs = resolve.push_group(UnresolvedPackageGroup::parse("macro-input", s)?)?;
231+
pkgs.push(resolve.push_group(UnresolvedPackageGroup::parse("macro-input", s)?)?);
196232
}
197233
Some(Source::Paths(p)) => parse(p)?,
198234
None => parse(&vec![root.join("wit")])?,

crates/guest-rust/rt/src/cabi_realloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include <stdint.h>
44

5-
extern void *cabi_realloc_wit_bindgen_0_28_0(void *ptr, size_t old_size, size_t align, size_t new_size);
5+
extern void *cabi_realloc_wit_bindgen_0_29_0(void *ptr, size_t old_size, size_t align, size_t new_size);
66

77
__attribute__((__weak__, __export_name__("cabi_realloc")))
88
void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) {
9-
return cabi_realloc_wit_bindgen_0_28_0(ptr, old_size, align, new_size);
9+
return cabi_realloc_wit_bindgen_0_29_0(ptr, old_size, align, new_size);
1010
}
0 Bytes
Binary file not shown.

crates/guest-rust/rt/src/cabi_realloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is generated by ./ci/rebuild-libcabi-realloc.sh
22

33
#[no_mangle]
4-
pub unsafe extern "C" fn cabi_realloc_wit_bindgen_0_28_0(
4+
pub unsafe extern "C" fn cabi_realloc_wit_bindgen_0_29_0(
55
old_ptr: *mut u8,
66
old_len: usize,
77
align: usize,
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)