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

[wasi] Initial wasi/aot build support #95051

Merged
merged 11 commits into from
Nov 22, 2023
2 changes: 2 additions & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@
IsNative="true" />

<LibrariesRuntimeFiles Include="
$(LibrariesNativeArtifactsPath)src\wasi-default.rsp;
$(LibrariesNativeArtifactsPath)src\wasi-link.rsp;
$(LibrariesNativeArtifactsPath)src\*.c"
NativeSubDirectory="src"
IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
<PlatformManifestFileEntry Include="emcc-default.rsp" IsNative="true" />
<PlatformManifestFileEntry Include="emcc-link.rsp" IsNative="true" />
<PlatformManifestFileEntry Include="emcc-props.json" IsNative="true" />
<PlatformManifestFileEntry Include="wasi-default.rsp" IsNative="true" />
<PlatformManifestFileEntry Include="wasi-link.rsp" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.WasmIntrinsics.xml" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.NoWasmIntrinsics.xml" IsNative="true" />
<PlatformManifestFileEntry Include="ILLink.Substitutions.LegacyJsInterop.xml" IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<!-- TFM specific -->

<Import Condition="'$(TargetsCurrent)' == 'true' and '$(RunAOTCompilation)' == 'true' and ('$(UsingBrowserRuntimeWorkload)' == 'true' or '$(UsingMobileWorkload)' == 'true')" Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" />
<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" />

<ImportGroup Condition="'$(TargetsCurrent)' == 'true' and ('$(TargetPlatformIdentifier)' == 'android' or '$(_IsAndroidLibraryMode)' == 'true')">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ app-builder:
$(DOTNET) build $(TOP)/src/tasks/WasmAppBuilder

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

clean:
$(RM) -rf $(BUILDS_OBJ_DIR)
Expand Down
15 changes: 11 additions & 4 deletions src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ public WasiTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void ConsoleBuildThenPublish(string config)
[InlineData("Debug", /*aot*/ false)]
[InlineData("Debug", /*aot*/ true)]
[InlineData("Release", /*aot*/ false)]
[InlineData("Release", /*aot*/ true)]
public void ConsoleBuildThenPublish(string config, bool aot)
{
string id = $"{config}_{GetRandomId()}";
string projectFile = CreateWasmTemplateProject(id, "wasiconsole");
string projectName = Path.GetFileNameWithoutExtension(projectFile);
File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_simpleMainWithArgs);

var buildArgs = new BuildArgs(projectName, config, false, id, null);
var buildArgs = new BuildArgs(projectName, config, true, id, null);
buildArgs = ExpandBuildArgs(buildArgs);

if (aot)
{
AddItemsPropertiesToProject(projectFile, "<RunAOTCompilation>true</RunAOTCompilation><_WasmDevel>false</_WasmDevel>");
}

BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
Expand Down
320 changes: 153 additions & 167 deletions src/mono/wasi/build/WasiApp.Native.targets

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mono/wasi/build/WasiApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
-->

<PropertyGroup>
<WasmDedup Condition="'$(WasmDedup)' == ''">false</WasmDedup>
<WasmDedup Condition="'$(WasmDedup)' == ''">true</WasmDedup>
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">false</WasmEnableExceptionHandling>
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">false</WasmEnableSIMD>

Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasi/build/WasiSdk.Defaults.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<WasiSysRoot>$([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'share', 'wasi-sysroot'))</WasiSysRoot>
<WasiClang>$(WasiSdkRoot)\bin\clang</WasiClang>
<WasiClang Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WasiClang).exe</WasiClang>

<WasiSdkBinPath>$([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'bin'))</WasiSdkBinPath>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/mono/wasi/wasi.proj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<ItemGroup>
<IcuDataFiles Include="$(NativeBinDir)*.dat" />
<WasmSrcFiles Include="$(NativeBinDir)src\*.c;" />
<WasmSrcFiles Include="$(_WasiDefaultsRspPath);$(_WasiCompileRspPath);$(_WasiLinkRspPath)" />
<WasmHeaderFiles Include="$(NativeBinDir)include\wasm\*.h" />
</ItemGroup>

Expand Down
4 changes: 0 additions & 4 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
_WasmAotCompileApp;
_WasmStripAOTAssemblies;
_PrepareForWasmBuildNative;
_GenerateDriverGenC;
_GenerateManagedToNative;
_WasmCompileNativeFiles;
_WasmLinkDotNet;
Expand Down Expand Up @@ -549,9 +548,6 @@
</ItemGroup>
</Target>

<Target Name="_GenerateDriverGenC" Condition="'$(_WasmShouldAOT)' != 'true'">
</Target>

<Target Name="_ReadEmccProps" Condition="'$(_IsEMSDKMissing)' != 'true'">
<ReadEmccProps JsonFilePath="$(_WasmRuntimePackSrcDir)emcc-props.json">
<Output TaskParameter="EmccProperties" ItemName="_EmccPropItems" />
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/WasmAppBuilder/EmccCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class EmccCompile : Microsoft.Build.Utilities.Task
public string? WorkingDirectory { get; set; }
public string OutputMessageImportance{ get; set; } = "Low";
public string? MessageToIndicateCompiling { get; set; }
public string CompilerBinaryPath { get; set; } = "emcc";

[Output]
public ITaskItem[]? OutputFiles { get; private set; }
Expand Down Expand Up @@ -192,7 +193,7 @@ bool ProcessSourceFile(string srcFile, string objFile)
string tmpObjFile = Path.GetTempFileName();
try
{
string command = $"emcc {Arguments} -c -o \"{tmpObjFile}\" \"{srcFile}\"";
string command = $"{CompilerBinaryPath} {Arguments} -c -o \"{tmpObjFile}\" \"{srcFile}\"";
var startTime = DateTime.Now;

// Log the command in a compact format which can be copy pasted
Expand Down