Skip to content

Commit 107ec06

Browse files
authored
Merge pull request #948 from unoplatform/dev/jela/unofileref
feat: Add support for WasmShellNativeFileReference
2 parents 8c74ae4 + 6aaa1da commit 107ec06

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

doc/features-module-linking.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ uid: UnoWasmBootstrap.ModuleLinking
66

77
## Static Linking overview
88

9-
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.
9+
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.
1010

11-
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.
11+
Files of type `.o` or `.a` specified in the MSBuild `WasmShellNativeFileReference` item will be statically linked in the application:
1212

13-
Any `.o` or `.a` file placed as `content` in the built project will be statically linked to the currently running application.
13+
```xml
14+
<ItemGroup>
15+
<WasmShellNativeFileReference Include="libMy.a" />
16+
</ItemGroup>
17+
```
18+
19+
`WasmShellNativeFileReference` also supports multi-version filtering specified below.
1420

15-
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:
21+
The .NET SDK [`NativeFileReference`](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies) is also supported.
22+
23+
### Support for Native Files as `Content`
24+
25+
Specifying native files as `Content` is also supported in version 9.x of the bootstrapper but will be removed in the next version.
26+
27+
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:
1628

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

24-
The .NET SDK [`NativeFileReference`](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies) is also supported.
25-
2636
## WebAssembly Exceptions support
2737

2838
As of version 7.0 and later, WebAssembly Exceptions support is now required.

src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
<GenerateUnoNativeAssetsTask_v0
302302
AotProfile="$(WasmAotProfilePath)"
303303
AOTProfileExcludedMethods="$(WasmShellAOTProfileExcludedMethods)"
304-
Assets="@(ContentWithTargetPath);@(_UnoWasmCopyToOutputAssets)"
304+
Assets="@(WasmShellNativeFileReference);@(ContentWithTargetPath);@(_UnoWasmCopyToOutputAssets)"
305305
CurrentProjectPath="$(MSBuildProjectDirectory)"
306306
EmscriptenVersion="$(_UnoEmscriptenVersion)"
307307
EnableThreads="@(WasmEnableThreads)"

src/Uno.Wasm.StaticLinking.Shared/Common.props

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<ItemGroup Condition="'$(UseAOT)'=='true' or '$(WasmShellGenerateAOTProfile)'=='true' or '$(WasmShellEnableLogProfiler)'=='true'">
4-
<Content Include="$(MSBuildThisFileDirectory)native/**/*.a" />
4+
<WasmShellNativeFileReference Include="$(MSBuildThisFileDirectory)native/**/*.a" Exclude="$(MSBuildThisFileDirectory)native/side.a/**" />
5+
6+
<!-- Legacy content inclusion -->
7+
<Content Include="$(MSBuildThisFileDirectory)native/side.a/**/*.a" Visible="False" />
8+
59
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test.cpp" />
610
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test2.cpp" />
711
</ItemGroup>

0 commit comments

Comments
 (0)