Skip to content

Commit

Permalink
scanner: disable printing for WASM
Browse files Browse the repository at this point in the history
WASM builds does not expose symbols for printing. As such, settle for
simply crashing.

Also add WASM build step to CI to verify that it can be built.
  • Loading branch information
alaviss committed Jul 11, 2024
1 parent bb2f809 commit 506ba35
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,34 @@ jobs:
with:
command: build

wasm:
needs: [generate]
runs-on: ubuntu-latest
name: Run WASM test build
steps:
- uses: actions/checkout@v4
- name: Download generated parser
uses: actions/download-artifact@v4
with:
name: parser
path: src/
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
cache: "npm"
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Run test build
run: npx tree-sitter build --wasm

success:
needs:
- compare-parser
- generate
- tests
- rust
- wasm
if: always()
runs-on: ubuntu-latest
name: "All checks passed"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ target/
*.so
*.pc
*.a
*.wasm
22 changes: 15 additions & 7 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ static bool debug_mode = false; /* NOLINT(*-global-variables) */
static const bool debug_mode = false;
#endif

#define RUNTIME_ASSERT(cond) \
if (!(cond)) { \
(void)fprintf( \
stderr, "lex_nim: %s():%d: Assertion `%s' failed.\n", __func__, \
__LINE__, #cond); \
abort(); \
}
#ifndef __wasm__
# define RUNTIME_ASSERT(cond) \
if (!(cond)) { \
(void)fprintf( \
stderr, "lex_nim: %s():%d: Assertion `%s' failed.\n", __func__, \
__LINE__, #cond); \
abort(); \
}
#else
// WASM doesn't have printing enabled
# define RUNTIME_ASSERT(cond) \
if (!(cond)) { \
abort(); \
}
#endif

#define MIN(left, right) ((left) > (right) ? (right) : (left))
#define MAX(left, right) ((left) < (right) ? (right) : (left))
Expand Down

0 comments on commit 506ba35

Please sign in to comment.