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

[WASI] testing code outside of the current repo #108490

Open
jsturtevant opened this issue Oct 2, 2024 · 8 comments
Open

[WASI] testing code outside of the current repo #108490

jsturtevant opened this issue Oct 2, 2024 · 8 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Infrastructure-mono os-wasi Related to WASI variant of arch-wasm
Milestone

Comments

@jsturtevant
Copy link
Contributor

Description

This doc https://github.com/dotnet/runtime/tree/main/src/mono/wasi#how-to-build-the-runtime suggested that built runtime pack can be referenced outside of the repo by a sample project. When I use it this way I end up with some errors:

hello-wasm failed with 1 error(s) (0.7s) → bin/Debug/net9.0/wasi-wasm/publish/
    /home/jstur/.dotnet/nightly/packs/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/9.0.0-rtm.24480.7/Sdk/WasmApp.Common.targets(875,5): error :
      Failed to compile /home/jstur/projects/runtime/artifacts/bin/microsof
      t.netcore.app.runtime.wasi-wasm/Debug/runtimes/wasi-wasm/native/src/p
      invoke.c -> /home/jstur/projects/components/hello-wasm/obj/Debug/net9
      .0/wasi-wasm/wasm/for-publish/pinvoke.o
      In file included from /home/jstur/projects/runtime/artifacts/bin/micr
      osoft.netcore.app.runtime.wasi-wasm/Debug/runtimes/wasi-wasm/native/s
      rc/pinvoke.c:15:
      /home/jstur/projects/components/hello-wasm/obj/Debug/net9.0/wasi-wasm
      /wasm/for-publish/pinvoke-table.h:169:149: error: too few arguments t
      o function call, expected 6, have 5

Is there a way to reference the runtime pack for testing outside of the repository? Maybe the approach in https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/using-dev-shipping-packages.md is needed?

Running the samples provided in wasi folder in the repo work fine.

Reproduction Steps

I changed the approach a bit from what is documented in after finding other docs that suggested:

<Target Name="UpdateRuntimePack" AfterTargets="ResolveFrameworkReferences">
    <ItemGroup>
      <!-- update runtime pack to local build -->
      <ResolvedRuntimePack
        PackageDirectory="/home/jstur/projects/runtime/artifacts/bin/microsoft.netcore.app.runtime.wasi-wasm/Debug"
        Condition="'%(ResolvedRuntimePack.FrameworkName)' == 'Microsoft.NETCore.App'" />
    </ItemGroup>
  </Target>

A sample repo is in: https://github.com/jsturtevant/test-runtime

Expected behavior

Should be able to test runtime with sample projects outside repo

Actual behavior

errors with linked code

Regression?

no

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Oct 2, 2024
Copy link
Contributor

Tagging subscribers to this area: @directhex, @matouskozak
See info in area-owners.md if you want to be subscribed.

@jsturtevant
Copy link
Contributor Author

I tried https://github.com/dotnet/runtime/tree/main/src/mono/wasi#4-debug-it as well and I don't see this wired up properly to connect a debugger either.

@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-wasi Related to WASI variant of arch-wasm labels Oct 3, 2024
@pavelsavara pavelsavara added this to the 10.0.0 milestone Oct 3, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Oct 3, 2024
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

@pavelsavara
Copy link
Member

I tried https://github.com/dotnet/runtime/tree/main/src/mono/wasi#4-debug-it as well and I don't see this wired up properly to connect a debugger either.

Debugger need to be upgraded to WASIp2 #101253
It's on my TODO list

@pavelsavara pavelsavara changed the title Testing WASI code outside of the current repo [WASI] testing code outside of the current repo Oct 3, 2024
@maraf
Copy link
Member

maraf commented Oct 3, 2024

The problem is about ManagedToNativeGenerator (it's a generator that generates piece of C code for transitions between managed and unmanaged code). It has been changed recently. This generator is not part of the runtime pack, and thus it's not replaced when replacing the runtime pack.

You either need a newer SDK (some nightly build could/should work) or use older runtime commit before changes to that generator happened. This is not happening too often, typically the generator in SDK is the same what runtime pack expects

EDIT: Alternative you can build src\tasks\WasmAppBuilder\WasmAppBuilder.csproj (dotnet build src\tasks\WasmAppBuilder\WasmAppBuilder.csproj) and set MSBuild property WasmAppBuilderTasksAssemblyPath=PATH_TO_WasmAppBuilder.csproj_OUTPUT_DLL https://github.com/dotnet/runtime/blob/main/src/mono/wasm/build/WasmApp.LocalBuild.props#L68

EDIT2: Another alternative is to let the build generate a whole .NET SDK

.\build.cmd -bl -os wasi -subset mono+libs+packs -c Debug
.\dotnet.cmd build -p:TargetOS=wasi -p:TargetArchitecture=wasm -c Debug src/mono/wasm/Wasi.Build.Tests/Wasi.Build.Tests.csproj -t:InstallWorkloadUsingArtifacts

Then you can use DOTNET_RUNTIME_PATH\artifacts\bin\dotnet-latest\dotnet.exe to build projects. Such SDK needs to configure custom nuget feed to restore from packages from

<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);DOTNET_RUNTIME_PATH\artifacts\packages\Debug\Shipping\</RestoreAdditionalProjectSources>

@jsturtevant
Copy link
Contributor Author

Thanks @maraf! I tried with a recent nightly build of the SDK but got the same error when I reported this. Is it possibly related to the dotnet workload install wasi-experimental? I will try the other alternatives as well

@maraf
Copy link
Member

maraf commented Oct 8, 2024

@jsturtevant I'm sorry, I have missed the message.

Latest .NET 9 SDK is missing changes to the generator, they won't land there. You need a nightly .NET 10 SDK and that has a different set problems :/

@lewing
Copy link
Member

lewing commented Oct 9, 2024

@jsturtevant It might be possible to test with the 10.0.1xx sdk while still targeting net9 as of early this week but there may still be problems. I will try to find a few minutes to verify soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Infrastructure-mono os-wasi Related to WASI variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

4 participants