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

[wasm] Templates don't pass the command line arguments to the app #76201

Open
1 of 3 tasks
radical opened this issue Sep 26, 2022 · 14 comments
Open
1 of 3 tasks

[wasm] Templates don't pass the command line arguments to the app #76201

radical opened this issue Sep 26, 2022 · 14 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono
Milestone

Comments

@radical
Copy link
Member

radical commented Sep 26, 2022

If we print the command line args:

using System;
using System.Runtime.InteropServices.JavaScript;

Console.WriteLine("Hello, Console!");
Console.WriteLine ($"command line args: {string.Join(',', args)}");

return 0;

public partial class MyClass
{
    [JSExport]
    internal static string Greeting()
    {
        var text = $"Hello, World! Greetings from node version: {GetNodeVersion()}";
        return text;
    }

    [JSImport("node.process.version", "main.mjs")]
    internal static partial string GetNodeVersion();
}

.. and run:

$ dotnet run x y z
WasmAppHost --runtime-config /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle/cc.runtimeconfig.json x y z
Running: node main.mjs x y z
Using working directory: /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Hello, World! Greetings from node version: v14.18.2
Hello, Console!
command line args: dotnet,is,great!

The command line arguments x y z were ignored, and instead we got dotnet,is,great. And that's because the main.mjs has:

await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);

This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code

private void UpdateConsoleMainJs()
{
string mainJsPath = Path.Combine(_projectDir!, "main.mjs");
string mainJsContent = File.ReadAllText(mainJsPath);
mainJsContent = mainJsContent
.Replace(".create()", ".withConsoleForwarding().create()")
.Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)");
File.WriteAllText(mainJsPath, mainJsContent);
}

And the same is done for the browser too.

We should instead:

  • Pass the command line args for console, and browser to the app
  • Automatically set console forwarding if runArgs has forward console set
  • The tests should be updated to run the template exactly as it is generated. And a follow up test can patch it to print the arguments, and check that

cc @pavelsavara

@radical radical added arch-wasm WebAssembly architecture area-Build-mono labels Sep 26, 2022
@radical radical added this to the 7.0.0 milestone Sep 26, 2022
@ghost
Copy link

ghost commented Sep 26, 2022

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

Issue Details

If we print the command line args:

using System;
using System.Runtime.InteropServices.JavaScript;

Console.WriteLine("Hello, Console!");
Console.WriteLine ($"command line args: {string.Join(',', args)}");

return 0;

public partial class MyClass
{
    [JSExport]
    internal static string Greeting()
    {
        var text = $"Hello, World! Greetings from node version: {GetNodeVersion()}";
        return text;
    }

    [JSImport("node.process.version", "main.mjs")]
    internal static partial string GetNodeVersion();
}

.. and run:

$ dotnet run x y z
WasmAppHost --runtime-config /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle/cc.runtimeconfig.json x y z
Running: node main.mjs x y z
Using working directory: /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Hello, World! Greetings from node version: v14.18.2
Hello, Console!
command line args: dotnet,is,great!

The command line arguments x y z were ignored, and instead we got dotnet,is,great. And that's because the main.mjs has:

await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);

This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code

private void UpdateConsoleMainJs()
{
string mainJsPath = Path.Combine(_projectDir!, "main.mjs");
string mainJsContent = File.ReadAllText(mainJsPath);
mainJsContent = mainJsContent
.Replace(".create()", ".withConsoleForwarding().create()")
.Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)");
File.WriteAllText(mainJsPath, mainJsContent);
}

And the same is done for the browser too.

We should instead:

  • Pass the command line args for console, and browser to the app
  • Automatically set console forwarding if runArgs has forward console set
  • The tests should be updated to run the template exactly as it is generated. And a follow up test can patch it to print the arguments, and check that

cc @pavelsavara

Author: radical
Assignees: -
Labels:

arch-wasm, area-Build-mono

Milestone: 7.0.0

@pavelsavara
Copy link
Member

we could have simpler await dotnet.run() instead of await runMainAndExit

@maraf
Copy link
Member

maraf commented Sep 27, 2022

we could have simpler await dotnet.run() instead of await runMainAndExit

Why do we have dotnet.run what implicitly reads main assembly and arguments, but runMainAndExit requires to pass them explicitly?

Using dotnet.run() after const runtime = dotnet.create() seems like "a break in code flow".

@pavelsavara
Copy link
Member

Why do we have dotnet.run what implicitly reads main assembly and arguments, but runMainAndExit requires to pass them explicitly?

Because it's a lower level API which is not part of the builder pattern.

Using dotnet.run() after const runtime = dotnet.create() seems like "a break in code flow".

That's OK :)

radical added a commit that referenced this issue Sep 29, 2022
radical added a commit that referenced this issue Sep 29, 2022
radical added a commit to radical/runtime that referenced this issue Sep 29, 2022
@pavelsavara
Copy link
Member

I believe this was fixed by #76182 and #76373
Is that right @radical @maraf ?

@maraf
Copy link
Member

maraf commented Sep 30, 2022

Partially. It passes command line args for the console template.

@pavelsavara pavelsavara modified the milestones: 7.0.0, 8.0.0 Sep 30, 2022
@pavelsavara pavelsavara removed their assignment Sep 30, 2022
@pavelsavara pavelsavara changed the title [release/7.0][wasm] Templates don't pass the command line arguments to the app [wasm] Templates don't pass the command line arguments to the app Sep 30, 2022
@pavelsavara
Copy link
Member

I updated it for Net8 then

lewing pushed a commit that referenced this issue Oct 3, 2022
* Update dependencies from https://github.com/dotnet/arcade build 20220920.1

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22470.1

* Update dependencies from https://github.com/dotnet/arcade build 20220920.3

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22470.3

* Update dependencies from https://github.com/dotnet/arcade build 20220921.2

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22471.2

* Update dependencies from https://github.com/dotnet/arcade build 20220922.1

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22472.1

* Update dependencies from https://github.com/dotnet/arcade build 20220923.1

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22473.1

* Update dependencies from https://github.com/dotnet/arcade build 20220926.4

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22476.4

* Update dependencies from https://github.com/dotnet/arcade build 20220927.1

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22477.1

* InstallWorkloadFromArtifacts: Remove hack because we have an updated sdk now

* [wasm] WBT: Make project names unique

* [wasm] WBT: Use a clean NUGET_PACKAGES dir separate from the project directory

* [wasm] WBT: Fixes to work with latest sdk

- Use only one source of which tfm to use
- Allow a different tfm for blazor
- Add `dotnet8` nuget feed for tests
- Support more than one choice for nuget.config, like for net7, or net8

* Revert to test projects created in bindir, instead of a temp one

This was necessary because on windows the tmp path is very long, causing
the test project paths to become too long causing build failures.

* [wasm] fix weird build failures

`MSBuildSDKsPath` is set by runtime repo, and that interferes with the
test projects. To avoid this the `MSBuildSDKsPath` was set to `""` in
the test environment. But even that can negatively affect the build
because msbuild treats environment variables as "global properties" that
cannot be changed. This manifests when running:

`$ dotnet run --no-build`

.. it would fail with `/foo/bar.csproj is not a valid project file`.

Instead, explicitly *remove* `MSBuildSDKsPath` from the environment when
invoking the process.

* PInvokeTableGenerator: Find path to WasmAppBuilder.dll at test time

.. instead of depending on *one* runtime pack version. This is needed
when we have more than one workload installed.

* WasmAppHost: allow rollForward to work with newer sdks

* Don't use the nuget packages directory as fallback.

.. because we explicitly set `NUGET_PACKAGES` envvar now.

* [wasm] Use the latest sdk for Wasm.Build.Tests

* Add missing nuget8.config

* WBT: workaround for #76201

* Update dependencies from https://github.com/dotnet/arcade build 20220928.2

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22478.2

* Revert "WBT: workaround for #76201"

This reverts commit 33e3679.

* Revert "Add missing nuget8.config"

This reverts commit dec9861.

* Revert "[wasm] Use the latest sdk for Wasm.Build.Tests"

This reverts commit 3a15bdf.

* Revert "Don't use the nuget packages directory as fallback."

This reverts commit 785504e.

* Revert "WasmAppHost: allow rollForward to work with newer sdks"

This reverts commit 28cfbcd.

* Revert "PInvokeTableGenerator: Find path to WasmAppBuilder.dll at test time"

This reverts commit 33dbf98.

* Revert "[wasm] fix weird build failures"

This reverts commit 1a731fb.

* Revert "Revert to test projects created in bindir, instead of a temp one"

This reverts commit 57ff0dd.

* Revert "[wasm] WBT: Fixes to work with latest sdk"

This reverts commit 0aa1b5a.

* Revert "[wasm] WBT: Use a clean NUGET_PACKAGES dir separate from the project directory"

This reverts commit 0678940.

* Revert "[wasm] WBT: Make project names unique"

This reverts commit 55120ac.

* Revert "InstallWorkloadFromArtifacts: Remove hack because we have an updated sdk now"

This reverts commit 60e9f8c.

* Fix Wasm.Build.Tests failures

- Use latest sdk for testing
- Add dotnet8 feed, needed by blazorwasm templates

- Workaround a bug in 7.0 templates which will be fixed by
#76373 . And this can be removed
once we have packages with that.

* WasmAppHost: Set rollForward=latestMajor to work with newer sdks

* Update dependencies from https://github.com/dotnet/arcade build 20220929.2

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22479.2

* Update dependencies from https://github.com/dotnet/arcade build 20220930.2

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22480.2

* Revert changes to source-build.yml

It was missing dotnet/arcade#10782

* Update dependencies from https://github.com/dotnet/arcade build 20220930.2

Microsoft.DotNet.ApiCompat , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 8.0.0-beta.22469.1 -> To Version 8.0.0-beta.22480.2

* Revert changes again

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Ankit Jain <[email protected]>
Co-authored-by: Alexander Köplinger <[email protected]>
radical added a commit that referenced this issue Oct 3, 2022
* InstallWorkloadFromArtifacts: Remove hack because we have an updated sdk now

* [wasm] WBT: Make project names unique

* [wasm] WBT: Use a clean NUGET_PACKAGES dir separate from the project directory

* [wasm] WBT: Fixes to work with latest sdk

- Use only one source of which tfm to use
- Allow a different tfm for blazor
- Add `dotnet8` nuget feed for tests
- Support more than one choice for nuget.config, like for net7, or net8

* WBT: Revert to test projects created in bindir, instead of a temp one

This was necessary because on windows the tmp path is very long, causing
the test project paths to become too long causing build failures.

* [wasm] fix weird build failures

`MSBuildSDKsPath` is set by runtime repo, and that interferes with the
test projects. To avoid this the `MSBuildSDKsPath` was set to `""` in
the test environment. But even that can negatively affect the build
because msbuild treats environment variables as "global properties" that
cannot be changed. This manifests when running:

`$ dotnet run --no-build`

.. it would fail with `/foo/bar.csproj is not a valid project file`.

Instead, explicitly *remove* `MSBuildSDKsPath` from the environment when
invoking the process.

* WBT: PInvokeTableGenerator: Find path to WasmAppBuilder.dll at test time

.. instead of depending on *one* runtime pack version. This is needed
when we have more than one workload installed.

* WBT: Don't use the nuget packages directory as fallback.

.. because we explicitly set `NUGET_PACKAGES` envvar now.

* [wasm] Use the latest sdk for Wasm.Build.Tests

* WBT: Add missing nuget8.config

* WBT: workaround for #76201

* WasmAppHost: add rollforward=latestMajor
@lewing
Copy link
Member

lewing commented Jul 24, 2023

@radical is this resolved?

@pavelsavara
Copy link
Member

I would like to see it resolved together with #88760

@radical radical modified the milestones: 8.0.0, 9.0.0 Aug 14, 2023
@lewing
Copy link
Member

lewing commented Feb 21, 2024

cc @richlander

@lewing lewing added the area-HostModel Microsoft.NET.HostModel issues label Feb 21, 2024
@ghost
Copy link

ghost commented Feb 21, 2024

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

Issue Details

If we print the command line args:

using System;
using System.Runtime.InteropServices.JavaScript;

Console.WriteLine("Hello, Console!");
Console.WriteLine ($"command line args: {string.Join(',', args)}");

return 0;

public partial class MyClass
{
    [JSExport]
    internal static string Greeting()
    {
        var text = $"Hello, World! Greetings from node version: {GetNodeVersion()}";
        return text;
    }

    [JSImport("node.process.version", "main.mjs")]
    internal static partial string GetNodeVersion();
}

.. and run:

$ dotnet run x y z
WasmAppHost --runtime-config /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle/cc.runtimeconfig.json x y z
Running: node main.mjs x y z
Using working directory: /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Hello, World! Greetings from node version: v14.18.2
Hello, Console!
command line args: dotnet,is,great!

The command line arguments x y z were ignored, and instead we got dotnet,is,great. And that's because the main.mjs has:

await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);

This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code

private void UpdateConsoleMainJs()
{
string mainJsPath = Path.Combine(_projectDir!, "main.mjs");
string mainJsContent = File.ReadAllText(mainJsPath);
mainJsContent = mainJsContent
.Replace(".create()", ".withConsoleForwarding().create()")
.Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)");
File.WriteAllText(mainJsPath, mainJsContent);
}

And the same is done for the browser too.

We should instead:

  • Pass the command line args for console, and browser to the app
  • Automatically set console forwarding if runArgs has forward console set
  • The tests should be updated to run the template exactly as it is generated. And a follow up test can patch it to print the arguments, and check that

cc @pavelsavara

Author: radical
Assignees: -
Labels:

arch-wasm, area-HostModel, area-Build-mono

Milestone: 9.0.0

@lewing lewing removed the area-HostModel Microsoft.NET.HostModel issues label Feb 21, 2024
@lewing
Copy link
Member

lewing commented Feb 21, 2024

What area owns template argument parsing and where should this be redirected?

@maraf
Copy link
Member

maraf commented Feb 21, 2024

I think this is all WasmAppHost related

@maraf maraf self-assigned this Feb 21, 2024
@lewing
Copy link
Member

lewing commented Feb 21, 2024

I think this is all WasmAppHost related

I think the app host doesn't get all the information it needs, but I hope I'm wrong

@maraf maraf modified the milestones: 9.0.0, 10.0.0 Jul 24, 2024
@pavelsavara pavelsavara modified the milestones: 10.0.0, Future Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

No branches or pull requests

4 participants