Skip to content

Commit

Permalink
Merge pull request #865 from unoplatform/dev/jela/multiple-native
Browse files Browse the repository at this point in the history
fix: Multiple native files compilation
  • Loading branch information
jeromelaban authored Jun 22, 2024
2 parents 82b744b + d5327dc commit e739ea4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uno.Wasm.Packager/packager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ int Run (string[] args) {
if (build_wasm) {
string zlibhelper = enable_zlib ? "$builddir/zlib-helper.o" : "";

var native_compile_params = string.Join("", native_compile.Select(f => $"$builddir/{Path.GetFileNameWithoutExtension(f)}.o"));
var native_compile_params = string.Join(" ", native_compile.Select(f => $"$builddir/{Path.GetFileNameWithoutExtension(f)}.o"));

ninja.WriteLine ($"build $appdir/dotnet.native.js $appdir/dotnet.native.wasm: emcc-link $builddir/driver.o $builddir/pinvoke.o {native_compile_params} {zlibhelper} {wasm_core_bindings} {ofiles} {profiler_libs} {extra_link_libs} {runtime_libs} | {EscapePath(src_prefix)}/es6/dotnet.es6.lib.js {wasm_core_support} $emsdk_env");
ninja.WriteLine ($" out_wasm=$appdir/dotnet.native.wasm");
Expand Down
1 change: 1 addition & 0 deletions src/Uno.Wasm.StaticLinking.Shared/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ItemGroup Condition="'$(UseAOT)'=='true' or '$(WasmShellGenerateAOTProfile)'=='true'">
<Content Include="$(MSBuildThisFileDirectory)native/**/*.bc" />
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test.cpp" />
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test2.cpp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Web.Services.Description" Version="4.10.0" />
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.Wasm.StaticLinking.Shared/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void Main()
var chmodRes = AdditionalImportTest.chmod("/tmp/test.txt", AdditionalImportTest.UGO_RWX);

var additionalNativeAdd = AdditionalImportTest.additional_native_add(21, 21);
var additionalNativeAdd2 = AdditionalImportTest.additional_native_add2(21, 21);

var resManager = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly);
var s1 = resManager.GetString("WebDescriptionMissing", new CultureInfo("en-US"));
Expand Down Expand Up @@ -137,6 +138,8 @@ static class AdditionalImportTest
internal static extern int chmod(string pathname, int mode);
[DllImport("__Native")]
internal static extern int additional_native_add(int left, int right);
[DllImport("__Native")]
internal static extern int additional_native_add2(int left, int right);
}

class SideModule1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
<None Include="$(MSBuildThisFileDirectory)side_module\pre.js" />
<None Include="$(MSBuildThisFileDirectory)side_module\server.py" />
<None Include="$(MSBuildThisFileDirectory)side_module\side.wasm" />
<None Include="$(MSBuildThisFileDirectory)test2.cpp" />
<None Include="$(MSBuildThisFileDirectory)test.cpp" />
</ItemGroup>
<ItemGroup Condition="'$(UseAOT)'=='true' or '$(WasmShellGenerateAOTProfile)'=='true' or '$(WasmShellEnableLogProfiler)'=='true'">
<Content Include="$(MSBuildThisFileDirectory)native/**/*.bc" />
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test.cpp" />
<WasmShellNativeCompile Include="$(MSBuildThisFileDirectory)test2.cpp" />
</ItemGroup>
<ItemGroup>
<WasmShellEmccExportedRuntimeMethod Include="GL" />
Expand Down
1 change: 1 addition & 0 deletions src/Uno.Wasm.StaticLinking.Shared/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ WASM_EXPORT int test_gl() {
GLuint programObject;
glGetString(GL_VENDOR);
SDL_Init(SDL_INIT_VIDEO);
return 0;
}
14 changes: 14 additions & 0 deletions src/Uno.Wasm.StaticLinking.Shared/test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#define WASM_EXPORT __attribute__((visibility("default")))

extern "C" {
WASM_EXPORT int additional_native_add2(int a, int b);
}

WASM_EXPORT int additional_native_add2(int a, int b) {
printf("additional_native_add2(%d, %d)\r\n", a, b);
return a + b;
}

0 comments on commit e739ea4

Please sign in to comment.