Skip to content

Commit

Permalink
Fix cmake dependency on wasm-intrinsics.wat (WebAssembly#6206)
Browse files Browse the repository at this point in the history
I think this is a nicer/better way to do WebAssembly#6204.
  • Loading branch information
sbc100 committed Jan 6, 2024
1 parent c3b2f24 commit 82057de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/passes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
file(READ wasm-intrinsics.wat WASM_INTRINSICS_WAT HEX)
set(CMAKE_CONFIGURE_DEPENDS wasm-intrinsics.wat)

string(REGEX MATCHALL "([A-Fa-f0-9][A-Fa-f0-9])" SEPARATED_HEX ${WASM_INTRINSICS_WAT})

# WASM_INTRINSICS_EMBED_2 and WASM_INTRINSICS_SIZE_2 should be renamed each time
# the content of the wat file changes. This is not strictly necessary, as CMake
# should use the fresh contents each time, but even just re-running CMake
# manually is not enough in practice (one needs to also erase the CMake temp
# files, or use a fresh build dir). Renaming the vars keeps things working
# smoothly for people with existing checkouts.
set(WASM_INTRINSICS_SIZE_2 1)
foreach (hex IN LISTS SEPARATED_HEX)
string(APPEND WASM_INTRINSICS_EMBED_2 "0x${hex},")
math(EXPR WASM_INTRINSICS_SIZE_2 "${WASM_INTRINSICS_SIZE_2}+1")
string(APPEND WASM_INTRINSICS_EMBED "0x${hex},")
endforeach ()
string(APPEND WASM_INTRINSICS_EMBED_2 "0x00")
string(APPEND WASM_INTRINSICS_EMBED "0x00")

configure_file(WasmIntrinsics.cpp.in WasmIntrinsics.cpp @ONLY)

Expand Down
4 changes: 2 additions & 2 deletions src/passes/WasmIntrinsics.cpp.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "passes/intrinsics-module.h"

static const char theModule[@WASM_INTRINSICS_SIZE_2@] = {
@WASM_INTRINSICS_EMBED_2@
static const char theModule[] = {
@WASM_INTRINSICS_EMBED@
};

namespace wasm {
Expand Down

0 comments on commit 82057de

Please sign in to comment.