Skip to content

Commit 83e44f4

Browse files
author
Timmy Silesmo
committed
Revert unintentional push of commit "adds new WasmImportLinkAttribute for C# and initial support for mono runtime."
This reverts commit b6fadcf.
1 parent b6fadcf commit 83e44f4

File tree

6 files changed

+23
-333
lines changed

6 files changed

+23
-333
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ CLI tool to generate bindings for WIT documents and the component model.
1111
"""
1212

1313
[workspace]
14-
members = ["crates/test-rust-wasm"]
14+
members = [
15+
"crates/test-rust-wasm",
16+
]
1517
resolver = "2"
1618

1719
[workspace.package]
@@ -20,7 +22,7 @@ edition = "2021"
2022
[workspace.dependencies]
2123
anyhow = "1.0.72"
2224
bitflags = "2.3.3"
23-
heck = { version = "0.4", features = ["unicode"] }
25+
heck = { version = "0.4", features = ["unicode"] }
2426
pulldown-cmark = { version = "0.9", default-features = false }
2527
clap = { version = "4.3.19", features = ["derive"] }
2628
env_logger = "0.10.0"
@@ -50,19 +52,22 @@ clap = { workspace = true }
5052
wit-bindgen-core = { workspace = true }
5153
wit-bindgen-rust = { workspace = true, features = ['clap'], optional = true }
5254
wit-bindgen-c = { workspace = true, features = ['clap'], optional = true }
53-
wit-bindgen-markdown = { workspace = true, features = [
54-
'clap',
55-
], optional = true }
56-
wit-bindgen-teavm-java = { workspace = true, features = [
57-
'clap',
58-
], optional = true }
55+
wit-bindgen-markdown = { workspace = true, features = ['clap'], optional = true }
56+
wit-bindgen-teavm-java = { workspace = true, features = ['clap'], optional = true }
5957
wit-bindgen-go = { workspace = true, features = ['clap'], optional = true }
6058
wit-bindgen-csharp = { workspace = true, features = ['clap'], optional = true }
6159
wit-component = { workspace = true }
6260
wasm-encoder = { workspace = true }
6361

6462
[features]
65-
default = ['c', 'rust', 'markdown', 'teavm-java', 'go', 'csharp-naot']
63+
default = [
64+
'c',
65+
'rust',
66+
'markdown',
67+
'teavm-java',
68+
'go',
69+
'csharp-naot',
70+
]
6671
c = ['dep:wit-bindgen-c']
6772
rust = ['dep:wit-bindgen-rust']
6873
markdown = ['dep:wit-bindgen-markdown']
@@ -78,5 +83,3 @@ wasmtime = { version = "15", features = ['component-model'] }
7883
wasmtime-wasi = { workspace = true }
7984
test-artifacts = { path = 'crates/test-rust-wasm/artifacts' }
8085
wit-parser = { workspace = true }
81-
wasmparser = "0.118.0"
82-
wasm-encoder = { workspace = true }

crates/csharp/src/csproj.rs

Lines changed: 4 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::{fs, path::PathBuf};
33

44
use heck::ToUpperCamelCase;
55

6-
pub struct CSProject;
7-
8-
pub struct CSProjectLLVMBuilder {
6+
pub struct CSProject {
97
name: String,
108
dir: PathBuf,
119
aot: bool,
@@ -14,17 +12,9 @@ pub struct CSProjectLLVMBuilder {
1412
wasm_imports: Vec<(String, String)>,
1513
}
1614

17-
pub struct CSProjectMonoBuilder {
18-
name: String,
19-
dir: PathBuf,
20-
aot: bool,
21-
clean_targets: bool,
22-
world_name: String,
23-
}
24-
2515
impl CSProject {
26-
pub fn new(dir: PathBuf, name: &str, world_name: &str) -> CSProjectLLVMBuilder {
27-
CSProjectLLVMBuilder {
16+
pub fn new(dir: PathBuf, name: &str, world_name: &str) -> CSProject {
17+
CSProject {
2818
name: name.to_string(),
2919
dir,
3020
aot: false,
@@ -34,18 +24,6 @@ impl CSProject {
3424
}
3525
}
3626

37-
pub fn new_mono(dir: PathBuf, name: &str, world_name: &str) -> CSProjectMonoBuilder {
38-
CSProjectMonoBuilder {
39-
name: name.to_string(),
40-
dir,
41-
aot: false,
42-
clean_targets: false,
43-
world_name: world_name.to_string(),
44-
}
45-
}
46-
}
47-
48-
impl CSProjectLLVMBuilder {
4927
pub fn generate(&self) -> Result<()> {
5028
let name = &self.name;
5129
let world = &self.world_name.replace("-", "_");
@@ -170,125 +148,12 @@ impl CSProjectLLVMBuilder {
170148
self.aot = true;
171149
}
172150

173-
pub fn clean(&mut self) -> &mut Self {
151+
pub fn clean(&mut self) {
174152
self.clean_targets = true;
175-
176-
self
177153
}
178154

179155
pub fn add_import(&mut self, module_name: &str, func_name: &str) {
180156
self.wasm_imports
181157
.push((module_name.to_string(), func_name.to_string()));
182158
}
183159
}
184-
185-
impl CSProjectMonoBuilder {
186-
pub fn generate(&self) -> Result<()> {
187-
let name = &self.name;
188-
let world = &self.world_name.replace("-", "_");
189-
let snake_world = world.to_upper_camel_case();
190-
191-
let aot = self.aot;
192-
193-
fs::write(
194-
self.dir.join("rd.xml"),
195-
format!(
196-
r#"<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
197-
<Application>
198-
<Assembly Name="{name}">
199-
</Assembly>
200-
</Application>
201-
</Directives>"#
202-
),
203-
)?;
204-
205-
let mut csproj = format!(
206-
"<Project Sdk=\"Microsoft.NET.Sdk\">
207-
208-
<PropertyGroup>
209-
<TargetFramework>net9.0</TargetFramework>
210-
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
211-
212-
<TargetOs>wasi</TargetOs>
213-
<WasmBuildNative>{aot}</WasmBuildNative>
214-
<WasmNativeStrip>false</WasmNativeStrip>
215-
<IsBrowserWasmProject>false</IsBrowserWasmProject>
216-
<WasmSingleFileBundle>true</WasmSingleFileBundle>
217-
218-
<RootNamespace>{name}</RootNamespace>
219-
<ImplicitUsings>enable</ImplicitUsings>
220-
<Nullable>enable</Nullable>
221-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
222-
</PropertyGroup>
223-
224-
<PropertyGroup>
225-
<PublishTrimmed>true</PublishTrimmed>
226-
<AssemblyName>{name}</AssemblyName>
227-
</PropertyGroup>
228-
229-
<ItemGroup>
230-
<NativeLibrary Include=\"{world}_component_type.o\" />
231-
</ItemGroup>
232-
233-
<ItemGroup>
234-
<RdXmlFile Include=\"rd.xml\" />
235-
</ItemGroup>
236-
"
237-
);
238-
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-
}
256-
257-
if self.clean_targets {
258-
let mut wasm_filename = self.dir.join(name);
259-
wasm_filename.set_extension("wasm");
260-
// In CI we run out of disk space if we don't clean up the files, we don't need to keep any of it around.
261-
csproj.push_str(&format!(
262-
"<Target Name=\"CleanAndDelete\" AfterTargets=\"Clean\">
263-
<!-- Remove obj folder -->
264-
<RemoveDir Directories=\"$(BaseIntermediateOutputPath)\" />
265-
<!-- Remove bin folder -->
266-
<RemoveDir Directories=\"$(BaseOutputPath)\" />
267-
<RemoveDir Directories=\"{}\" />
268-
<RemoveDir Directories=\".packages\" />
269-
</Target>",
270-
wasm_filename.display()
271-
));
272-
}
273-
274-
csproj.push_str(
275-
r#"</Project>
276-
"#,
277-
);
278-
279-
let camel = snake_world.to_upper_camel_case();
280-
fs::write(self.dir.join(format!("{camel}.csproj")), csproj)?;
281-
282-
Ok(())
283-
}
284-
285-
pub fn aot(&mut self) {
286-
self.aot = true;
287-
}
288-
289-
pub fn clean(&mut self) -> &mut Self {
290-
self.clean_targets = true;
291-
292-
self
293-
}
294-
}

crates/csharp/src/lib.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ pub struct Opts {
4545
pub string_encoding: StringEncoding,
4646
#[cfg_attr(feature = "clap", arg(long))]
4747
pub generate_stub: bool,
48-
49-
// TODO: This should only temporarily needed until mono and native aot aligns.
50-
#[cfg_attr(feature = "clap", arg(short, long, value_enum))]
51-
pub runtime: CSharpRuntime,
5248
}
5349

5450
impl Opts {
@@ -60,14 +56,6 @@ impl Opts {
6056
}
6157
}
6258

63-
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
64-
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
65-
pub enum CSharpRuntime {
66-
#[default]
67-
NativeAOT,
68-
Mono,
69-
}
70-
7159
struct InterfaceFragment {
7260
csharp_src: String,
7361
csharp_interop_src: String,
@@ -499,22 +487,6 @@ impl WorldGenerator for CSharp {
499487
);
500488
}
501489

502-
//TODO: This is currently neede for mono even if it's built as a library.
503-
if self.opts.runtime == CSharpRuntime::Mono {
504-
files.push(
505-
&format!("MonoEntrypoint.cs",),
506-
indent(
507-
r#"
508-
public class MonoEntrypoint() {
509-
public static void Main() {
510-
}
511-
}
512-
"#,
513-
)
514-
.as_bytes(),
515-
);
516-
}
517-
518490
files.push(
519491
&format!("{snake}_component_type.o",),
520492
component_type_object::object(resolve, id, self.opts.string_encoding)
@@ -627,7 +599,7 @@ impl InterfaceGenerator<'_> {
627599
});
628600
}
629601

630-
fn import(&mut self, module: &String, func: &Function) {
602+
fn import(&mut self, _module: &String, func: &Function) {
631603
if func.kind != FunctionKind::Freestanding {
632604
todo!("resources");
633605
}
@@ -694,14 +666,12 @@ impl InterfaceGenerator<'_> {
694666
.join(", ");
695667

696668
let import_name = &func.name;
697-
698669
uwrite!(
699670
self.csharp_interop_src,
700671
r#"
701672
internal static class {camel_name}Interop
702673
{{
703-
[WasmImportLinkage]
704-
[DllImport("{module}", EntryPoint = "{import_name}")]
674+
[DllImport("*", EntryPoint = "{import_name}")]
705675
internal static extern {wasm_result_type} wasmImport{camel_name}({wasm_params});
706676
}}
707677
"#

crates/csharp/tests/codegen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ macro_rules! codegen_test {
7171
wit_bindgen_csharp::Opts {
7272
generate_stub: true,
7373
string_encoding: StringEncoding::UTF8,
74-
runtime: Default::default(),
7574
}
7675
.build()
7776
.generate(resolve, world, files)

0 commit comments

Comments
 (0)