Skip to content

Commit 8d1dddf

Browse files
Add multithreaded builds to dotnet-wasm CI. (#6319)
* Add multithreaded builds to dotnet-wasm CI. * Try again. * Try again. * Try again. * Minor improvements.
1 parent e4b0362 commit 8d1dddf

4 files changed

Lines changed: 46 additions & 24 deletions

File tree

.github/workflows/build-test-distribute.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ jobs:
217217
- name: Download C# Wasm Archive (single thread)
218218
uses: actions/download-artifact@v8
219219
with:
220-
pattern: DotNetPatchArchiveWasm-Single
221-
path: browser_wasm_runtime_single
220+
pattern: DotNetPatchArchiveWasm-*
221+
path: browser_wasm_runtime
222+
merge-multiple: true
222223

223224
- name: Build C# Wasm package
224225
run: |
225226
mkdir meshlib_dotnet-wasm
226227
mkdir meshlib_dotnet-wasm/native
227228
move dotnet_dll/MRDotNet2Static.dll meshlib_dotnet-wasm
228-
mkdir meshlib_dotnet-wasm/native/single
229-
move browser_wasm_runtime_single/* meshlib_dotnet-wasm/native/single
229+
move browser_wasm_runtime/* meshlib_dotnet-wasm/native
230230
Compress-Archive -Path meshlib_dotnet-wasm -DestinationPath meshlib_dotnet-wasm.zip
231231
232232
- name: Generate NuGet specification

.github/workflows/build-test-emscripten-c-bindings.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@ on:
1111
type: boolean
1212

1313
jobs:
14-
emscripten-build:
14+
emscripten-build-c-bindings:
1515
timeout-minutes: 40
1616
runs-on: ubuntu-24.04
1717
container:
1818
image: meshlib/meshlib-emscripten-build-c-bindings:${{ inputs.docker_image_tag }}
1919
strategy:
2020
fail-fast: false
21+
matrix:
22+
config: [Singlethreaded, Multithreaded]
23+
include:
24+
- config: Singlethreaded
25+
target_name: emscripten-singlethreaded
26+
short_name: singlethreaded
27+
thirdparty-dir: emscripten-single
28+
- config: Multithreaded
29+
target_name: emscripten
30+
short_name: multithreaded
31+
thirdparty-dir: emscripten
2132

2233
steps:
2334
- name: Work-around possible permission issues
@@ -42,7 +53,7 @@ jobs:
4253
continue-on-error: true
4354
uses: ./.github/actions/collect-runner-stats
4455
with:
45-
target_os: emscripten-singlethreaded
56+
target_os: ${{ matrix.target_name }}
4657
target_arch: wasm
4758
cxx_compiler: emcc
4859
build_config: Release
@@ -65,9 +76,9 @@ jobs:
6576
6677
- name: Install thirdparty libs
6778
run: |
68-
ln -s /usr/local/lib/emscripten-single/include ./include
69-
ln -s /usr/local/lib/emscripten-single/lib ./lib
70-
ln -s /usr/local/lib/emscripten-single/share ./share
79+
ln -s /usr/local/lib/${{ matrix.thirdparty-dir }}/include ./include
80+
ln -s /usr/local/lib/${{ matrix.thirdparty-dir }}/lib ./lib
81+
ln -s /usr/local/lib/${{ matrix.thirdparty-dir }}/share ./share
7182
7283
- name: Wait for C bindings
7384
uses: ./.github/actions/wait-for-job
@@ -93,7 +104,7 @@ jobs:
93104
MR_EMSCRIPTEN: "ON"
94105
MESHLIB_BUILD_RELEASE: "ON"
95106
MESHLIB_BUILD_DEBUG: "OFF"
96-
MR_EMSCRIPTEN_SINGLE: "ON"
107+
MR_EMSCRIPTEN_SINGLE: ${{ fromJSON('["OFF", "ON"]')[matrix.config == 'Singlethreaded'] }}
97108
MR_EMSCRIPTEN_WASM64: "OFF"
98109
MR_EMSCRIPTEN_MIMALLOC: "OFF"
99110
# options to be passed to cmake
@@ -105,17 +116,17 @@ jobs:
105116
--target MeshLibC2
106117
run: ./scripts/build_source.sh
107118

108-
- name: Prepare C bindings for Wasm
119+
- name: Prepare output files
109120
shell: bash
110121
run: |
111-
mkdir wasm_files
112-
cp build/Release/bin/*.a wasm_files
113-
cp lib/*.a wasm_files
122+
mkdir -p wasm_files/${{matrix.short_name}}
123+
cp build/Release/bin/*.a wasm_files/${{matrix.short_name}}
124+
cp lib/*.a wasm_files/${{matrix.short_name}}
114125
115-
- name: Upload Wasm files to Artifacts
126+
- name: Upload to Artifacts
116127
uses: actions/upload-artifact@v7
117128
with:
118-
name: DotNetPatchArchiveWasm-Single
129+
name: DotNetPatchArchiveWasm-${{matrix.short_name}}
119130
path: ./wasm_files/*
120131
retention-days: 1
121132
overwrite: true

docker/emscripten-build-c-bindingsDockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ COPY . .
3737
ENV MR_STATE=DOCKER_BUILD
3838
ENV MR_EMSCRIPTEN=ON
3939

40+
# 32-bit multi-threaded
41+
RUN <<EOF
42+
set -e
43+
./scripts/build_thirdparty.sh
44+
./scripts/cmake_install.sh /opt/meshlib-thirdparty/emscripten
45+
rm -rf bin include lib share thirdparty_build
46+
EOF
47+
4048
# 32-bit single-threaded
4149
RUN <<EOF
4250
set -e
@@ -48,6 +56,7 @@ EOF
4856

4957
FROM base
5058

59+
COPY --from=builder /opt/meshlib-thirdparty/emscripten /usr/local/lib/emscripten
5160
COPY --from=builder /opt/meshlib-thirdparty/emscripten-single /usr/local/lib/emscripten-single
5261

5362
# Setup non-root user (use 1001 to play nicely with actions/checkout@v4)

docs/using_dotnet_wasm_bindings.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@ If you also have installed MeshLib in Nuget-for-Unity (which is a good idea to b
2424

2525
2. Click on `meshlib_vA.B.C.D_dotnet-wasm/MRDotNet2Static.dll`.
2626

27-
* On the right panel, uncheck `Any Platform`, and check `Include Platforms`->`WebGL`.
27+
* On the right panel, uncheck `Any Platform`, and enable only `Include Platforms`->`WebGL`.
2828

2929
* Click `Apply`.
3030

31-
3. Open `meshlib_vA.B.C.D_dotnet-wasm/native/single/`.
31+
3. Open `meshlib_vA.B.C.D_dotnet-wasm/native/singlethreaded/` or `.../multithreaded/`.
3232

33-
4. Select all files there (`.a` files).
33+
This must match your Wasm build settings in Unity. If you enabled Wasm multithreading in Unity, use the multithreaded version of the files. If you don't know what you're doing, you probably have a single-threaded build.
3434

35-
* On the right panel, similarly uncheck `Any Platform`, and check `Include Platforms`->`WebGL`.
35+
* Select all files there (`.a` files).
36+
37+
* On the right panel, similarly uncheck `Any Platform`, and enable only `Include Platforms`->`WebGL`.
3638

3739
* Click `Apply`.
3840

39-
5. Uncheck specific libraries that conflcit with Unity:
41+
4. Uncheck specific libraries that conflcit with Unity:
4042

4143
* Select only `libblosc.a` and uncheck `WebGL`. Click `Apply`.
4244

4345
Unity links some libraries of its own into the Wasm build, which conflict with ours, and need to be disabled.
4446

4547
We still add them to the distribution for use outside of Unity.
4648

47-
## Different kinds of binaries
49+
5. Uncheck the unused libraries:
4850

49-
Right now we only ship one set of C++ binaries (`meshlib_vA.B.C.D_dotnet-wasm/native/single`). Those are single-threaded.
51+
* If you used `.../singlethreaded/` libraries, then disable the `.../multithreaded/` ones, or vice versa.
5052

51-
We plan to add more configurations (at least a multithreaded one), and possibly have versions built with different versions of Emscripten SDK (to match different versions of Unity).
53+
* To disable them, open the respective directory, select all files there (`.a` files), uncheck `Any Platform` and uncheck all platforms.

0 commit comments

Comments
 (0)