Skip to content

Commit

Permalink
adjust build commands to emscripten's new defaults since v2.0.3, to c…
Browse files Browse the repository at this point in the history
…hoose between two options in PR
  • Loading branch information
jmarcosfer committed Jan 7, 2024
1 parent 794d4d1 commit eb83a1d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Makefile.essentiajs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ build:
@echo "Compiling the emscripten embind cpp bindings to bitcode ..."

@emcc -v -I $(EIGEN_PATH) -I $(INCLUDE_DIR_ESSENTIA)\
-lessentia -L ${LIB_DIR_ESSENTIA} \
--bind -Oz $(BINDING_ESSENTIAJS) $(INCLUDE_ESSENTIAJS) \
-o $(BUILD_DIR_ES)/essentiajs.bc \
-s EXCEPTION_DEBUG \
-s ASSERTIONS=2 \
-s DISABLE_EXCEPTION_CATCHING=2 || exit 1
-s DISABLE_EXCEPTION_CATCHING=2 \
-o $(BUILD_DIR_ES)/bindings_essentiajs.o \
-c $(BINDING_ESSENTIAJS) || exit 1

@emcc -v -I $(EIGEN_PATH) -I $(INCLUDE_DIR_ESSENTIA)\
-s DISABLE_EXCEPTION_CATCHING=2 \
-o $(BUILD_DIR_ES)/essentiajs.o \
-c $(INCLUDE_ESSENTIAJS) || exit 1
@echo "Done ..."

@echo "Linking and compiling the bindings with essentia to js, wasm files ..."
@echo "compiling async builds..."
@emcc --bind -Oz $(BUILD_DIR_ES)/essentiajs.bc ${LIB_DIR_ESSENTIA}/essentia.a \
-s WASM=1 \
@emcc -lembind -Oz $(BUILD_DIR_ES)/bindings_essentiajs.o $(BUILD_DIR_ES)/essentiajs.o ${LIB_DIR_ESSENTIA}/libessentia.a \
-L $(LIB_DIR_ESSENTIA) \
-s WASM=1 \
-o $(ESSENTIA_JS_WEB) \
-s EXCEPTION_DEBUG \
-s ASSERTIONS=2 \
Expand All @@ -54,7 +57,8 @@ build:
@echo "Done ..."

@echo "compiling sync builds..."
@emcc --bind -Oz $(BUILD_DIR_ES)/essentiajs.bc ${LIB_DIR_ESSENTIA}/essentia.a \
@emcc --bind -Oz $(BUILD_DIR_ES)/bindings_essentiajs.o $(BUILD_DIR_ES)/essentiajs.o ${LIB_DIR_ESSENTIA}/libessentia.a \
-L $(LIB_DIR_ESSENTIA) \
-s WASM=1 \
-o $(ESSENTIA_JS_MODULE) \
-s BINARYEN_ASYNC_COMPILATION=0 \
Expand All @@ -81,7 +85,7 @@ build:
@echo "Done ..."

@echo "Removing unnecessary files ..."
@rm $(BUILD_DIR_ES)/essentiajs.bc
@rm $(BUILD_DIR_ES)/essentiajs.o $(BUILD_DIR_ES)/bindings_essentiajs.o

@echo "Builds ..."
@ls $(BUILD_DIR_ES)
Expand Down
81 changes: 81 additions & 0 deletions Makefile2.essentiajs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
ESSENTIAJS_VERSION=0.1.3
## Path to libs for Emscripten
LIB_DIR_ESSENTIA=$(EMSCRIPTEN)/system/local/lib
INCLUDE_DIR_ESSENTIA=$(EMSCRIPTEN)/system/local/include
EIGEN_PATH=/usr/local/include/eigen3
## Pass custom build and dist directories using system environment variables
BUILD_DIR_ES := $(or $(ESSENTIAJS_WASM_BUILDS_DIR),builds)
DIST_DIR_ES := $(or $(ESSENTIAJS_BUILDS_DIR),dist)
## C++ source code for Essentia.js
BINDING_ESSENTIAJS=src/cpp/bindings_essentiajs.cpp
INCLUDE_ESSENTIAJS=src/cpp/includes/essentiajs.cpp
## Define builds
ESSENTIA_JS_WEB=$(BUILD_DIR_ES)/essentia-wasm.web.js
ESSENTIA_JS_WEB_WASM=$(BUILD_DIR_ES)/essentia-wasm.web.wasm
ESSENTIA_JS_MODULE=$(BUILD_DIR_ES)/essentia-wasm.module.js
ESSENTIA_WASM_UMD_MODULE=$(BUILD_DIR_ES)/essentia-wasm.umd.js
ESSENTIA_WASM_ES6_MODULE=$(BUILD_DIR_ES)/essentia-wasm.es.js
## Path to custom --pre-js and --post-js files for Emscripten
PRE_JS_WASM=src/js/wasm.module.pre.js
POST_JS_WEB_WASM=src/js/wasm.webmodule.post.js
POST_JS_ES6_WASM=src/js/wasm.es6module.post.js
POST_JS_UMD_WASM=src/js/wasm.umd.post.js

codegen:
@echo "Generating cpp source code from essentia python bindings ..."
@cd src/python && python3 configure_bindings.py

build:
@mkdir -p $(BUILD_DIR_ES)

@echo "Compiling + linking emscripten embind cpp bindings directly to js, wasm files ..."

@echo "... compiling async builds..."
@emcc -lembind -Oz $(BINDING_ESSENTIAJS) $(INCLUDE_ESSENTIAJS) ${LIB_DIR_ESSENTIA}/libessentia.a \
-L $(LIB_DIR_ESSENTIA) \
-I $(EIGEN_PATH) -I $(INCLUDE_DIR_ESSENTIA)\
-s WASM=1 \
-o $(ESSENTIA_JS_WEB) \
-s EXCEPTION_DEBUG \
-s ASSERTIONS=2 \
-s ENVIRONMENT=web \
-s MODULARIZE=1 \
-s EXPORT_NAME="EssentiaWASM" \
--post-js $(POST_JS_WEB_WASM) \
-s ALLOW_MEMORY_GROWTH=1 || exit 1
@echo "Done ..."

@echo "... compiling sync builds..."
@emcc --bind -Oz $(BINDING_ESSENTIAJS) $(INCLUDE_ESSENTIAJS) ${LIB_DIR_ESSENTIA}/libessentia.a \
-L $(LIB_DIR_ESSENTIA) \
-I $(EIGEN_PATH) -I $(INCLUDE_DIR_ESSENTIA)\
-s WASM=1 \
-o $(ESSENTIA_JS_MODULE) \
-s BINARYEN_ASYNC_COMPILATION=0 \
-s ALLOW_MEMORY_GROWTH=1 \
-s SINGLE_FILE=1 || exit 1

@cat $(PRE_JS_WASM) $(ESSENTIA_JS_WEB) > $$.tmp && mv $$.tmp $(ESSENTIA_JS_WEB)
@cat $(PRE_JS_WASM) $(ESSENTIA_JS_MODULE) > $$.tmp && mv $$.tmp $(ESSENTIA_JS_MODULE)

@cp -f $(ESSENTIA_JS_MODULE) $(ESSENTIA_WASM_ES6_MODULE)
@cat $(POST_JS_ES6_WASM) >> $(ESSENTIA_WASM_ES6_MODULE)

@cp -f $(ESSENTIA_JS_MODULE) $(ESSENTIA_WASM_UMD_MODULE)
@cat $(POST_JS_UMD_WASM) >> $(ESSENTIA_WASM_UMD_MODULE)

@rm -f $(ESSENTIA_JS_MODULE)

@mkdir -p $(DIST_DIR_ES)
@cp -f $(ESSENTIA_JS_WEB) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_JS_WEB_WASM) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_WASM_UMD_MODULE) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_WASM_ES6_MODULE) $(DIST_DIR_ES)/

@echo "Done ..."

@echo "Builds ..."
@ls $(BUILD_DIR_ES)

clean:
@rm -rf $(BUILD_DIR_ES)

0 comments on commit eb83a1d

Please sign in to comment.