Skip to content

Commit

Permalink
close #19 : add cmake option for single-file wasm build
Browse files Browse the repository at this point in the history
If enabled, we build ggwave using "-s SINGLE_FILE=1" which causes
the WASM to be embedded inside the .js file.

Otherwise, 2 separate files are produced:
- libggwave.js
- libggwave.wasm
  • Loading branch information
ggerganov committed Feb 20, 2021
1 parent 580090c commit d373294
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ endif()
if (EMSCRIPTEN)
set(GGWAVE_SUPPORT_SDL2_DEFAULT ON)
set(BUILD_SHARED_LIBS_DEFAULT OFF)

option(GGWAVE_WASM_SINGLE_FILE "ggwave: embed WASM inside the generated ggwave.js" ON)
else()
set(GGWAVE_SUPPORT_SDL2_DEFAULT ON)
set(BUILD_SHARED_LIBS_DEFAULT ON)
Expand Down
22 changes: 14 additions & 8 deletions bindings/javascript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ target_link_libraries(${TARGET} PRIVATE
ggwave
)

unset(EXTRA_FLAGS)
if (GGWAVE_WASM_SINGLE_FILE)
set(EXTRA_FLAGS "-s SINGLE_FILE=1")
message(STATUS "Embedding WASM inside ggwave.js")

add_custom_command(
TARGET libggwave POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/bin/libggwave.js
${CMAKE_CURRENT_SOURCE_DIR}/ggwave.js
)
endif()

set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
--bind \
-s MODULARIZE=1 \
-s SINGLE_FILE=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s EXPORT_NAME=\"'ggwave_factory'\" \
${EXTRA_FLAGS} \
")

add_custom_command(
TARGET libggwave POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/bin/libggwave.js
${CMAKE_CURRENT_SOURCE_DIR}/ggwave.js
)
2 changes: 1 addition & 1 deletion bindings/javascript/ggwave.js

Large diffs are not rendered by default.

0 comments on commit d373294

Please sign in to comment.