Skip to content

Commit 8ec2ff6

Browse files
committed
Add VS2026 support and WASM binaries
1 parent 5141851 commit 8ec2ff6

File tree

7 files changed

+875
-1
lines changed

7 files changed

+875
-1
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,39 @@ parser_config.fsharp = {
5252
The `package.json` defines some helpful targets for developing the grammar:
5353

5454
- `npm run generate` rebuilds all parser.
55+
- `npm run build:wasm` builds WASM modules for both parsers (requires Docker or Emscripten).
56+
- `npm run build:wasm:fsharp` builds only the fsharp WASM module.
57+
- `npm run build:wasm:signature` builds only the fsharp_signature WASM module.
5558
- `npx tree-sitter test` runs all tests for both parsers.
5659
- `npx tree-sitter parse $file` run the `fsharp` parser on `$file` and outputs the parse tree.
5760
- `npx tree-sitter parse -d $file` run the `fsharp` parser on `$file` and prints debug information.
5861

62+
### Building WASM
63+
64+
To build WebAssembly modules, you need either Docker or Emscripten installed:
65+
66+
**Option 1: Using Docker (recommended)**
67+
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
68+
2. Start Docker Desktop
69+
3. Run `npm run build:wasm`
70+
71+
**Option 2: Using Emscripten**
72+
1. Install the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html)
73+
2. Activate Emscripten in your terminal
74+
3. Run `npm run build:wasm`
75+
76+
**Option 3: Using WSL (Windows)**
77+
The repository includes `build-wasm.sh` which can be run with WSL:
78+
```bash
79+
wsl bash build-wasm.sh
80+
```
81+
82+
This will generate WASM files in the wasm/ directory:
83+
- `wasm/tree-sitter-fsharp.wasm` - Main F# grammar
84+
- `wasm/tree-sitter-fsharp_signature.wasm` - F# signature (.fsi) grammar
85+
86+
**Note**: WASM files are included in the repository for convenience.
87+
5988
## How to contribute
6089

6190
Clone the project and start playing around with it.

build-wasm.bat

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@echo off
2+
REM Build WASM files for tree-sitter-fsharp
3+
4+
if not exist wasm mkdir wasm
5+
6+
echo Building WASM for fsharp grammar...
7+
cd fsharp
8+
call npx tree-sitter build --wasm
9+
if errorlevel 1 (
10+
echo Failed to build fsharp WASM
11+
cd ..
12+
exit /b 1
13+
)
14+
move /Y tree-sitter-fsharp.wasm ..\wasm\ >nul 2>&1
15+
cd ..
16+
17+
echo Building WASM for fsharp_signature grammar...
18+
cd fsharp_signature
19+
call npx tree-sitter build --wasm
20+
if errorlevel 1 (
21+
echo Failed to build fsharp_signature WASM
22+
cd ..
23+
exit /b 1
24+
)
25+
move /Y tree-sitter-fsharp_signature.wasm ..\wasm\ >nul 2>&1
26+
cd ..
27+
28+
echo.
29+
echo WASM files built successfully in wasm\ directory:
30+
if exist wasm\tree-sitter-fsharp.wasm (
31+
echo - wasm\tree-sitter-fsharp.wasm
32+
)
33+
if exist wasm\tree-sitter-fsharp_signature.wasm (
34+
echo - wasm\tree-sitter-fsharp_signature.wasm
35+
)
36+
echo.

build-wasm.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Build WASM files for tree-sitter-fsharp
3+
# This script can be run with WSL on Windows or natively on Linux/macOS
4+
5+
set -e
6+
7+
# Check if tree-sitter is available
8+
if ! command -v tree-sitter &> /dev/null; then
9+
echo "Error: tree-sitter CLI not found"
10+
echo "Please install it with: cargo install tree-sitter-cli"
11+
echo "Or download from: https://github.com/tree-sitter/tree-sitter/releases"
12+
exit 1
13+
fi
14+
15+
# Setup Emscripten if available
16+
if [ -f "/tmp/emsdk/emsdk_env.sh" ]; then
17+
export EMSDK_QUIET=1
18+
source /tmp/emsdk/emsdk_env.sh
19+
fi
20+
21+
# Create wasm directory if it doesn't exist
22+
mkdir -p wasm
23+
24+
echo "Building WASM for fsharp grammar..."
25+
cd fsharp
26+
tree-sitter build --wasm
27+
mv -f tree-sitter-fsharp.wasm ../wasm/ 2>/dev/null || true
28+
cd ..
29+
30+
echo "Building WASM for fsharp_signature grammar..."
31+
cd fsharp_signature
32+
tree-sitter build --wasm
33+
mv -f tree-sitter-fsharp_signature.wasm ../wasm/ 2>/dev/null || true
34+
cd ..
35+
36+
echo ""
37+
echo "WASM files built successfully in wasm/ directory:"
38+
if [ -f wasm/tree-sitter-fsharp.wasm ]; then
39+
ls -lh wasm/tree-sitter-fsharp.wasm | awk '{print " - wasm/tree-sitter-fsharp.wasm (" $5 ")"}'
40+
fi
41+
if [ -f wasm/tree-sitter-fsharp_signature.wasm ]; then
42+
ls -lh wasm/tree-sitter-fsharp_signature.wasm | awk '{print " - wasm/tree-sitter-fsharp_signature.wasm (" $5 ")"}'
43+
fi
44+
echo ""

0 commit comments

Comments
 (0)