Skip to content

Commit

Permalink
Merge pull request #474 from VeriFIT/wasm-build
Browse files Browse the repository at this point in the history
Support of the WASM build #patch
  • Loading branch information
Adda0 authored Nov 29, 2024
2 parents e953d8c + 190224c commit 96a7bc2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 3rdparty/simlib/include/mata/simlib/util/shared_list.hh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public:
}

if (elem)
--elem->counter_;
--elem->refcount_;
}

template <class Deleter>
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
option(MATA_WERROR "Warnings should be handled as errors" OFF)
option(MATA_ENABLE_COVERAGE "Build with coverage compiler flags" OFF)

# For the case of WASM build we need to add -pthread option
if (EMSCRIPTEN)
add_compile_options(-pthread)
endif()

# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Store compile commands into 'build/compile_commands.json', which are needed, beside others, for linters.
Expand Down
9 changes: 9 additions & 0 deletions README-WASM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Building Mata to WASM

In order to build Mata library to WASM, you need to have `emscripten` set up, along with all of its dependencies.
You can use the system packages or consult [emsdk](https://github.com/emscripten-core/emsdk).
For building Mata to WASM then use the following steps:

1. create folder `build-wasm` for the WASM build of libmata.a
2. in `build-wasm` run `emcmake cmake -DBUILD_TYPE=Release -DMATA_BUILD_EXAMPLES:BOOL=OFF -DBUILD_TESTING:BOOL=OFF ..`
3. build the library using `emmake make` (the WASM static library `src/libmata.a` should be created after that)
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ set_target_properties(libmata PROPERTIES

target_include_directories(libmata PUBLIC "${PROJECT_SOURCE_DIR}/include/")

# For the case of WASM build we need to link with pthread
if (EMSCRIPTEN)
target_link_libraries(libmata PRIVATE pthread)
endif()

target_link_libraries(libmata PUBLIC cudd simlib)
target_link_libraries(libmata PRIVATE re2)

Expand Down

0 comments on commit 96a7bc2

Please sign in to comment.