Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the mono runtime test config #958

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/csharp/src/csproj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl CSProjectLLVMBuilder {
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -109,6 +111,7 @@ impl CSProjectLLVMBuilder {
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
<!--<add key="dotnet-experimental" value="C:\github\runtimelab\artifacts\packages\Debug\Shipping" />-->
</packageSources>
Expand Down Expand Up @@ -168,7 +171,7 @@ impl CSProjectMonoBuilder {
};

let mut csproj = format!(
"<Project Sdk=\"Microsoft.NET.Sdk\">
"<Project Sdk=\"Microsoft.NET.Sdk.WebAssembly\">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
Expand All @@ -182,6 +185,8 @@ impl CSProjectMonoBuilder {
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WasmGenerateAppBundle>true</WasmGenerateAppBundle>
<WasmBuildNative>true</WasmBuildNative>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -190,9 +195,17 @@ impl CSProjectMonoBuilder {
</PropertyGroup>

<ItemGroup>
<NativeFileReference Include=\"{camel}_component_type.o\" Condition=\"Exists('{camel}_component_type.o')\"/>
<_WasiLinkStepArgs Include=\"-Wl,--component-type,{camel}_component_type.wit\" />
<!-- both versions of these seem to fail to find the .o
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wit-bindgen doesn't produce the object file directly anymore,

I've used:

<CustomLinkerArg Include="@(WitComponentImports->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" />

In https://github.com/bytecodealliance/componentize-dotnet/pull/35/files#diff-7f4dfa8be7454aa047e35760bfbb0f95c0e1402fd34943606ccd9975e45b8b71

Not sure if _WasiLinkStepArgs is the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's another case of bad coevolution dotnet/runtime#107194 but they will be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolution there is that everybody should use LinkerArg over all the other options

<_WasiLinkStepArgs Include=\"-Wl,--component-type,&quot;$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '{camel}_component_type.wit').Replace('\\','/'))&quot;\" />
-->
</ItemGroup>

<Target Name=\"_FixRootAssembly\" AfterTargets=\"PrepareForILLink\">
<ItemGroup>
<TrimmerRootAssembly Update=\"@(TrimmerRootAssembly)\" Condition=\" '%(RootMode)' == 'EntryPoint' \" RootMode=\"Library\" />
</ItemGroup>
</Target>
"
);

Expand Down
9 changes: 5 additions & 4 deletions tests/runtime/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
fs::write(dst, contents).unwrap();
}

let mut csproj = wit_bindgen_csharp::CSProject::new_mono(
let csproj = wit_bindgen_csharp::CSProject::new_mono(
out_dir.clone(),
&assembly_name,
world_name,
Expand All @@ -553,6 +553,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
csproj.generate()?;

let dotnet_root_env = "DOTNET_ROOT";
let configuration = "Debug";
let dotnet_cmd: PathBuf;
match env::var(dotnet_root_env) {
Ok(val) => dotnet_cmd = Path::new(&val).join("dotnet"),
Expand All @@ -563,10 +564,10 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {

cmd.current_dir(&out_dir);

cmd.arg("build")
cmd.arg("publish")
.arg(out_dir.join(format!("{camel}.csproj")))
.arg("-c")
.arg("Debug")
.arg(configuration)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.arg(configuration)
.arg(configuration)
.arg("-bl:publish-mono.binlog")

.arg("/p:PlatformTarget=AnyCPU")
.arg("--self-contained")
Copy link

@pavelsavara pavelsavara Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me --self-contained doesn't' work with 9.0.100-preview.6.24328.19 without workload. The publish doesn't fail but the file is located elsewhere and it's not single file.

After I install workload Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk version 9.0.0-preview.6.24327.7 I get

FooWorld failed with 4 error(s) (11.4s) → xxx\
    wasm-ld : error : unknown argument: --component-type
    wasm-ld : error : unknown file type: FooWorld_component_type.wit

Which makes sense for preview6.

With preview7 I get

    1: error while executing at wasm backtrace:
           0: 0x296a7b - .tmpJCkP17!fseek
           1: 0x8efe - .tmpJCkP17!load_icu_data
           2: 0x8ff4 - .tmpJCkP17!mono_wasm_load_runtime
           3: 0x9299 - .tmpJCkP17!initialize_runtime
           4: 0x92b8 - .tmpJCkP17!main
           5: 0x28bc5c - .tmpJCkP17!__main_void
           6: 0x7e78 - .tmpJCkP17!_start
           7: 0xb40aff - wit-component:adapter:wasi_snapshot_preview1!wasi:cli/run@0.2.0#run

Which means <WasmSingleFileBundle>true</WasmSingleFileBundle> didn't work.

Copy link
Contributor Author

@lewing lewing Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing about this will work without the workload, I'm testing against daily builds of 9

using https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script
and dotnet-install -c 9.0 -q daily

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add <WasmBuildNative>true</WasmBuildNative> to get it to produce a single file

.arg("-o")
Expand All @@ -586,7 +587,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
panic!("failed to compile");
}

let out_wasm = out_wasm.join("AppBundle").join(assembly_name);
let out_wasm = out_dir.join("bin").join(configuration).join("net9.0").join("AppBundle").join(assembly_name);
let mut wasm_filename = out_wasm.clone();
wasm_filename.set_extension("wasm");

Expand Down
Loading