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

WASM target is not supported #174

Closed
vitallium opened this issue Sep 5, 2024 · 2 comments
Closed

WASM target is not supported #174

vitallium opened this issue Sep 5, 2024 · 2 comments

Comments

@vitallium
Copy link

Hey! First of all, thanks for creating this grammar for Justfiles. I have a small issue when I tried to compile the grammar for the WASM target via WASI SDK:

Failed to instantiate wasm module: invalid import 'fprintf'

According to WASI SDK outputting to stdio/stderr is not supported. To avoid that error one can use preprocessor macro to disable printing if the target is WASM:

From 828a0021e66ac2a953b8a58f01ae5ed1c404f4ef Mon Sep 17 00:00:00 2001
From: Vitaly Slobodin <[email protected]>
Date: Tue, 3 Sep 2024 22:02:27 +0200
Subject: [PATCH] Disable debugging statements for the WASM target

---
 src/scanner.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/scanner.c b/src/scanner.c
index 57611c8..2f05b37 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -22,6 +22,10 @@
 #define unused_attr
 #endif
 
+#ifdef __wasm__
+#define assertf(...) (void)0;
+#else
+
 #ifndef fprintf_s
 #define fprintf_s fprintf // NOLINT
 #endif
@@ -55,6 +59,8 @@
 #define __builtin_expect(a, b) a
 #endif
 
+#endif
+
 #define SBYTES sizeof(Scanner)
 
 enum TokenType {
-- 
2.46.0

0001-Disable-debugging-statements-for-the-WASM-target.patch

I think you can replicate that by using the WASI SDK Docker image like this:

docker run -v (pwd):/src -w /src ghcr.io/webassembly/wasi-sdk make

And then instantiating the WASM module.

I wonder if you could provide WASM support for the Justfile grammar? That would be really appreciated. Thanks!

tommy added a commit to tommy/tree-sitter-just that referenced this issue Sep 5, 2024
@lvignoli
Copy link
Contributor

lvignoli commented Sep 23, 2024

I get a different error when targeting WASM.
On a fresh clone, at 6648ac1, building for WASM outputs

This external scanner uses a symbol that isn't available to wasm parsers.

Missing symbols:
    fiprintf
    fwrite
    fputc
    exit
    stderr

Available symbols:
    calloc
    free
    iswalnum
    iswalpha
    iswblank
    iswdigit
    iswlower
    iswspace
    iswupper
    iswxdigit
    malloc
    memchr
    memcmp
    memcpy
    memmove
    memset
    realloc
    strcmp
    strlen
    strncat
    strncmp
    strncpy
    towlower
    towupper

@tommy's fix f676df8 does not help :/

Specs:
Apple M1 Pro on macOS 14.4.1.
tree-sitter 0.23.0
emcc 3.1.67-git

@lvignoli lvignoli mentioned this issue Oct 12, 2024
@tgross35
Copy link
Collaborator

I think this should be fixed by #178, feel free to reopen if that isn't the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants