Skip to content

Commit 5b71ac2

Browse files
committed
build: Add support for amd64 and arm64 Linux builds.
Handle Linux architecture-specific library files in language()
1 parent f5993e4 commit 5b71ac2

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM --platform=linux/amd64 debian:12-slim
1+
FROM debian:12-slim
22

33
ARG LIBRARY_NAME=tree-sitter-cedarscript
44

55
# Install necessary dependencies
66
RUN apt-get update && apt-get >/dev/null install -y \
7-
build-essential git curl mingw-w64 \
7+
build-essential git curl mingw-w64 gcc-x86-64-linux-gnu \
88
&& rm -rf /var/lib/apt/lists/*
99

1010
# Install Node.js and npm
@@ -23,8 +23,13 @@ COPY grammar.js .
2323

2424
# Generate and build the parser
2525
RUN tree-sitter generate -l -b && mkdir lib && \
26-
cc -c -I./src src/parser.c && \
27-
cc -shared -o lib/lib$LIBRARY_NAME.so parser.o && \
26+
# AMD64 Linux build
27+
x86_64-linux-gnu-gcc -c -I./src src/parser.c -o parser_amd64.o && \
28+
x86_64-linux-gnu-gcc -shared -o lib/lib$LIBRARY_NAME.amd64.so parser_amd64.o && \
29+
# ARM64 Linux build
30+
gcc -c -I./src src/parser.c -o parser_arm64.o && \
31+
gcc -shared -o lib/lib$LIBRARY_NAME.arm64.so parser_arm64.o && \
32+
# Windows build
2833
x86_64-w64-mingw32-gcc -c -I./src src/parser.c && \
2934
x86_64-w64-mingw32-gcc -shared -o lib/lib$LIBRARY_NAME.dll parser.o && \
3035
apt-get >/dev/null purge 2>&1 -y --auto-remove build-essential git curl \

build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ ts test || { playground; exit 1 ;}
4343
rm -f "$TARGET_DIR"/lib"$LIBRARY_NAME".* "$GRAMMAR_DIR"/lib"$LIBRARY_NAME".*
4444

4545
# Linux and Windows compilation using Docker
46-
BUILDKIT_PROGRESS=plain docker buildx build --platform linux/amd64 \
46+
BUILDKIT_PROGRESS=plain docker buildx build \
4747
-t "$LIBRARY_NAME"-builder --build-arg LIBRARY_NAME="$LIBRARY_NAME" --load . || exit
4848
container_id=$(docker create "$LIBRARY_NAME"-builder) || exit
4949
# Copy both Linux and Windows libraries from the single container
50-
docker cp "$container_id:/out/lib/lib${LIBRARY_NAME}.so" "$GRAMMAR_DIR/" && \
50+
docker cp "$container_id:/out/lib/lib${LIBRARY_NAME}.amd64.so" "$GRAMMAR_DIR/" && \
51+
docker cp "$container_id:/out/lib/lib${LIBRARY_NAME}.arm64.so" "$GRAMMAR_DIR/" && \
5152
docker cp "$container_id:/out/lib/lib${LIBRARY_NAME}.dll" "$GRAMMAR_DIR/" && \
5253
docker rm "$container_id" > /dev/null || exit
5354

src/cedarscript_grammar/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ def language() -> Language:
3030
case x if x.startswith('darwin'):
3131
libext = 'dylib'
3232
case x if x.startswith('linux'):
33-
libext = 'so'
33+
arch = platform.machine().lower()
34+
if arch == 'x86_64':
35+
libext = 'amd64.so'
36+
elif arch in ('aarch64', 'arm64'):
37+
libext = 'arm64.so'
38+
else:
39+
raise OSError(f"Unsupported Linux architecture: {arch}")
3440
case x if x.startswith('win'):
3541
libext = 'dll'
3642
case _ as invalid:

0 commit comments

Comments
 (0)