Skip to content

Commit

Permalink
[wasi] Fix WasmLinkIcalls and WasmNativeStrip support. (#91843)
Browse files Browse the repository at this point in the history
* [wasi] Fix WasmLinkIcalls and WasmNativeStrip support.

* Add a wasi AOT cross compiler nuget.

* Fix wasi.mk.

* More changes to build AOT cross compilers for wasi.

* Tidy up the xml a bit.

* Share _GetNugetsForAOT target with wasi.
  • Loading branch information
vargaz authored Nov 16, 2023
1 parent 7990c07 commit 33d7f98
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 38 deletions.
26 changes: 0 additions & 26 deletions eng/testing/tests.browser.targets
Original file line number Diff line number Diff line change
Expand Up @@ -354,30 +354,4 @@
*******************" />
</Target>

<Target Name="_GetNugetsForAOT" Returns="@(_NuGetsToBuild)">
<PropertyGroup>
<!-- Eg. Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.browser-wasm.6.0.0-dev.nupkg -->
<_AOTCrossNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.AOT.$(NETCoreSdkRuntimeIdentifier).Cross.$(RuntimeIdentifier).$(PackageVersionForWorkloadManifests).nupkg</_AOTCrossNuGetPath>
</PropertyGroup>

<ItemGroup>
<_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Ref.$(PackageVersionForWorkloadManifests).nupkg"
Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App\Microsoft.NETCore.App.Ref.sfxproj"
Properties="@(_DefaultPropsForNuGetBuild, ';')"
Descriptor="Ref pack"/>

<!-- AOT Cross compiler -->
<_PropsForAOTCrossBuild Include="@(_DefaultPropsForNuGetBuild)" />
<_PropsForAOTCrossBuild Include="TestingWorkloads=true" />
<_PropsForAOTCrossBuild Include="RuntimeIdentifier=$(NETCoreSdkRuntimeIdentifier)" />
<_PropsForAOTCrossBuild Include="TargetCrossRid=$(RuntimeIdentifier)" />
<_PropsForAOTCrossBuild Include="DisableSourceLink=true" />

<_NuGetsToBuild Include="$(_AOTCrossNuGetPath)"
Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App\Microsoft.NETCore.App.MonoCrossAOT.sfxproj"
Properties="@(_PropsForAOTCrossBuild,';')"
Descriptor="AOT Cross compiler"/>
</ItemGroup>
</Target>
</Project>
1 change: 1 addition & 0 deletions eng/testing/tests.wasi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<!--<InstallWorkloadUsingArtifactsDependsOn>_GetWorkloadsToInstall;$(InstallWorkloadUsingArtifactsDependsOn)</InstallWorkloadUsingArtifactsDependsOn>-->
<GetWorkloadInputsDependsOn>_GetWorkloadsToInstall;$(GetWorkloadInputsDependsOn)</GetWorkloadInputsDependsOn>
<GetNuGetsToBuildForWorkloadTestingDependsOn>_GetNugetsForAOT;$(GetNuGetsToBuildForWorkloadTestingDependsOn)</GetNuGetsToBuildForWorkloadTestingDependsOn>
<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == ''">$([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
</PropertyGroup>

Expand Down
26 changes: 26 additions & 0 deletions eng/testing/tests.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,30 @@
<Target Name="DeployHelixTargetsFile" AfterTargets="ArchiveTests" Condition="'$(HelixTargetsFile)' != ''">
<Copy SourceFiles="$(HelixTargetsFile)" DestinationFiles="$(TestArchiveTestsDir)$(TestProjectName).helix.targets" SkipUnchangedFiles="true" />
</Target>

<Target Name="_GetNugetsForAOT" Returns="@(_NuGetsToBuild)">
<PropertyGroup>
<!-- Eg. Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.browser-wasm.6.0.0-dev.nupkg -->
<_AOTCrossNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.AOT.$(NETCoreSdkRuntimeIdentifier).Cross.$(RuntimeIdentifier).$(PackageVersionForWorkloadManifests).nupkg</_AOTCrossNuGetPath>
</PropertyGroup>

<ItemGroup>
<_NuGetsToBuild Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Ref.$(PackageVersionForWorkloadManifests).nupkg"
Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App\Microsoft.NETCore.App.Ref.sfxproj"
Properties="@(_DefaultPropsForNuGetBuild, ';')"
Descriptor="Ref pack"/>

<!-- AOT Cross compiler -->
<_PropsForAOTCrossBuild Include="@(_DefaultPropsForNuGetBuild)" />
<_PropsForAOTCrossBuild Include="TestingWorkloads=true" />
<_PropsForAOTCrossBuild Include="RuntimeIdentifier=$(NETCoreSdkRuntimeIdentifier)" />
<_PropsForAOTCrossBuild Include="TargetCrossRid=$(RuntimeIdentifier)" />
<_PropsForAOTCrossBuild Include="DisableSourceLink=true" />

<_NuGetsToBuild Include="$(_AOTCrossNuGetPath)"
Project="$(InstallerProjectRoot)pkg/sfx/Microsoft.NETCore.App\Microsoft.NETCore.App.MonoCrossAOT.sfxproj"
Properties="@(_PropsForAOTCrossBuild,';')"
Descriptor="AOT Cross compiler"/>
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"packs": [
"Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk",
"Microsoft.NETCore.App.Runtime.Mono.wasi-wasm",
"Microsoft.NET.Runtime.WebAssembly.Templates"
"Microsoft.NET.Runtime.WebAssembly.Templates",
"Microsoft.NETCore.App.Runtime.AOT.Cross.wasi-wasm"
],
"extends": [ "microsoft-net-runtime-mono-tooling" ],
"platforms": [ "win-x64", "win-arm64", "linux-x64", "linux-arm64", "osx-x64", "osx-arm64" ]
Expand Down Expand Up @@ -372,6 +373,18 @@
"osx-arm64": "Microsoft.NETCore.App.Runtime.AOT.osx-arm64.Cross.browser-wasm"
}
},
"Microsoft.NETCore.App.Runtime.AOT.Cross.wasi-wasm": {
"kind": "Sdk",
"version": "${PackageVersion}",
"alias-to": {
"win-x64": "Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.wasi-wasm",
"win-arm64": "Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.wasi-wasm",
"linux-x64": "Microsoft.NETCore.App.Runtime.AOT.linux-x64.Cross.wasi-wasm",
"linux-arm64": "Microsoft.NETCore.App.Runtime.AOT.linux-arm64.Cross.wasi-wasm",
"osx-x64": "Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.wasi-wasm",
"osx-arm64": "Microsoft.NETCore.App.Runtime.AOT.osx-arm64.Cross.wasi-wasm"
}
},
"Microsoft.NETCore.App.Runtime.Mono.browser-wasm" : {
"kind": "framework",
"version": "${PackageVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk" />
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.wasi-wasm" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
</ImportGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasi/wasi.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ clean:
rm -rf bin $(TOP)/artifacts/obj/mono/$(PROJECT_NAME:%.csproj=%)

run-console:
cd bin/wasi-wasm/AppBundle && PATH=${WASMTIME_PROV_DIR}:${PATH} ./run-wasmtime.sh $(ARGS)
cd bin/wasi-wasm/AppBundle && PATH="${WASMTIME_PROV_DIR}:${PATH}" ./run-wasmtime.sh $(ARGS)
20 changes: 10 additions & 10 deletions src/mono/wasi/build/WasiApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
Text="$(_ToolchainMissingErrorMessage) Emscripten SDK is required for building native files." />

<PropertyGroup>
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','wasi-wasm'))</_MonoAotCrossCompilerPath>
<_WasiClangDefaultFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-default.rsp'))</_WasiClangDefaultFlagsRsp>
<_WasiClangDefaultLinkFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-link.rsp'))</_WasiClangDefaultLinkFlagsRsp>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
Expand All @@ -115,7 +115,7 @@
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>

<_WasmICallTablePath>$(_WasmIntermediateOutputPath)icall-table.h</_WasmICallTablePath>
<!--<_WasmRuntimeICallTablePath>$(_WasmIntermediateOutputPath)runtime-icall-table.h</_WasmRuntimeICallTablePath>-->
<_WasmRuntimeICallTablePath>$(_WasmIntermediateOutputPath)runtime-icall-table.h</_WasmRuntimeICallTablePath>
<_WasmPInvokeTablePath>$(_WasmIntermediateOutputPath)pinvoke-table.h</_WasmPInvokeTablePath>
<_WasmInterpToNativeTablePath>$(_WasmIntermediateOutputPath)wasm_m2n_invoke.g.h</_WasmInterpToNativeTablePath>
<_WasmPInvokeHPath>$(_WasmRuntimePackIncludeDir)wasm\pinvoke.h</_WasmPInvokeHPath>
Expand Down Expand Up @@ -176,6 +176,7 @@
<_WasmCommonCFlags Condition="'$(WasmSingleFileBundle)' == 'true'" Include="-DWASM_SINGLE_FILE=1" />
<_WasmCommonCFlags Condition="'$(InvariantGlobalization)' == 'true'" Include="-DINVARIANT_GLOBALIZATION=1" />
<_WasmCommonCFlags Condition="'$(InvariantTimezone)' == 'true'" Include="-DINVARIANT_TIMEZONE=1" />
<_WasmCommonCFlags Condition="'$(WasmLinkIcalls)' == 'true'" Include="-DLINK_ICALLS=1" />

<!-- Adding optimization flag at the top, so it gets precedence -->
<!--<_EmccCFlags Include="$(EmccCompileOptimizationFlag)" />-->
Expand Down Expand Up @@ -242,14 +243,13 @@
</PropertyGroup>

<Error Condition="'$(_HasMscorlib)' != 'true' and !Exists($(_MscorlibPath))" Text="Could not find 'mscorlib.dll' in the runtime pack at $(_MscorlibPath)" />
<Error Condition="'$(_MonoAotCrossCompilerPath)' == '' or !Exists('$(_MonoAotCrossCompilerPath)')"
Text="Could not find AOT cross compiler at %24(_MonoAotCrossCompilerPath)=$(_MonoAotCrossCompilerPath)" />

<!--<Error Condition="'$(_MonoAotCrossCompilerPath)' == '' or !Exists('$(_MonoAotCrossCompilerPath)')"-->
<!--Text="Could not find AOT cross compiler at %24(_MonoAotCrossCompilerPath)=$(_MonoAotCrossCompilerPath)" />-->

<!--<Exec Command='"$(_MonoAotCrossCompilerPath)" print-icall-table > "$(_WasmRuntimeICallTablePath)"' />-->
<!--<ItemGroup>-->
<!--<FileWrites Include="$(_WasmRuntimeICallTablePath)" />-->
<!--</ItemGroup>-->
<Exec Command='"$(_MonoAotCrossCompilerPath)" --print-icall-table > "$(_WasmRuntimeICallTablePath)"' Condition="!Exists($(_WasmRuntimeICallTablePath))" />
<ItemGroup>
<FileWrites Include="$(_WasmRuntimeICallTablePath)" />
</ItemGroup>

<MakeDir Directories="$(_WasmIntermediateOutputPath)" Condition="!Exists('$(_WasmIntermediateOutputPath)')" />

Expand Down Expand Up @@ -461,7 +461,7 @@
<_WasiSdkClangArgs Include="-Wl,--export=malloc,--export=free,--export=__heap_base,--export=__data_end" />
<!-- keep in sync with src\mono\wasi\wasi.proj -->
<_WasiSdkClangArgs Include="-Wl,-z,stack-size=8388608,-lwasi-emulated-process-clocks,-lwasi-emulated-signal,-lwasi-emulated-mman"/>
<_WasiSdkClangArgs Include="-Wl,-s" /> <!-- Strip debug symbols -->
<_WasiSdkClangArgs Include="-Wl,-s" Condition="'$(WasmNativeStrip)' == 'true'"/>

<_WasiSdkClangArgs Include="@(_WasiSdkLinkerFlags -> '-Xlinker %(Identity)', ' ')" />

Expand Down
12 changes: 12 additions & 0 deletions src/mono/wasi/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,21 @@ void load_icu_data (void);

int mono_wasm_enable_gc = 1;

/* Not part of public headers */
#define MONO_ICALL_TABLE_CALLBACKS_VERSION 3

typedef struct {
int version;
void* (*lookup) (MonoMethod *method, char *classname, char *methodname, char *sigstart, int32_t *flags);
const char* (*lookup_icall_symbol) (void* func);
} MonoIcallTableCallbacks;

int
mono_string_instance_is_interned (MonoString *str_raw);

void
mono_install_icall_table_callbacks (const MonoIcallTableCallbacks *cb);

void mono_trace_init (void);

#define g_new(type, size) ((type *) malloc (sizeof (type) * (size)))
Expand Down

0 comments on commit 33d7f98

Please sign in to comment.