Stream: general

Topic: Errors when compiling C# as a WASM component with wit world


view this post on Zulip SeanOMik (Nov 05 2024 at 23:36):

I'm trying to follow the guide here for compiling C# as a WASM component, but I'm getting an error:

Restore complete (0.4s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  dotnet-guest-test failed with 1 error(s) (2.8s)  bin/Debug/net9.0/wasi-wasm/dotnet-guest-test.dll
    /home/seanomik/.nuget/packages/microsoft.dotnet.ilcompiler.llvm/10.0.0-alpha.1.24525.6/build/Microsoft.NETCore.Native.targets(363,5): error MSB3073: The command ""\tools\\ilc" @"obj/Debug/net9.0/wasi-wasm/native/dotnet-guest-test.ilc.rsp"" exited with code 127.

I'm on Arch Linux and installed dotnet-sdk-preview-bin to get dotnet 9.0. I tried to switch the target to 8.0, but got the same error. I even tried to downgrade dotnet to 8.0, but that didn't change anything. I tried to build the project in a podman container using mcr.microsoft.com/dotnet/sdk:9.0 which is based off of Debian 12, but got the same error.

Any help appreciated!

view this post on Zulip Milan (Nov 06 2024 at 00:07):

My understanding is that componentize-dotnet and specifically the NativeAOT compiler are not supported on Linux yet, see the note under Getting Started: https://bytecodealliance.org/articles/simplifying-components-for-dotnet-developers-with-componentize-dotnet

If you’re a .NET/C# developer, componentize-dotnet makes it easy to compile your code to WebAssembly components using a single tool. This Bytecode Alliance project is a NuGet package that can be used to create a fully AOT-compiled compon...

view this post on Zulip SeanOMik (Nov 06 2024 at 13:28):

Damn, okay. I didn't see that page. Maybe I'll make a windows vm just for compiling this component then lol. I actually found a PR that was opened a week ago on the componentize-dotnet repo to fix linux support. I tried that fork, but it didn't fix it :sad: so I made a comment.

The reference to <Import Project="build\BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" /> was causing the SDK to pull the Windows specific dep in at packaging time: dotnet li...

view this post on Zulip Joel Dice (Nov 06 2024 at 15:30):

I've used componentize-dotnet on Linux, although I had to hack a few files to make it work. Since then, I think those fixes have been upstreamed, so I would have expected it to work out-of-the-box at this point. @James Sturtevant would you expect that to work?

view this post on Zulip SeanOMik (Nov 06 2024 at 15:34):

Its possible I'm missing a required system package. I'm pretty new to compiling C# to WASM, and relatively new to C# in general. All I did was install the dotnet 9.0 preview, the exact version is9.0.100-rc.2.24474.11. I have Rust stable and nightly installed. Not sure if I need to install something else.

view this post on Zulip Ralph (Nov 06 2024 at 15:44):

James is PDT, so he'll not quite be up yet..... but I think Joel is correct.

view this post on Zulip James Sturtevant (Nov 06 2024 at 16:42):

It does work on Linux but there is a bug when the pacakges are published to nuget via a Windows machine: It always hard links the windows LLVM compiler: https://github.com/bytecodealliance/componentize-dotnet/issues/55. If you build the pacakge on linux you get the opposite affect.

After adding componentize-dotnet dep, You should be able to manualy add the correct LLVM pacakge with: dotnet add runtime.linux-x64.Microsoft.DotNet.ILCompiler.LLVM . If you are on the latest preview of .net9 then a dotnet publish is required to generate the package.

Been working on resolving this in https://github.com/bytecodealliance/componentize-dotnet/pull/54 but ran into some issues with the latest preview version on .net9, mainly some of the build flags changed leading to the same issues you've seen in https://github.com/bytecodealliance/componentize-dotnet/pull/54#issuecomment-2459742388

Currently the package only pulls in the Windows version of the runtime packages: runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM It should do this for the version that it is running against. #54 i...
The reference to <Import Project="build\BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" /> was causing the SDK to pull the Windows specific dep in at packaging time: dotnet li...
The reference to <Import Project="build\BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" /> was causing the SDK to pull the Windows specific dep in at packaging time: dotnet li...

view this post on Zulip Jacob Lifshay (Nov 07 2024 at 05:41):

SeanOMik said:

Maybe I'll make a windows vm just for compiling this component then lol.

I would try building it using the Windows version running in Wine, it may work just fine.

view this post on Zulip Jacob Lifshay (Nov 07 2024 at 05:44):

in my experience installing Wine is much easier than creating a Windows VM (unless you already have a VM image lying around)

view this post on Zulip SeanOMik (Nov 07 2024 at 22:49):

James Sturtevant said:

It does work on Linux but there is a bug when the pacakges are published to nuget via a Windows machine: It always hard links the windows LLVM compiler: https://github.com/bytecodealliance/componentize-dotnet/issues/55. If you build the pacakge on linux you get the opposite affect.

After adding componentize-dotnet dep, You should be able to manualy add the correct LLVM pacakge with: dotnet add runtime.linux-x64.Microsoft.DotNet.ILCompiler.LLVM . If you are on the latest preview of .net9 then a dotnet publish is required to generate the package.

That fixed it, that must have been what I was missing! I struggled a bit with getting my wit world to work with bindgen, but eventually figured it out. Thanks!!

view this post on Zulip SeanOMik (Nov 07 2024 at 22:50):

Jacob Lifshay said:

SeanOMik said:

Maybe I'll make a windows vm just for compiling this component then lol.

I would try building it using the Windows version running in Wine, it may work just fine.

I'll have to try that if I do end up needing it. I wasn't sure it would work on wine since its dev stuff, not application stuff, but its worth a shot next time.

view this post on Zulip James Sturtevant (Nov 08 2024 at 16:37):

Glad it worked! I am trying to resolve that issue to make a smoother expereince but msbuild hasn't played nicely so far.


Last updated: Nov 22 2024 at 16:03 UTC