Skip to content

Commit 1f03a77

Browse files
authored
Merge pull request #10 from dhil/wasmfx-merge
Merge with upstream
2 parents b97199b + 83e59df commit 1f03a77

File tree

26 files changed

+1360
-401
lines changed

26 files changed

+1360
-401
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/c/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,11 @@ extern void {ns}_{snake}_drop_own({own} handle);
10401040
let import_module = if self.in_import {
10411041
self.wasm_import_module.unwrap().to_string()
10421042
} else {
1043-
match self.interface {
1043+
let module = match self.interface {
10441044
Some((_, key)) => self.resolve.name_world_key(key),
10451045
None => unimplemented!("resource exports from worlds"),
1046-
}
1046+
};
1047+
format!("[export]{module}")
10471048
};
10481049

10491050
let drop_fn = format!("__wasm_import_{ns}_{snake}_drop");

crates/csharp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ wasm-metadata = { workspace = true }
2323
heck = { workspace = true }
2424
clap = { workspace = true, optional = true }
2525
anyhow = { workspace = true }
26+
indexmap = { workspace = true }
2627

2728
[dev-dependencies]
2829
test-helpers = { path = '../test-helpers' }

crates/csharp/src/RepTable.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* This class is used to assign a unique integer identifier to instances of
3+
* exported resources, which the host will use as its "core representation" per
4+
* https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#definition-types.
5+
* The identifier may be used to retrieve the corresponding instance e.g. when
6+
* lifting a handle as part of the canonical ABI implementation.
7+
*/
8+
internal class RepTable<T> {
9+
private List<object> list = new List<object>();
10+
private int? firstVacant = null;
11+
12+
private class Vacant {
13+
internal int? next;
14+
15+
internal Vacant(int? next) {
16+
this.next = next;
17+
}
18+
}
19+
20+
internal int Add(T v) {
21+
int rep;
22+
if (firstVacant.HasValue) {
23+
rep = firstVacant.Value;
24+
firstVacant = ((Vacant) list[rep]).next;
25+
list[rep] = v;
26+
} else {
27+
rep = list.Count;
28+
list.Add(v);
29+
}
30+
return rep;
31+
}
32+
33+
internal T Get(nint rep) {
34+
if (list[(int)rep] is Vacant) {
35+
throw new ArgumentException("invalid rep");
36+
}
37+
return (T) list[(int)rep];
38+
}
39+
40+
internal T Remove(nint rep) {
41+
var val = Get(rep);
42+
list[(int)rep] = new Vacant(firstVacant);
43+
firstVacant = (int)rep;
44+
return (T) val;
45+
}
46+
}

crates/csharp/src/csproj.rs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ impl CSProjectLLVMBuilder {
8080
<ItemGroup>
8181
<NativeLibrary Include=\"{camel}_component_type.o\" />
8282
<NativeLibrary Include=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o\" />
83-
8483
</ItemGroup>
8584
8685
<ItemGroup>
@@ -185,18 +184,6 @@ impl CSProjectMonoBuilder {
185184

186185
let aot = self.aot;
187186

188-
fs::write(
189-
self.dir.join("rd.xml"),
190-
format!(
191-
r#"<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
192-
<Application>
193-
<Assembly Name="{name}">
194-
</Assembly>
195-
</Application>
196-
</Directives>"#
197-
),
198-
)?;
199-
200187
let maybe_aot = match aot {
201188
true => format!("<WasmBuildNative>{aot}</WasmBuildNative>"),
202189
false => String::new(),
@@ -208,13 +195,11 @@ impl CSProjectMonoBuilder {
208195
<PropertyGroup>
209196
<TargetFramework>net9.0</TargetFramework>
210197
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
211-
212-
<TargetOs>wasi</TargetOs>
198+
<OutputType>Library</OutputType>
213199
{maybe_aot}
200+
<RunAOTCompilation>{aot}</RunAOTCompilation>
214201
<WasmNativeStrip>false</WasmNativeStrip>
215-
<IsBrowserWasmProject>false</IsBrowserWasmProject>
216202
<WasmSingleFileBundle>true</WasmSingleFileBundle>
217-
218203
<RootNamespace>{name}</RootNamespace>
219204
<ImplicitUsings>enable</ImplicitUsings>
220205
<Nullable>enable</Nullable>
@@ -227,32 +212,27 @@ impl CSProjectMonoBuilder {
227212
</PropertyGroup>
228213
229214
<ItemGroup>
230-
<NativeLibrary Include=\"{camel}_component_type.o\" />
215+
<NativeFileReference Include=\"{camel}_component_type.o\" Condition=\"Exists('{camel}_component_type.o')\"/>
231216
</ItemGroup>
232217
233-
<ItemGroup>
234-
<RdXmlFile Include=\"rd.xml\" />
235-
</ItemGroup>
236218
"
237219
);
238220

239-
if self.aot {
240-
fs::write(
241-
self.dir.join("nuget.config"),
242-
r#"<?xml version="1.0" encoding="utf-8"?>
243-
<configuration>
244-
<config>
245-
<add key="globalPackagesFolder" value=".packages" />
246-
</config>
247-
<packageSources>
248-
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
249-
<clear />
250-
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
251-
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
252-
</packageSources>
253-
</configuration>"#,
254-
)?;
255-
}
221+
fs::write(
222+
self.dir.join("nuget.config"),
223+
r#"<?xml version="1.0" encoding="utf-8"?>
224+
<configuration>
225+
<config>
226+
<add key="globalPackagesFolder" value=".packages" />
227+
</config>
228+
<packageSources>
229+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
230+
<clear />
231+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
232+
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
233+
</packageSources>
234+
</configuration>"#,
235+
)?;
256236

257237
if self.clean_targets {
258238
let mut wasm_filename = self.dir.join(name);

0 commit comments

Comments
 (0)