未验证 提交 b7c8919f 编写于 作者: A Ankit Jain 提交者: GitHub

[wasm] Misc fixes for template projects (#71468)

* [wasm] Add runArgs.json for console projects

* [wasm] Fix `dotnet.js.symbols` being copied to the bundle

.. and enable it by default for the template projects.
上级 921029ba
......@@ -155,8 +155,6 @@
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>
<!-- Temporarily `false`, till sdk gets a fix for supporting the new file -->
<WasmEmitSymbolMap Condition="'$(WasmEmitSymbolMap)' == ''">false</WasmEmitSymbolMap>
<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
<_WasmRuntimeICallTablePath>$(_WasmIntermediateOutputPath)runtime-icall-table.h</_WasmRuntimeICallTablePath>
......
......@@ -107,6 +107,9 @@
<WasmGenerateAppBundle Condition="'$(WasmGenerateAppBundle)' == ''">false</WasmGenerateAppBundle>
<UseAppHost>false</UseAppHost>
<!-- Temporarily `false`, till sdk gets a fix for supporting the new file -->
<WasmEmitSymbolMap Condition="'$(WasmEmitSymbolMap)' == '' and '$(RunAOTCompilation)' != 'true'">false</WasmEmitSymbolMap>
<!-- if DebuggerSupport==true, then ensure that WasmDebugLevel isn't disabling debugging -->
<WasmDebugLevel Condition="('$(WasmDebugLevel)' == '' or '$(WasmDebugLevel)' == '0') and ('$(DebuggerSupport)' == 'true' or '$(Configuration)' == 'Debug')">-1</WasmDebugLevel>
......@@ -294,7 +297,9 @@
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.worker.js" Condition="'$(_HasDotnetJsWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.worker.js')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet-crypto-worker.js" Condition="'$(_HasDotnetJsCryptoWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet-crypto-worker.js')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js.symbols"
Condition="'$(WasmEmitSymbolMap)' == 'true' and '$(_HasDotnetJs)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js.symbols')" />
Condition="'$(WasmEmitSymbolMap)' == 'true' and
'$(_HasDotnetJsSymbols)' != 'true' and
Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js.symbols')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(WasmIcuDataFileName)" Condition="'$(InvariantGlobalization)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.timezones.blat" />
......
......@@ -59,6 +59,10 @@ private async Task<int> RunAsync()
if (_args.CommonConfig.Debugging)
throw new CommandLineException($"Debugging not supported with {_args.Host}");
var runArgsJson = new RunArgumentsJson(applicationArguments: Array.Empty<string>(),
runtimeArguments: _args.CommonConfig.RuntimeArguments);
runArgsJson.Save(Path.Combine(_args.CommonConfig.AppPath, "runArgs.json"));
var args = new List<string>();
if (_args.Host == WasmHost.V8)
......@@ -75,8 +79,6 @@ private async Task<int> RunAsync()
// v8/jsc want arguments to the script separated by "--", others don't
args.Add("--");
}
foreach (var rarg in _args.CommonConfig.RuntimeArguments)
args.Add($"--runtime-arg={rarg}");
args.AddRange(_args.AppArgs);
......
......@@ -8,6 +8,7 @@
<WasmMainJSPath>main.js</WasmMainJSPath>
<OutputType>Exe</OutputType>
<PublishTrimmed>true</PublishTrimmed>
<WasmEmitSymbolMap Condition="'$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
</PropertyGroup>
<ItemGroup>
......
......@@ -71,12 +71,13 @@ let is_debugging = false;
function initRunArgs() {
// set defaults
runArgs.applicationArguments = runArgs.applicationArguments === undefined ? [] : runArgs.applicationArguments;
runArgs.applicationArguments = []; // not set in runArgs.json for non-browser cases
runArgs.workingDirectory = runArgs.workingDirectory === undefined ? '/' : runArgs.workingDirectory;
runArgs.environmentVariables = runArgs.environmentVariables === undefined ? {} : runArgs.environmentVariables;
runArgs.runtimeArgs = runArgs.runtimeArgs === undefined ? [] : runArgs.runtimeArgs;
runArgs.diagnosticTracing = runArgs.diagnosticTracing === undefined ? false : runArgs.diagnosticTracing;
runArgs.debugging = runArgs.debugging === undefined ? false : runArgs.debugging;
runArgs.forwardConsole = false; // not relevant for non-browser
}
function mergeArguments() {
......
......@@ -8,6 +8,7 @@
<WasmMainJSPath>main.mjs</WasmMainJSPath>
<OutputType>Exe</OutputType>
<PublishTrimmed>true</PublishTrimmed>
<WasmEmitSymbolMap Condition="'$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
</PropertyGroup>
<ItemGroup>
......
......@@ -575,6 +575,11 @@ protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack)
same: fromRuntimePack);
}
protected static void AssertDotNetJsSymbols(string bundleDir, bool fromRuntimePack)
=> AssertFile(Path.Combine(s_buildEnv.RuntimeNativeDir, "dotnet.js.symbols"),
Path.Combine(bundleDir, "dotnet.js.symbols"),
same: fromRuntimePack);
protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null)
=> AssertFilesExist(dir, filenames, label, expectToExist: false);
......
......@@ -6,7 +6,6 @@
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using System.Threading.Tasks;
#nullable enable
......@@ -42,6 +41,8 @@ public void BrowserBuildThenPublish(string config)
TargetFramework: "net7.0"
));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true);
if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product))
throw new XunitException($"Test bug: could not get the build product in the cache");
......@@ -61,6 +62,8 @@ public void BrowserBuildThenPublish(string config)
Publish: true,
TargetFramework: "net7.0",
UseCache: false));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !expectRelinking);
}
[Theory]
......@@ -86,6 +89,8 @@ public void ConsoleBuildThenPublish(string config)
TargetFramework: "net7.0"
));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true);
(int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config}", workingDir: _projectDir);
Assert.Equal(0, exitCode);
Assert.Contains("Hello, Console!", output);
......@@ -108,6 +113,8 @@ public void ConsoleBuildThenPublish(string config)
Publish: true,
TargetFramework: "net7.0",
UseCache: false));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !expectRelinking);
}
[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
......@@ -141,6 +148,8 @@ public void ConsoleBuildAndRun(string config)
TargetFramework: "net7.0"
));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true);
(int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config} x y z", workingDir: _projectDir);
Assert.Equal(0, exitCode);
Assert.Contains("args[0] = x", output);
......@@ -184,6 +193,8 @@ public void ConsolePublishAndRun(string config, bool aot)
TargetFramework: "net7.0",
UseCache: false));
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !expectRelinking);
// FIXME: pass envvars via the environment, once that is supported
string runArgs = $"run --no-build -c {config}";
if (aot)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册