Skip to content

[wasi] Combine main function for the default and single file bundle - #85617

Merged
lewing merged 1 commit into
dotnet:mainfrom
radical:wasi-invariant-tests
May 2, 2023
Merged

lewing merged 1 commit into
dotnet:mainfrom
radical:wasi-invariant-tests

Conversation

@radical

@radical radical commented May 1, 2023 •

Copy link
Copy Markdown
Member

.. case.

This was prompted by #85616 where running Invariant.Tests breaks with:

Running /root/helix/work/correlation/wasmtime/wasmtime --dir=. --env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true dotnet.wasm WasmTestRunner managed/Invariant.Tests.dll -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing

Unhandled Exception:
System.ArgumentException: Invalid argument 'managed/Invariant.Tests.dll'.
   at SimpleWasmTestRunner.Main(String[] args)
   at SimpleWasmTestRunner.<Main>(String[] args)
  • This broke because of a recent change due to which setting InvariantGlobalization=true meant WasmBuildNative=true
  • But this did not trigger single file bundle
  • And the build ended up relinking a dotnet.wasm but using the single-file bundle main function.
  • The default, and single-file bundle main functions expect different set of command line arguments, and the mismatch causes the failure

Instead, we combine the two main functions and switch between the behavior depending on compile time defines.

Fixes #85616

.. case.

This was prompted by dotnet#85616
where running `Invariant.Tests` breaks with:

```
Running /root/helix/work/correlation/wasmtime/wasmtime --dir=. --env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true dotnet.wasm WasmTestRunner managed/Invariant.Tests.dll -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing

Unhandled Exception:
System.ArgumentException: Invalid argument 'managed/Invariant.Tests.dll'.
   at SimpleWasmTestRunner.Main(String[] args)
   at SimpleWasmTestRunner.<Main>(String[] args)
```

- This broke because of a recent change due to which setting
  `InvariantGlobalization=true` meant `WasmBuildNative=true`
- But this did not trigger single file bundle
- And the build ended up relinking a dotnet.wasm but using the
  single-file bundle `main` function.

Instead, we combine the two main functions and switch between the
behavior depending on compile time defines.

Fixes dotnet#85616
@radical radical added arch-wasm WebAssembly architecture area-VM-meta-mono labels May 1, 2023
@radical
radical requested review from lewing, maraf and pavelsavara May 1, 2023 22:46
@radical
radical requested a review from marek-safar as a code owner May 1, 2023 22:46
@ghost ghost assigned radical May 1, 2023
@ghost

ghost commented May 1, 2023

Copy link
Copy Markdown

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

Issue Details

.. case.

This was prompted by #85616 where running Invariant.Tests breaks with:

Running /root/helix/work/correlation/wasmtime/wasmtime --dir=. --env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true dotnet.wasm WasmTestRunner managed/Invariant.Tests.dll -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing

Unhandled Exception:
System.ArgumentException: Invalid argument 'managed/Invariant.Tests.dll'.
   at SimpleWasmTestRunner.Main(String[] args)
   at SimpleWasmTestRunner.<Main>(String[] args)
  • This broke because of a recent change due to which setting InvariantGlobalization=true meant WasmBuildNative=true
  • But this did not trigger single file bundle
  • And the build ended up relinking a dotnet.wasm but using the single-file bundle main function.

Instead, we combine the two main functions and switch between the behavior depending on compile time defines.

Fixes #85616

Author: radical
Assignees: -
Labels:

arch-wasm, area-VM-meta-mono

Milestone: -

/*
* For default case which uses dotnet.wasm, running with wasmtime:
*
* $ wasmtime run --dir . dotnet.wasm MainAssembly [args]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we have a unified way to run the application? For example, could we rename the dotnet.wasm to MainAssembly.wasm even for non-single file bundle?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that for non-single application, the interesting feature is that dotnet.wasm is always the same content. Full set of features, with which you could run any managed assembly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does renaming it harm the premise you mentioned? Do we plan to distribute it separately? Isn't it confusing to run the app differently based on build time bundling?

@pavelsavara pavelsavara May 2, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

dotnet host should be able to run any assembly on wasi

mono_wasm_load_runtime("", 0);

int arg_ofs = 0;
#ifdef WASM_SINGLE_FILE

@pavelsavara pavelsavara May 2, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is the same problem we have with shell on emscripten.
I would prefer to separate the "runtime options" from "application arguments" by --.
In this case there are no "runtime options" because we know which assembly to load.

it would be wasmtime run --dir . -- --run MainAssembly.wasm -- [application args]

In the single file the syntax would be
it would be wasmtime run --dir . -- -- [application args]

Note, that wasmtime also has -- it's own, to solve the same problem.

This would allow us in the future to add other runtime options, without counting positions of the arguments.
For example single-file
wasmtime run --dir . -- --soft-breakpoints -- [args]

where --soft-breakpoints is example of Mono option

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Cleanly delineating arguments sounds like a good idea. I can explore that in a follow up PR. This PR fixes a regression and gets it passing on CI.

@lewing
lewing merged commit c240ade into dotnet:main May 2, 2023
@radical
radical deleted the wasi-invariant-tests branch May 2, 2023 19:09
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-VM-meta-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasi] Invariant.Tests failing to run - regression

4 participants