Skip to content

Commit e0355b9

Browse files
authored
[wasi] Initial wasi/aot build support (#95051)
* EmccCompile: Add CompilerBinaryPath input property * [wasi] Add default rsp files to the runtime pack * [wasi] Add build support for AOT * [wasi] Add simple aot build tests * [wasi] update build-tasks target * cleanup * Import monoaotcompiler pack for wasi * fix windows build * [wasi] Enable WasmDedup by default, same as wasm * [wasi] WBT: run aot tests without _wasmDevel, to avoid running out of memory when compiling with -O0 * [wasi] Fix wasi-link.rsp path on windows
1 parent 91e3b3e commit e0355b9

11 files changed

Lines changed: 176 additions & 179 deletions

File tree

eng/liveBuilds.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
IsNative="true" />
245245

246246
<LibrariesRuntimeFiles Include="
247+
$(LibrariesNativeArtifactsPath)src\wasi-default.rsp;
248+
$(LibrariesNativeArtifactsPath)src\wasi-link.rsp;
247249
$(LibrariesNativeArtifactsPath)src\*.c"
248250
NativeSubDirectory="src"
249251
IsNative="true" />

src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@
229229
<PlatformManifestFileEntry Include="emcc-default.rsp" IsNative="true" />
230230
<PlatformManifestFileEntry Include="emcc-link.rsp" IsNative="true" />
231231
<PlatformManifestFileEntry Include="emcc-props.json" IsNative="true" />
232+
<PlatformManifestFileEntry Include="wasi-default.rsp" IsNative="true" />
233+
<PlatformManifestFileEntry Include="wasi-link.rsp" IsNative="true" />
232234
<PlatformManifestFileEntry Include="ILLink.Substitutions.WasmIntrinsics.xml" IsNative="true" />
233235
<PlatformManifestFileEntry Include="ILLink.Substitutions.NoWasmIntrinsics.xml" IsNative="true" />
234236
<PlatformManifestFileEntry Include="ILLink.Substitutions.LegacyJsInterop.xml" IsNative="true" />

src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/WorkloadManifest.targets.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
<!-- TFM specific -->
9797

98-
<Import Condition="'$(TargetsCurrent)' == 'true' and '$(RunAOTCompilation)' == 'true' and ('$(UsingBrowserRuntimeWorkload)' == 'true' or '$(UsingMobileWorkload)' == 'true')" Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" />
98+
<Import Condition="'$(TargetsCurrent)' == 'true' and '$(RunAOTCompilation)' == 'true' and ('$(UsingBrowserRuntimeWorkload)' == 'true' or '$(UsingMobileWorkload)' == 'true' or '$(UsingWasiRuntimeWorkload)' == 'true')" Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" />
9999

100100
<ImportGroup Condition="'$(TargetsCurrent)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(_IsAndroidLibraryMode)' == 'true')">
101101
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />

src/mono/wasi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ app-builder:
5252
$(DOTNET) build $(TOP)/src/tasks/WasmAppBuilder
5353

5454
build-tasks:
55-
$(DOTNET) build $(TOP)/src/tasks/WasmBuildTasks $(MSBUILD_ARGS)
55+
$(DOTNET) build $(TOP)/src/tasks/tasks.proj /p:Configuration=$(CONFIG) $(MSBUILD_ARGS)
5656

5757
clean:
5858
$(RM) -rf $(BUILDS_OBJ_DIR)

src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ public WasiTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
2121
}
2222

2323
[Theory]
24-
[InlineData("Debug")]
25-
[InlineData("Release")]
26-
public void ConsoleBuildThenPublish(string config)
24+
[InlineData("Debug", /*aot*/ false)]
25+
[InlineData("Debug", /*aot*/ true)]
26+
[InlineData("Release", /*aot*/ false)]
27+
[InlineData("Release", /*aot*/ true)]
28+
public void ConsoleBuildThenPublish(string config, bool aot)
2729
{
2830
string id = $"{config}_{GetRandomId()}";
2931
string projectFile = CreateWasmTemplateProject(id, "wasiconsole");
3032
string projectName = Path.GetFileNameWithoutExtension(projectFile);
3133
File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_simpleMainWithArgs);
3234

33-
var buildArgs = new BuildArgs(projectName, config, false, id, null);
35+
var buildArgs = new BuildArgs(projectName, config, true, id, null);
3436
buildArgs = ExpandBuildArgs(buildArgs);
3537

38+
if (aot)
39+
{
40+
AddItemsPropertiesToProject(projectFile, "<RunAOTCompilation>true</RunAOTCompilation><_WasmDevel>false</_WasmDevel>");
41+
}
42+
3643
BuildProject(buildArgs,
3744
id: id,
3845
new BuildProjectOptions(

src/mono/wasi/build/WasiApp.Native.targets

Lines changed: 153 additions & 167 deletions
Large diffs are not rendered by default.

src/mono/wasi/build/WasiApp.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
-->
7878

7979
<PropertyGroup>
80-
<WasmDedup Condition="'$(WasmDedup)' == ''">false</WasmDedup>
80+
<WasmDedup Condition="'$(WasmDedup)' == ''">true</WasmDedup>
8181
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">false</WasmEnableExceptionHandling>
8282
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">false</WasmEnableSIMD>
8383

src/mono/wasi/build/WasiSdk.Defaults.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<WasiSysRoot>$([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'share', 'wasi-sysroot'))</WasiSysRoot>
55
<WasiClang>$(WasiSdkRoot)\bin\clang</WasiClang>
66
<WasiClang Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WasiClang).exe</WasiClang>
7+
8+
<WasiSdkBinPath>$([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'bin'))</WasiSdkBinPath>
79
</PropertyGroup>
810
</Project>

src/mono/wasi/wasi.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
<ItemGroup>
265265
<IcuDataFiles Include="$(NativeBinDir)*.dat" />
266266
<WasmSrcFiles Include="$(NativeBinDir)src\*.c;" />
267+
<WasmSrcFiles Include="$(_WasiDefaultsRspPath);$(_WasiCompileRspPath);$(_WasiLinkRspPath)" />
267268
<WasmHeaderFiles Include="$(NativeBinDir)include\wasm\*.h" />
268269
</ItemGroup>
269270

src/mono/wasm/build/WasmApp.Native.targets

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
_WasmAotCompileApp;
1212
_WasmStripAOTAssemblies;
1313
_PrepareForWasmBuildNative;
14-
_GenerateDriverGenC;
1514
_GenerateManagedToNative;
1615
_WasmCompileNativeFiles;
1716
_WasmLinkDotNet;
@@ -549,9 +548,6 @@
549548
</ItemGroup>
550549
</Target>
551550

552-
<Target Name="_GenerateDriverGenC" Condition="'$(_WasmShouldAOT)' != 'true'">
553-
</Target>
554-
555551
<Target Name="_ReadEmccProps" Condition="'$(_IsEMSDKMissing)' != 'true'">
556552
<ReadEmccProps JsonFilePath="$(_WasmRuntimePackSrcDir)emcc-props.json">
557553
<Output TaskParameter="EmccProperties" ItemName="_EmccPropItems" />

0 commit comments

Comments
 (0)