IndianBoy42 / tree-sitter-just

Treesitter grammar for Justfiles (casey/just)
Apache License 2.0
146 stars 26 forks source link

WASM target is not supported #174

Closed vitallium closed 1 month ago

vitallium commented 2 months ago

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 <vitaliy.slobodin@gmail.com>
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!

lvignoli commented 1 month ago

I get a different error when targeting WASM. On a fresh clone, at 6648ac1c0cdadaec8ee8bcf9a4ca6ace5102cf21, 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

tgross35 commented 1 month ago

I think this should be fixed by https://github.com/IndianBoy42/tree-sitter-just/pull/178, feel free to reopen if that isn't the case.