Skip to content

Commit 61a65f5

Browse files
authored
17 - Fmod 2.03.09 pthread Support (#18)
* 17 - Wasm Pthread Support * 17 - testing clarification * 17 - attempted removing pthread pool size * 17 - better manifest
1 parent 02c7547 commit 61a65f5

File tree

7 files changed

+88
-15
lines changed

7 files changed

+88
-15
lines changed

CONTRIBUTE.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,38 @@ common prefix of the files you downloaded as the first argument:
8282
```bash
8383
# For example, if you downloaded FMOD 2.01.07:
8484
./update_fmod.sh ~/Downloads/fmodstudioapi20107
85-
```
85+
```
86+
87+
## Testing HTML5/WASM pthread builds locally
88+
89+
WASM pthread builds require specific CORS headers to enable `SharedArrayBuffer`.
90+
Regular `python3 -m http.server` will **not** work so please send required headers.
91+
92+
**Required headers:**
93+
- `Cross-Origin-Opener-Policy: same-origin`
94+
- `Cross-Origin-Embedder-Policy: require-corp`
95+
96+
So for python serving, you can add the request CORS handler like
97+
```python3
98+
class CORSRequestHandler(SimpleHTTPRequestHandler):
99+
(...)
100+
def end_headers(self):
101+
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
102+
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
103+
```
104+
105+
106+
**Build with both architectures** (loader needs both for fallback):
107+
108+
```bash
109+
java -jar bob.jar build bundle --platform js-web \
110+
--architectures wasm-web,wasm_pthread-web \
111+
--bundle-format html5
112+
(...)
113+
```
114+
115+
Validate in the console
116+
117+
```javascript
118+
console.log("Pthread:", Module.isWASMPthreadSupported); // Should be: true
119+
```

bridge/Makefile.emscripten

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
LIBPATH := ../fmod/lib/web/libfmodbridge.a
2+
LIBPATH_PTHREAD := ../fmod/lib/wasm_pthread-web/libfmodbridge.a
23

34
SOURCES = \
45
src/fmod_init.c \
@@ -10,8 +11,11 @@ CC := emcc
1011
AR := emar
1112

1213
CFLAGS := -O3 -fvisibility=hidden -I./include -s ALLOW_MEMORY_GROWTH=1 -s LEGACY_RUNTIME=1
13-
all: $(LIBPATH)
14+
CFLAGS_PTHREAD := -O3 -visibility=hidden -I./include -s ALLOW_MEMORY_GROWTH=1 -pthread
1415

16+
all: $(LIBPATH) $(LIBPATH_PTHREAD)
17+
18+
# Regular build
1519
OBJECTS = $(patsubst src/%.c,build/js-%.o,$(SOURCES))
1620

1721
build/js-%.o: src/%.c $(HEADERS)
@@ -20,7 +24,16 @@ build/js-%.o: src/%.c $(HEADERS)
2024
$(LIBPATH): $(OBJECTS)
2125
$(AR) rcs $@ $^
2226

27+
# Pthread build
28+
OBJECTS_PTHREAD = $(patsubst src/%.c,build/js-pthread-%.o,$(SOURCES))
29+
30+
build/js-pthread-%.o: src/%.c $(HEADERS)
31+
$(CC) $(CFLAGS_PTHREAD) -c $< -o $@
32+
33+
$(LIBPATH_PTHREAD): $(OBJECTS_PTHREAD)
34+
$(AR) rcs $@ $^
35+
2336
clean:
24-
rm -f $(LIBPATH) build/js-*.o
37+
rm -f $(LIBPATH) $(LIBPATH_PTHREAD) build/js-*.o build/js-pthread-*.o
2538

2639
.PHONY: all clean

fmod/ext.manifest

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ platforms:
3232
context:
3333
libs: ["shlwapi.lib"]
3434

35-
js-web:
35+
web:
3636
context:
3737
libs: ["fmodbridge", "fmodstudio"]
3838
emscriptenLinkFlags: ["EXPORTED_RUNTIME_METHODS=[\"ccall\",\"callMain\",\"UTF8ToString\",\"HEAPU8\",\"stringToUTF8\",\"cwrap\",\"getValue\",\"setValue\"]"]
3939

40-
wasm-web:
40+
wasm_pthread-web:
4141
context:
42-
libs: ["fmodbridge", "fmodstudio"]
43-
emscriptenLinkFlags: ["EXPORTED_RUNTIME_METHODS=[\"ccall\",\"callMain\",\"UTF8ToString\",\"HEAPU8\",\"stringToUTF8\",\"cwrap\",\"getValue\",\"setValue\"]"]
42+
emscriptenLinkFlags: ["EXPORTED_RUNTIME_METHODS=[\"ccall\",\"callMain\",\"UTF8ToString\",\"HEAPU8\",\"stringToUTF8\",\"cwrap\",\"getValue\",\"setValue\"]", "-pthread", "-s PTHREAD_POOL_SIZE=5"]
498 KB
Binary file not shown.
6.51 MB
Binary file not shown.

fmod/lib/web/libfmodstudio.a

-23.6 KB
Binary file not shown.

update_fmod_linux.sh

100644100755
Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,44 @@ find "$TMPDIR/win" -type f -path "*/api/studio/lib/x64/fmodstudio.dll" -exec cp
2929
find "$TMPDIR/win" -type f -path "*/api/core/lib/x86/fmod.dll" -exec cp {} "$REPO/fmod/res/x86-win32/fmod-x86/fmod.dll" \;
3030
find "$TMPDIR/win" -type f -path "*/api/studio/lib/x86/fmodstudio.dll" -exec cp {} "$REPO/fmod/res/x86-win32/fmod-x86/fmodstudio.dll" \;
3131

32-
# cp "$TMPDIR/win"/*/*/api/core/lib/x64/fmod.dll "$REPO/fmod/res/x86_64-win32/fmod-x86_64/fmod.dll"
33-
# cp "$TMPDIR/win"/*/*/api/studio/lib/x64/fmodstudio.dll "$REPO/fmod/res/x86_64-win32/fmod-x86_64/fmodstudio.dll"
34-
# cp "$TMPDIR/win"/*/*/api/core/lib/x86/fmod.dll "$REPO/fmod/res/x86-win32/fmod-x86/fmod.dll"
35-
# cp "$TMPDIR/win"/*/*/api/studio/lib/x86/fmodstudio.dll "$REPO/fmod/res/x86-win32/fmod-x86/fmodstudio.dll"
36-
37-
3832
echo -e "${YELLOW}Updating HTML5 FMOD...${NC}"
3933
mkdir -p "$TMPDIR/html5"
4034
unzip "${PREFIX}html5${FMOD_PATCH_POSTFIX}.zip" -d "$TMPDIR/html5"
41-
# cp "$TMPDIR/html5"/*/api/studio/lib/upstream/w32/fmodstudio.a $REPO/fmod/lib/web/libfmodstudio.a
42-
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/upstream/w32/fmodstudio.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio.a" \;
35+
36+
# Regular WASM libraries (non-pthread)
37+
# FMOD w32 libs are split - we need both _wasm.a and _bindings.a combined
38+
echo -e "${YELLOW}Extracting regular WASM libraries...${NC}"
39+
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudio_wasm.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio_wasm.a" \;
40+
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudio_bindings.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio_bindings.a" \;
41+
42+
# Combine split libraries into single archive
43+
cd "$REPO/fmod/lib/web"
44+
ar -M <<EOF
45+
CREATE libfmodstudio.a
46+
ADDLIB libfmodstudio_wasm.a
47+
ADDLIB libfmodstudio_bindings.a
48+
SAVE
49+
END
50+
EOF
51+
rm libfmodstudio_wasm.a libfmodstudio_bindings.a
52+
53+
# Pthread WASM libraries
54+
echo -e "${YELLOW}Extracting pthread WASM libraries...${NC}"
55+
mkdir -p "$REPO/fmod/lib/wasm_pthread-web"
56+
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudioP_wasm.a" -exec cp {} "$REPO/fmod/lib/wasm_pthread-web/libfmodstudio_wasm.a" \;
57+
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudioP_bindings.a" -exec cp {} "$REPO/fmod/lib/wasm_pthread-web/libfmodstudio_bindings.a" \;
58+
59+
# Combine pthread split libraries into single archive
60+
cd "$REPO/fmod/lib/wasm_pthread-web"
61+
ar -M <<EOF
62+
CREATE libfmodstudio.a
63+
ADDLIB libfmodstudio_wasm.a
64+
ADDLIB libfmodstudio_bindings.a
65+
SAVE
66+
END
67+
EOF
68+
rm libfmodstudio_wasm.a libfmodstudio_bindings.a
69+
cd "$REPO"
4370

4471

4572
echo -e "${YELLOW}Updating Android FMOD...${NC}"

0 commit comments

Comments
 (0)