Skip to content

[NativeAOT-LLVM] Add a property to build Wasm core modules for library project types #3126

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

Open
wants to merge 2 commits into
base: feature/NativeAOT-LLVM
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions docs/using-nativeaot/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ Note that assemblies other than the one being published (e. g. those from refere

See also the [NativeLibrary sample](../../samples/NativeLibrary).

### WebAssembly Core Modules for WASI

NativeAOT-LLVM by default will produce Wasi component modules using the `wasm32-unknown-wasip2` triple. If you need to produce WebAssemblyCore modules from a library project, add
```xml
<PropertyGroup>
<WasmCoreModule>true</WasmCoreModule>
</PropertyGroup>
```
to your project file. This can be useful for uses that do not support WebAssembly components, e.g. extism.

## WebAssembly module imports

Functions in other WebAssembly modules can be imported and invoked using `DllImport` and `WasmImportLinkage` e.g.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ The .NET Foundation licenses this file to you under the MIT license.
<WasmOptimizationSetting Condition="$(Optimize) == 'true' and $(OptimizationPreference) == 'Size'">-Oz</WasmOptimizationSetting>

<IlcLlvmTarget Condition="'$(_targetOS)' == 'browser'">wasm32-unknown-emscripten</IlcLlvmTarget>
<IlcLlvmTarget Condition="'$(_targetOS)' == 'wasi'">wasm32-unknown-wasip2</IlcLlvmTarget>
<IlcLlvmTarget Condition="'$(_targetOS)' == 'wasi' and '$(WasmCoreModule)' != 'true'">wasm32-unknown-wasip2</IlcLlvmTarget>
<IlcLlvmTarget Condition="'$(_targetOS)' == 'wasi' and '$(WasmCoreModule)' == 'true'">wasm32-unknown-wasi</IlcLlvmTarget>
<IlcWasmStackSize>1048576</IlcWasmStackSize> <!-- 1MB -->
<IlcWasmStackSize Condition="'$(EmccStackSize)' != ''">$(EmccStackSize)</IlcWasmStackSize>
<IlcWasmGlobalBase>1024</IlcWasmGlobalBase>
Expand Down Expand Up @@ -582,7 +583,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CustomLinkerArg Include="@(NativeObjects->'&quot;%(Identity)&quot;'->Replace(&quot;\&quot;, &quot;/&quot;))" />
<!-- The canary function should be last in the linked output. But adding it to Native[Library|Object] runs into https://github.com/dotnet/msbuild/issues/5937. -->
<CustomLinkerArg Include="&quot;$(IlcSdkPath.Replace('\', '/'))libStackTraceIpCanary.o&quot;" Condition="'$(_targetOS)' == 'browser'" />
<CustomLinkerArg Include="@(WasmComponentTypeWit->'%(FullPath)'->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" />
<CustomLinkerArg Include="@(WasmComponentTypeWit->'%(FullPath)'->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" Condition="'$(WasmCoreModule)' != 'true'"/>
<CustomLinkerArg Include="-o &quot;$(NativeBinary.Replace(&quot;\&quot;, &quot;/&quot;))&quot;" />
<CustomLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="-g3" />
<CustomLinkerArg Condition="'$(NativeDebugSymbols)' != 'true'" Include="-Wl,--strip-all" />
Expand Down