Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,38 @@ common prefix of the files you downloaded as the first argument:
```bash
# For example, if you downloaded FMOD 2.01.07:
./update_fmod.sh ~/Downloads/fmodstudioapi20107
```
```

## Testing HTML5/WASM pthread builds locally

WASM pthread builds require specific CORS headers to enable `SharedArrayBuffer`.
Regular `python3 -m http.server` will **not** work so please send required headers.

**Required headers:**
- `Cross-Origin-Opener-Policy: same-origin`
- `Cross-Origin-Embedder-Policy: require-corp`

So for python serving, you can add the request CORS handler like
```python3
class CORSRequestHandler(SimpleHTTPRequestHandler):
(...)
def end_headers(self):
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
```


**Build with both architectures** (loader needs both for fallback):

```bash
java -jar bob.jar build bundle --platform js-web \
--architectures wasm-web,wasm_pthread-web \
--bundle-format html5
(...)
```

Validate in the console

```javascript
console.log("Pthread:", Module.isWASMPthreadSupported); // Should be: true
```
17 changes: 15 additions & 2 deletions bridge/Makefile.emscripten
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LIBPATH := ../fmod/lib/web/libfmodbridge.a
LIBPATH_PTHREAD := ../fmod/lib/wasm_pthread-web/libfmodbridge.a

SOURCES = \
src/fmod_init.c \
Expand All @@ -10,8 +11,11 @@ CC := emcc
AR := emar

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

all: $(LIBPATH) $(LIBPATH_PTHREAD)

# Regular build
OBJECTS = $(patsubst src/%.c,build/js-%.o,$(SOURCES))

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

# Pthread build
OBJECTS_PTHREAD = $(patsubst src/%.c,build/js-pthread-%.o,$(SOURCES))

build/js-pthread-%.o: src/%.c $(HEADERS)
$(CC) $(CFLAGS_PTHREAD) -c $< -o $@

$(LIBPATH_PTHREAD): $(OBJECTS_PTHREAD)
$(AR) rcs $@ $^

clean:
rm -f $(LIBPATH) build/js-*.o
rm -f $(LIBPATH) $(LIBPATH_PTHREAD) build/js-*.o build/js-pthread-*.o

.PHONY: all clean
7 changes: 3 additions & 4 deletions fmod/ext.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ platforms:
context:
libs: ["shlwapi.lib"]

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

wasm-web:
wasm_pthread-web:
context:
libs: ["fmodbridge", "fmodstudio"]
emscriptenLinkFlags: ["EXPORTED_RUNTIME_METHODS=[\"ccall\",\"callMain\",\"UTF8ToString\",\"HEAPU8\",\"stringToUTF8\",\"cwrap\",\"getValue\",\"setValue\"]"]
emscriptenLinkFlags: ["EXPORTED_RUNTIME_METHODS=[\"ccall\",\"callMain\",\"UTF8ToString\",\"HEAPU8\",\"stringToUTF8\",\"cwrap\",\"getValue\",\"setValue\"]", "-pthread", "-s PTHREAD_POOL_SIZE=5"]
Binary file added fmod/lib/wasm_pthread-web/libfmodbridge.a
Binary file not shown.
Binary file added fmod/lib/wasm_pthread-web/libfmodstudio.a
Binary file not shown.
Binary file modified fmod/lib/web/libfmodstudio.a
Binary file not shown.
43 changes: 35 additions & 8 deletions update_fmod_linux.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,44 @@ find "$TMPDIR/win" -type f -path "*/api/studio/lib/x64/fmodstudio.dll" -exec cp
find "$TMPDIR/win" -type f -path "*/api/core/lib/x86/fmod.dll" -exec cp {} "$REPO/fmod/res/x86-win32/fmod-x86/fmod.dll" \;
find "$TMPDIR/win" -type f -path "*/api/studio/lib/x86/fmodstudio.dll" -exec cp {} "$REPO/fmod/res/x86-win32/fmod-x86/fmodstudio.dll" \;

# cp "$TMPDIR/win"/*/*/api/core/lib/x64/fmod.dll "$REPO/fmod/res/x86_64-win32/fmod-x86_64/fmod.dll"
# cp "$TMPDIR/win"/*/*/api/studio/lib/x64/fmodstudio.dll "$REPO/fmod/res/x86_64-win32/fmod-x86_64/fmodstudio.dll"
# cp "$TMPDIR/win"/*/*/api/core/lib/x86/fmod.dll "$REPO/fmod/res/x86-win32/fmod-x86/fmod.dll"
# cp "$TMPDIR/win"/*/*/api/studio/lib/x86/fmodstudio.dll "$REPO/fmod/res/x86-win32/fmod-x86/fmodstudio.dll"


echo -e "${YELLOW}Updating HTML5 FMOD...${NC}"
mkdir -p "$TMPDIR/html5"
unzip "${PREFIX}html5${FMOD_PATCH_POSTFIX}.zip" -d "$TMPDIR/html5"
# cp "$TMPDIR/html5"/*/api/studio/lib/upstream/w32/fmodstudio.a $REPO/fmod/lib/web/libfmodstudio.a
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/upstream/w32/fmodstudio.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio.a" \;

# Regular WASM libraries (non-pthread)
# FMOD w32 libs are split - we need both _wasm.a and _bindings.a combined
echo -e "${YELLOW}Extracting regular WASM libraries...${NC}"
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudio_wasm.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio_wasm.a" \;
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudio_bindings.a" -exec cp {} "$REPO/fmod/lib/web/libfmodstudio_bindings.a" \;

# Combine split libraries into single archive
cd "$REPO/fmod/lib/web"
ar -M <<EOF
CREATE libfmodstudio.a
ADDLIB libfmodstudio_wasm.a
ADDLIB libfmodstudio_bindings.a
SAVE
END
EOF
rm libfmodstudio_wasm.a libfmodstudio_bindings.a

# Pthread WASM libraries
echo -e "${YELLOW}Extracting pthread WASM libraries...${NC}"
mkdir -p "$REPO/fmod/lib/wasm_pthread-web"
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudioP_wasm.a" -exec cp {} "$REPO/fmod/lib/wasm_pthread-web/libfmodstudio_wasm.a" \;
find "$TMPDIR/html5" -type f -path "*/api/studio/lib/w32/fmodstudioP_bindings.a" -exec cp {} "$REPO/fmod/lib/wasm_pthread-web/libfmodstudio_bindings.a" \;

# Combine pthread split libraries into single archive
cd "$REPO/fmod/lib/wasm_pthread-web"
ar -M <<EOF
CREATE libfmodstudio.a
ADDLIB libfmodstudio_wasm.a
ADDLIB libfmodstudio_bindings.a
SAVE
END
EOF
rm libfmodstudio_wasm.a libfmodstudio_bindings.a
cd "$REPO"


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