Skip to content

Commit

Permalink
cmake wasm projects
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Dec 23, 2023
1 parent 252af39 commit 1027083
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build**/
upstream**/
**/dist/
**/cmake-build**/

# build cache files
**/*.idx
Expand Down
30 changes: 30 additions & 0 deletions tooling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# set minimum cmake version
cmake_minimum_required(VERSION 3.26)

# set project name
project(wasmtools)

# set c++ standard
set(CMAKE_CXX_STANDARD 20)

# set output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

include_directories(${CMAKE_SOURCE_DIR}/wasm-utils)

file(GLOB WASM_UTILS_SRC ${CMAKE_SOURCE_DIR}/wasm-utils/*.cpp)
file(GLOB WASM_UTILS_HEADERS ${CMAKE_SOURCE_DIR}/wasm-utils/*.hpp)
file(GLOB WASM_TRANSFORM_SRC ${CMAKE_SOURCE_DIR}/wasm-transform/*.cpp)
file(GLOB WASM_PACKAGE_SRC ${CMAKE_SOURCE_DIR}/wasm-package/*.cpp)

include_directories(${CMAKE_SOURCE_DIR}/wasm-utils)

# set linker flags if EMSCRIPTEN
if(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=_main,_free,_malloc -s EXPORTED_RUNTIME_METHODS=FS,PROXYFS,ERRNO_CODES,allocateUTF8 -lproxyfs.js --js-library=${CMAKE_SOURCE_DIR}/../emlib/fsroot.js -lidbfs.js -flto -O3")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -O3")
endif()

add_executable(wasm-transform ${WASM_TRANSFORM_SRC} ${WASM_UTILS_SRC} ${WASM_UTILS_HEADERS})
add_executable(wasm-package ${WASM_PACKAGE_SRC} ${WASM_UTILS_SRC} ${WASM_UTILS_HEADERS})
6 changes: 5 additions & 1 deletion tooling/wasm-package/wasm-package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ int main(int argc, const char *argv[]) {
if (lstat(name, &status) == 0) {
buffer.write<std::string_view>(name);
buffer.write<std::uint64_t>(status.st_mode);
#if defined(__APPLE__)
buffer.write<std::uint64_t>(status.st_atimespec.tv_sec);
buffer.write<std::uint64_t>(status.st_mtimespec.tv_sec);
#else
buffer.write<std::uint64_t>(status.st_atim.tv_sec);
buffer.write<std::uint64_t>(status.st_mtim.tv_sec);

#endif
switch (status.st_mode & S_IFMT) {
case S_IFREG: // normal file
buffer.write(readFile(name));
Expand Down

0 comments on commit 1027083

Please sign in to comment.