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] Enable wasm relinking by default for Release config #49251

Merged
merged 5 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/pipelines/runtime-linker-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ jobs:
nameSuffix: Runtime_Release
buildArgs: -s mono+libs -c $(_BuildConfig)
extraStepsTemplate: /eng/pipelines/libraries/execute-trimming-tests-steps.yml
dependsOn:
- mono_browser_offsets
monoCrossAOTTargetOS:
- Browser
34 changes: 30 additions & 4 deletions src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,13 @@
</ItemGroup>
</Target>

<Target Name="_BeforeWasmBuildApp">
<Target Name="_BeforeWasmBuildApp" DependsOnTargets="_SetWasmBuildNativeDefaults">
<Error Condition="'$(IntermediateOutputPath)' == ''" Text="%24(IntermediateOutputPath) property needs to be set" />
<Error Condition="!Exists('$(MicrosoftNetCoreAppRuntimePackRidDir)')" Text="MicrosoftNetCoreAppRuntimePackRidDir=$(MicrosoftNetCoreAppRuntimePackRidDir) doesn't exist" />
<Error Condition="@(WasmAssembliesToBundle->Count()) == 0" Text="WasmAssembliesToBundle item is empty. No assemblies to process" />

<PropertyGroup>
<WasmGenerateAppBundle Condition="'$(WasmGenerateAppBundle)' == ''">true</WasmGenerateAppBundle>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true'">true</WasmBuildNative>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmAppDir Condition="'$(WasmAppDir)' == ''">$(OutputPath)AppBundle\</WasmAppDir>
<WasmMainAssemblyFileName Condition="'$(WasmMainAssemblyFileName)' == ''">$(TargetFileName)</WasmMainAssemblyFileName>
Expand All @@ -224,6 +222,34 @@
</ItemGroup>
</Target>

<Target Name="_SetWasmBuildNativeDefaults">
<PropertyGroup>
<_IsEMSDKMissing Condition="'$(EMSDK_PATH)' == '' or !Exists('$(EMSDK_PATH)')">true</_IsEMSDKMissing>
</PropertyGroup>

<!-- if already set, maybe by a user projects, then a missing emsdk is an error -->
<Error Condition="'$(WasmBuildNative)' == 'true' and '$(_IsEMSDKMissing)' == 'true'"
Text="Cannot find emscripten sdk, required for building native files. %24(EMSDK_PATH)=$(EMSDK_PATH)" />

<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(_IsEMSDKMissing)' == 'true'"
Text="Cannot find emscripten sdk, required for AOT'ing assemblies. %24(EMSDK_PATH)=$(EMSDK_PATH)" />

<PropertyGroup>
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(PublishTrimmed)' != 'true'">false</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(Configuration)' == 'Release'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
</PropertyGroup>

<!-- If we want to default to true, and sdk is missing, then just warn, and set it to false -->
<Warning Condition="'$(WasmBuildNative)' == 'true' and '$(_IsEMSDKMissing)' == 'true'"
Text="Cannot find emscripten sdk, required for building native files. %24(EMSDK_PATH)=$(EMSDK_PATH). Skipping native relinking" />

<PropertyGroup>
<WasmBuildNative Condition="'$(WasmBuildNative)' == 'true' and '$(_IsEMSDKMissing)' == 'true'">false</WasmBuildNative>
</PropertyGroup>
</Target>

<Target Name="_WasmCoreBuild" BeforeTargets="WasmBuildApp" DependsOnTargets="$(WasmBuildAppDependsOn)" />

<Target Name="_WasmGenerateAppBundle" Condition="'$(WasmGenerateAppBundle)' == 'true'">
Expand Down Expand Up @@ -278,8 +304,8 @@
</ReadLinesFromFile>

<PropertyGroup>
<EmccFlags>$(_DefaultEmccFlags) $(EmccFlags)</EmccFlags>
<EmccFlags Condition="'$(_WasmDevel)' == 'true'">-O0 $(EmccFlags)</EmccFlags>
<EmccFlags>$(EmccFlags) $(_DefaultEmccFlags) $(EmccFlags)</EmccFlags>
<EmccFlags>$(EmccFlags) -s DISABLE_EXCEPTION_CATCHING=0</EmccFlags>
<EmccFlags Condition="'$(RunAOTCompilation)' == 'true'">$(EmccFlags) -DENABLE_AOT=1 -DDRIVER_GEN=1</EmccFlags>
<EmccFlags Condition="'$(InvariantGlobalization)' == 'true'">$(EmccFlags) -DINVARIANT_GLOBALIZATION=1</EmccFlags>
Expand Down
7 changes: 4 additions & 3 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/WasmBuildAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public static int Main()

string projectName = $"invariant_{invariantGlobalization?.ToString() ?? "unset"}";
BuildProject(projectName, config, aot: aot, extraProperties: extraProperties,
hasIcudt: invariantGlobalization == null || invariantGlobalization.Value == false);
hasIcudt: invariantGlobalization == null || invariantGlobalization.Value == false,
dotnetWasmFromRuntimePack: !(aot || config == "Release"));

RunAndTestWasmApp(projectName, config, isAOT: aot, expectedExitCode: 42,
test: output => Assert.Contains("Hello, World!", output));
Expand Down Expand Up @@ -265,7 +266,7 @@ public void TopLevelWithArgs(string config, bool aot, string[] args)
void TestMain(string projectName, string programText, string config, bool aot)
{
File.WriteAllText(Path.Combine(_tempDir, "Program.cs"), programText);
BuildProject(projectName, config, aot: aot);
BuildProject(projectName, config, aot: aot, dotnetWasmFromRuntimePack: !(aot || config == "Release"));
RunAndTestWasmApp(projectName, config, isAOT: aot, expectedExitCode: 42,
test: output => Assert.Contains("Hello, World!", output));
}
Expand All @@ -281,7 +282,7 @@ void TestMainWithArgs(string projectName, string programFormatString, string con
string programText = programFormatString.Replace("##CODE##", code);

File.WriteAllText(Path.Combine(_tempDir, "Program.cs"), programText);
BuildProject(projectName, config, aot: aot);
BuildProject(projectName, config, aot: aot, dotnetWasmFromRuntimePack: !(aot || config == "Release"));
RunAndTestWasmApp(projectName, config, isAOT: aot, expectedExitCode: 42 + args.Length, args: string.Join(' ', args),
test: output =>
{
Expand Down