Skip to content

Commit

Permalink
Merge pull request #948 from unoplatform/dev/jela/unofileref
Browse files Browse the repository at this point in the history
feat: Add support for WasmShellNativeFileReference
  • Loading branch information
jeromelaban authored Feb 13, 2025
2 parents 8c74ae4 + 6aaa1da commit 107ec06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
22 changes: 16 additions & 6 deletions doc/features-module-linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ uid: UnoWasmBootstrap.ModuleLinking

## Static Linking overview

Statically linking Emscripten LLVM Bitcode (`.o` and `.a` files) files to mono is supported on both Windows 10 and Linux. To build on Windows please refer to the AOT environment setup instructions.
Statically linking Emscripten LLVM Bitcode (`.o` and `.a` files) files is supported to embed `.o` or `.a` files with the rest of the WebAssembly modules. This allows for using p/invoke when resolving methods from the loaded native library.

This linking type embeds the `.o` or `.a` files with the rest of the WebAssembly modules, and uses _normal_ webassembly function invocations that are faster than with dynamic linking.
Files of type `.o` or `.a` specified in the MSBuild `WasmShellNativeFileReference` item will be statically linked in the application:

Any `.o` or `.a` file placed as `content` in the built project will be statically linked to the currently running application.
```xml
<ItemGroup>
<WasmShellNativeFileReference Include="libMy.a" />
</ItemGroup>
```

`WasmShellNativeFileReference` also supports multi-version filtering specified below.

This allowing for p/invoke to be functional when resolving methods from the loaded module. If you have a `.o` or a `.a` file you don't want to be include in the linking, you may add the `UnoAotCompile="false"` metadata that way:
The .NET SDK [`NativeFileReference`](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies) is also supported.

### Support for Native Files as `Content`

Specifying native files as `Content` is also supported in version 9.x of the bootstrapper but will be removed in the next version.

When specified as Content, if you have a `.o` or a `.a` file you don't want to be include in the linking, you may add the `UnoAotCompile="false"` metadata that way:

```xml
<ItemGroup>
Expand All @@ -21,8 +33,6 @@ This allowing for p/invoke to be functional when resolving methods from the load
</ItemGroup>
```

The .NET SDK [`NativeFileReference`](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies) is also supported.

## WebAssembly Exceptions support

As of version 7.0 and later, WebAssembly Exceptions support is now required.
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
<GenerateUnoNativeAssetsTask_v0
AotProfile="$(WasmAotProfilePath)"
AOTProfileExcludedMethods="$(WasmShellAOTProfileExcludedMethods)"
Assets="@(ContentWithTargetPath);@(_UnoWasmCopyToOutputAssets)"
Assets="@(WasmShellNativeFileReference);@(ContentWithTargetPath);@(_UnoWasmCopyToOutputAssets)"
CurrentProjectPath="$(MSBuildProjectDirectory)"
EmscriptenVersion="$(_UnoEmscriptenVersion)"
EnableThreads="@(WasmEnableThreads)"
Expand Down
6 changes: 5 additions & 1 deletion src/Uno.Wasm.StaticLinking.Shared/Common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup Condition="'$(UseAOT)'=='true' or '$(WasmShellGenerateAOTProfile)'=='true' or '$(WasmShellEnableLogProfiler)'=='true'">
<Content Include="$(MSBuildThisFileDirectory)native/**/*.a" />
<WasmShellNativeFileReference Include="$(MSBuildThisFileDirectory)native/**/*.a" Exclude="$(MSBuildThisFileDirectory)native/side.a/**" />

<!-- Legacy content inclusion -->
<Content Include="$(MSBuildThisFileDirectory)native/side.a/**/*.a" Visible="False" />

<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test.cpp" />
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test2.cpp" />
</ItemGroup>
Expand Down

0 comments on commit 107ec06

Please sign in to comment.