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

Add support for rebuilding the wasm executable in non-aot mode. #45072

Merged
merged 4 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add support for rebuilding the wasm executable in non-AOT mode.
* Run the pinvoke generator as well.
* Strip the final executable.
* Document some of the public msbuild properties.
  • Loading branch information
vargaz committed Dec 18, 2020
commit f5df0cd8b39aad286687d1fcd6cd4eb7a5655eed
2 changes: 1 addition & 1 deletion src/mono/netcore/sample/wasm/console/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CONFIG?=Release
all: build

build:
EMSDK_PATH=$(realpath $(TOP)/src/mono/wasm/emsdk) $(DOTNET) publish $(DOTNET_Q_ARGS) $(DOTNET_RUN_AOT_COMPILATION_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) $(MSBUILD_ARGS) WasmSample.csproj
EMSDK_PATH=$(realpath $(TOP)/src/mono/wasm/emsdk) $(DOTNET) publish $(DOTNET_Q_ARGS) $(DOTNET_RUN_AOT_COMPILATION_ARGS) $(DOTNET_EXTRA_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) $(MSBUILD_ARGS) WasmSample.csproj

clean:
rm -rf bin
Expand Down
4 changes: 2 additions & 2 deletions src/mono/netcore/sample/wasm/console/WasmSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<Target Name="PrepareForWasmBuild" BeforeTargets="WasmBuildApp">
<PropertyGroup>
<WasmAppDir>$(AppBundleDir)</WasmAppDir>
<WasmAOTDir>$(MSBuildProjectDirectory)\$(PublishDir)\</WasmAOTDir>
<WasmBuildDir>$(MSBuildProjectDirectory)\$(PublishDir)\</WasmBuildDir>
<WasmMainJSPath>$(MonoProjectRoot)\wasm\runtime-test.js</WasmMainJSPath>
<WasmMainAssemblyPath>$(WasmAotDir)WasmSample.dll</WasmMainAssemblyPath>
<WasmMainAssemblyPath>$(WasmBuildDir)WasmSample.dll</WasmMainAssemblyPath>
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
</PropertyGroup>
<ItemGroup>
Expand Down
63 changes: 47 additions & 16 deletions src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
<UsingTask TaskName="WasmAppBuilder" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="WasmAOT" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="WasmLoadAssembliesAndReferences" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="PInvokeTableGenerator" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />

<!--
Public properties:
- WasmBuildDir - Directory where build artifacts are stored.
- WasmBuildNative - Whenever to build the native executable. Defaults to false.
- WasmNativeStrip - Whenever to strip the native executable. Defaults to true.
-->

<PropertyGroup>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
<WasmBuildNative Condition="'$(RunAOTCompilation)' == ''">true</WasmBuildNative>
<WasmNativeStrip>true</WasmNativeStrip>
</PropertyGroup>

<PropertyGroup>
<WasmBuildAppDependsOn>_BeforeWasmBuildApp;_WasmResolveReferences;_WasmAOT</WasmBuildAppDependsOn>
<WasmBuildAppDependsOn>_BeforeWasmBuildApp;_WasmResolveReferences;_WasmBuildNative</WasmBuildAppDependsOn>
</PropertyGroup>

<Target Name="WasmBuildApp" AfterTargets="Publish" />

<Target Condition="'$(RunAOTCompilation)' == 'true'" Name="_WasmAotCompileApp">
<PropertyGroup>
<EmccFlagsFile>$(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-flags.txt</EmccFlagsFile>
<RuntimeEmccVersionFile>$(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-version.txt</RuntimeEmccVersionFile>
<EmccPublishVersionFile>$(WasmAOTDir)emcc-version.txt</EmccPublishVersionFile>
</PropertyGroup>
<Target Name="_WasmAotCompileApp" Condition="'$(RunAOTCompilation)' == 'true'">
<ItemGroup>
<MonoAOTCompilerDefaultAotArguments Include="no-opt" />
<MonoAOTCompilerDefaultAotArguments Include="static" />
Expand All @@ -37,7 +46,7 @@
OutputType="AsmOnly"
Assemblies="@(AotInputAssemblies)"
UseAotDataFile="false"
AotModulesTablePath="$(WasmAOTDir)driver-gen.c"
AotModulesTablePath="$(WasmBuildDir)driver-gen.c"
UseLLVM="true"
DisableParallelAot="true"
LLVMPath="$(EMSDK_PATH)\upstream\bin">
Expand All @@ -63,10 +72,9 @@
<Target Name="_BeforeWasmBuildApp">
<Error Condition="'$(WasmMainAssemblyPath)' == ''" Text="%24(WasmMainAssemblyPath) property needs to be set" />
<Error Condition="'$(WasmAppDir)' == ''" Text="%24(WasmAppDir) property needs to be set" />
<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(WasmAOTDir)' == ''" Text="%24(WasmAOTDir) property needs to be set" />
<Error Condition="'$(WasmBuildNative)' == 'true' and '$(WasmBuildDir)' == ''" Text="%24(WasmBuildDir) property needs to be set" />
<Error Condition="!Exists('$(MicrosoftNetCoreAppRuntimePackRidDir)')" Text="MicrosoftNetCoreAppRuntimePackRidDir=$(MicrosoftNetCoreAppRuntimePackRidDir) doesn't exist" />
<Error Condition="'$(WasmMainJSPath)' == ''" Text="%24(WasmMainJSPath) property needs to be set" />

<ItemGroup>
<_WasmAssemblies Include="$(WasmMainAssemblyPath);@(WasmAssembliesToBundle)" />
</ItemGroup>
Expand Down Expand Up @@ -100,29 +108,52 @@
<Exec Condition="'$(RunAOTCompilation)' == 'true'" Command="mono-cil-strip %(_managedAppAssemblies.Identity)" />
</Target>

<Target Name="_WasmAOT" DependsOnTargets="_WasmAotCompileApp" Condition="'$(RunAOTCompilation)' == 'true'">
<Target Name="_WasmBuildNative" DependsOnTargets="_WasmAotCompileApp" Condition="'$(WasmBuildNative)' == 'true'">
<PropertyGroup>
<EmccFlagsFile>$(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-flags.txt</EmccFlagsFile>
<RuntimeEmccVersionFile>$(MicrosoftNetCoreAppRuntimePackRidDir)native\src\emcc-version.txt</RuntimeEmccVersionFile>
<EmccPublishVersionFile>$(WasmBuildDir)emcc-version.txt</EmccPublishVersionFile>
</PropertyGroup>
<ReadLinesFromFile File="$(EmccFlagsFile)">
<Output TaskParameter="Lines" PropertyName="EmccFlags" />
</ReadLinesFromFile>

<PropertyGroup>
<EmccFlags>$(EmccFlags) -s DISABLE_EXCEPTION_CATCHING=0</EmccFlags>
<EmccFlags Condition="'$(RunAOTCompilation)'">$(EmccFlags) -DENABLE_AOT=1 -DDRIVER_GEN=1</EmccFlags>
vargaz marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ReadLinesFromFile File="$(RuntimeEmccVersionFile)">
<Output TaskParameter="Lines" PropertyName="RuntimeEmccVersion" />
</ReadLinesFromFile>

<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc --version | head -1 > emcc-version.txt" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmAOTDir)" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc --version | head -1 > emcc-version.txt" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" />
<ReadLinesFromFile File="$(EmccPublishVersionFile)">
<Output TaskParameter="Lines" PropertyName="EmccVersion" />
</ReadLinesFromFile>
<Error Condition="'$(RuntimeEmccVersion)' != '$(EmccVersion)'" Text="Emscripten version mismatch, expected '$(RuntimeEmccVersion)', got '$(EmccVersion)'"/>

<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -DCORE_BINDINGS -DENABLE_AOT=1 -DDRIVER_GEN=1 -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/mono-2.0 -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/wasm -I$(WasmAOTDir) $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/driver.c -c -o driver.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmAOTDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/mono-2.0 $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/corebindings.c -c -o corebindings.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmAOTDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -DGEN_PINVOKE=1 -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/wasm $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/pinvoke.c -c -o pinvoke.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmAOTDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -s TOTAL_MEMORY=536870912 --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/library_mono.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/binding_support.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/dotnet_support.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/pal_random.js driver.o pinvoke.o corebindings.o @(_WasmAssemblies->'%(LlvmBitcodeFile)', ' ') libmono-ee-interp.a libmonosgen-2.0.a libmono-ilgen.a libmono-icall-table.a libSystem.Native.a libSystem.IO.Compression.Native.a libicuuc.a libicui18n.a -o dotnet.js" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmAOTDir)" StandardOutputImportance="Low" />
<!-- Either created by MonoAOTCompiler or here -->
<WriteLinesToFile File="$(WasmBuildDir)driver-gen.c" Overwrite="true" Condition="'$(RunAOTCompilation)' == 'false'"
Lines=""
/>

<ItemGroup>
<_WasmPInvokeModules Include="libSystem.Native" />
<_WasmPInvokeModules Include="libSystem.IO.Compression.Native" />
<_WasmPInvokeModules Include="libSystem.Globalization.Native" />
<_WasmPInvokeAssemblies Include="$(WasmBuildDir)\*.dll" />
</ItemGroup>
<PInvokeTableGenerator
Modules="@(_WasmPInvokeModules)"
Assemblies="@(_WasmPInvokeAssemblies)"
OutputPath="$(WasmBuildDir)pinvoke-table.h" />

<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -DCORE_BINDINGS -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/mono-2.0 -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/wasm -I$(WasmBuildDir) $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/driver.c -c -o driver.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/mono-2.0 $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/corebindings.c -c -o corebindings.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -DGEN_PINVOKE=1 -I$(WasmBuildDir) -I$(MicrosoftNetCoreAppRuntimePackRidDir)native/include/wasm $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/pinvoke.c -c -o pinvoke.o" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" StandardOutputImportance="Low" />
<Exec Command="source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcc $(EmccFlags) -s TOTAL_MEMORY=536870912 --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/library_mono.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/binding_support.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/dotnet_support.js --js-library $(MicrosoftNetCoreAppRuntimePackRidDir)native/src/pal_random.js driver.o pinvoke.o corebindings.o @(_WasmAssemblies->'%(LlvmBitcodeFile)', ' ') libmono-ee-interp.a libmonosgen-2.0.a libmono-ilgen.a libmono-icall-table.a libSystem.Native.a libSystem.IO.Compression.Native.a libicuuc.a libicui18n.a -o dotnet.js" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" StandardOutputImportance="Low" />
<Exec Condition="'$(WasmNativeStrip)' == 'true'" Command="$(EMSDK_PATH)/upstream/bin/wasm-opt --strip-dwarf dotnet.wasm -o dotnet.wasm" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(WasmBuildDir)" />
</Target>

<Target Name="_GenerateRunV8Script">
Expand Down