Skip to content

Commit

Permalink
fix js wasm build with new simplified build system
Browse files Browse the repository at this point in the history
  • Loading branch information
jaromil committed Sep 23, 2024
1 parent 2f1a3d9 commit 84a33ff
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ jobs:
with:
version: ${{ env.EM_VERSION }}
- run: sudo apt-get update; sudo apt-get install zsh meson ninja-build
- run: yarn
- run: yarn build
- run: yarn --cwd bindings/javascript
- run: yarn --cwd bindings/javascript build
env:
EMSCRIPTEN: ${{ env.EMSDK }}/upstream/emscripten
- name: 🧪 test bindings node-${{ matrix.node-version }}
run: yarn test
run: yarn --cwd bindings/javascript test
- name: 🔐 check crypto with node-${{ matrix.node-version }}
working-directory: ./
run: make check-js
Expand Down Expand Up @@ -358,8 +358,8 @@ jobs:
with:
version: ${{ env.EM_VERSION }}
- run: sudo apt-get update; sudo apt-get install zsh meson ninja-build
- run: yarn
- run: yarn build
- run: yarn --cwd bindings/javascript
- run: yarn --cwd bindings/javascript build
env:
EMSCRIPTEN: ${{ env.EMSDK }}/upstream/emscripten
- uses: actions/upload-artifact@v4
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ include ${pwd}/build/windows.mk
# build targets for linux systems (also musl and android)
include ${pwd}/build/linux.mk

# build targets for the meson build system (mostly linux)
include ${pwd}/build/meson.mk

# build targets for apple systems (OSX and IOS)
include ${pwd}/build/osx.mk

Expand Down
9 changes: 6 additions & 3 deletions bindings/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"scripts": {
"lint": "npx standard",
"build": "run-s build:*",
"build:zenroom": "cd ../.. && COMPILE_LUA=1 make javascript",
"build:zenroom": "cd ../.. && make -f build/wasm.mk",
"build:clean": "rimraf dist/*",
"build:copylibs": "mkdirp dist/main && mkdirp dist/module && cp -v ../../build/npm/* dist/main/ && cp -v ../../build/npm/* dist/module",
"build:copylibssrc": "cp -v ../../build/npm/* src/",
"build:copylibs": "mkdirp dist/main && mkdirp dist/module && cp -v ../../zenroom.js dist/main/ && cp -v ../../zenroom.js dist/module/",
"build:copylibssrc": "cp -v ../../zenroom.js src/",
"build:typescript": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"coverage:old": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
Expand Down Expand Up @@ -107,5 +107,8 @@
"**/*.spec.js",
"**/zenroom.js"
]
},
"dependencies": {
"yarn": "^1.22.22"
}
}
2 changes: 1 addition & 1 deletion build/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ check-linux: prepare-executables
@echo "----------------"


check-js: test-exec := node ${pwd}/test/zenroom_exec.js ${pwd}/src/zenroom.js
check-js: test-exec := node ${pwd}/test/zenroom_exec.js ${pwd}/zenroom.js
check-js:
@echo "#!/bin/sh\n${test-exec} \$$@\n" > test/zenroom && chmod +x test/zenroom
$(call bats, test/lua/native.bats)
Expand Down
33 changes: 33 additions & 0 deletions build/wasm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Initialize build defaults
include build/init.mk

# Add here any function used from JS
WASM_EXPORTS := '["_malloc","_zenroom_exec","_zencode_exec","_zenroom_hash_init","_zenroom_hash_update","_zenroom_hash_final","_zencode_valid_input","_zencode_valid_code"]'

# EMSDK should point to installation of EMSDK i.e.: /opt/emsdk
EMSCRIPTEN ?= ${EMSDK}/upstream/emscripten
cc := ${EMSCRIPTEN}/emcc
ar := ${EMSCRIPTEN}/emar
ld := ${cc}
ranlib := ${EMSCRIPTEN}/emranlib
system := Javascript
ld_emsdk_settings := -I ${EMSCRIPTEN}/system/include/libc -DLIBRARY
ld_emsdk_settings += -sMODULARIZE=1 -sSINGLE_FILE=1 --embed-file 'src/lua@/'
ld_emsdk_settings += -sMALLOC=dlmalloc --no-heap-copy -sALLOW_MEMORY_GROWTH=1
ld_emsdk_settings += -sINITIAL_MEMORY=${JS_INIT_MEM} -sMAXIMUM_MEMORY=${JS_MAX_MEM} -sSTACK_SIZE=${JS_STACK_SIZE}
ld_emsdk_settings += -sINCOMING_MODULE_JS_API=print,printErr -s EXPORTED_FUNCTIONS=${WASM_EXPORTS} -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]'
ld_emsdk_optimizations := -O2 -sSTRICT -flto -sUSE_SDL=0 -sEVAL_CTORS=1
cc_emsdk_settings := -DARCH_WASM -D'ARCH="WASM"'
cc_emsdk_optimizations := -O2 -sSTRICT -flto -fno-rtti -fno-exceptions
# lua_embed_opts := "compile"
ldflags += -lm ${ld_emsdk_optimizations} ${ld_emsdk_settings}
cflags += -DLIBCMALLOC ${cc_emsdk_settings} ${cc_emsdk_optimizations}

all: ${BUILD_DEPS} zenroom.js

zenroom.js: ${ZEN_SOURCES}
$(info === Linking Zenroom WASM for Javascript)
${cc} ${cflags} ${ZEN_SOURCES} \
-o $@ ${ldflags} ${ldadd}

include build/deps.mk
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"semantic-release": "^19.0.5"
},
"dependencies": {
"docsify-cli": "^4.4.4"
"docsify-cli": "^4.4.4",
"yarn": "^1.22.22"
}
}

0 comments on commit 84a33ff

Please sign in to comment.