Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of the WASM build #474

Merged
merged 3 commits into from
Nov 29, 2024
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
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_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like quite random fix, how did you find this bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It simply does not compile. Maybe it has something to do with the emscripten that is used for the build (but the counter_ is indeed not present there, it is a real error).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really weird, maybe the function is never used, so the compiler removes it? But it should still not compile normally, weird.

}

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
Loading