Skip to content

Commit 3ce10ca

Browse files
authored
ci: cross-compiling to aarch64-unknown-linux-gnu on GitHub Actions (#894)
1 parent 789f559 commit 3ce10ca

File tree

3 files changed

+74
-24
lines changed

3 files changed

+74
-24
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ jobs:
3838
- os: windows-2019
3939
emacs-version: '27.2'
4040
target: ""
41+
- os: ubuntu-20.04
42+
emacs-version: '28.2'
43+
# Cross build
44+
target: aarch64-unknown-linux-gnu
4145
- os: macos-13
4246
emacs-version: '28.2'
4347
# Cross build
@@ -47,6 +51,12 @@ jobs:
4751
- uses: actions/checkout@v4
4852
- run: .github/script/setup
4953

54+
# Cross build
55+
- uses: mlugg/setup-zig@v1
56+
if: matrix.target == 'aarch64-unknown-linux-gnu'
57+
with:
58+
version: 0.13.0
59+
5060
- uses: actions/setup-python@v4
5161
with:
5262
python-version: '3.10'

.github/workflows/release.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
emacs-version: '27.2'
3535
ext: so
3636
host: x86_64-unknown-linux-gnu
37+
- os: ubuntu-20.04
38+
bundle_os: linux
39+
emacs-version: '27.2'
40+
ext: so
41+
target: aarch64-unknown-linux-gnu
3742
- os: windows-2019
3843
bundle_os: windows
3944
emacs-version: '27.2'
@@ -44,6 +49,12 @@ jobs:
4449
- uses: actions/checkout@v4
4550
- run: .github/script/setup
4651

52+
# Cross build
53+
- uses: mlugg/setup-zig@v1
54+
if: matrix.target == 'aarch64-unknown-linux-gnu'
55+
with:
56+
version: 0.13.0
57+
4758
- uses: actions/setup-python@v4
4859
with:
4960
python-version: '3.10'

tree-sitter-langs-build.el

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ If VERSION and OS are not spcified, use the defaults of
282282
;; FIX: Implement this correctly, refactoring 'OS' -> 'platform'.
283283
(pcase os
284284
("windows" "x86_64-pc-windows-msvc")
285-
("linux" "x86_64-unknown-linux-gnu")
285+
("linux" (if (string-prefix-p "aarch64" system-configuration)
286+
"aarch64-unknown-linux-gnu"
287+
"x86_64-unknown-linux-gnu"))
286288
("freebsd" "x86_64-unknown-freebsd")
287289
("macos" (if (string-prefix-p "aarch64" system-configuration)
288290
"aarch64-apple-darwin"
@@ -314,6 +316,7 @@ from the current state of the grammar repo, without cleanup."
314316
(setq target
315317
(pcase (format "%s" target)
316318
;; Rust's triple -> system toolchain's triple
319+
("aarch64-unknown-linux-gnu" "aarch64-linux-gnu")
317320
("aarch64-apple-darwin" "arm64-apple-macos11")
318321
("nil" nil)
319322
(_ (error "Unsupported cross-compilation target %s" target))))
@@ -360,6 +363,55 @@ from the current state of the grammar repo, without cleanup."
360363
(default-directory (file-name-as-directory (concat dir path))))
361364
(tree-sitter-langs--call "tree-sitter" "generate")
362365
(cond
366+
(target (cond
367+
;; XXX: This is a hack for cross compilation on Linux.
368+
((string-suffix-p "-linux-gnu" target)
369+
(cond
370+
((file-exists-p "src/scanner.cc")
371+
(tree-sitter-langs--call
372+
"zig" "c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
373+
"-I" "src"
374+
"src/scanner.cc" "-xc" "src/parser.c"
375+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
376+
"-target" target))
377+
((file-exists-p "src/scanner.c")
378+
(tree-sitter-langs--call
379+
"zig" "cc" "-shared" "-fPIC" "-g" "-O2"
380+
"-I" "src"
381+
"src/scanner.c" "src/parser.c"
382+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
383+
"-target" target))
384+
(:default
385+
(tree-sitter-langs--call
386+
"zig" "cc" "-shared" "-fPIC" "-g" "-O2"
387+
"-I" "src"
388+
"src/parser.c"
389+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
390+
"-target" target))))
391+
;; XXX: This is a hack for cross compilation for Apple Silicon.
392+
((string-match-p "macos" target)
393+
(cond
394+
((file-exists-p "src/scanner.cc")
395+
(tree-sitter-langs--call
396+
"c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
397+
"-I" "src"
398+
"src/scanner.cc" "-xc" "src/parser.c"
399+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
400+
"-target" target))
401+
((file-exists-p "src/scanner.c")
402+
(tree-sitter-langs--call
403+
"cc" "-shared" "-fPIC" "-g" "-O2"
404+
"-I" "src"
405+
"src/scanner.c" "src/parser.c"
406+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
407+
"-target" target))
408+
(:default
409+
(tree-sitter-langs--call
410+
"cc" "-shared" "-fPIC" "-g" "-O2"
411+
"-I" "src"
412+
"src/parser.c"
413+
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
414+
"-target" target))))))
363415
((and (memq system-type '(gnu/linux))
364416
(file-exists-p "src/scanner.cc"))
365417
;; XXX: Modified from
@@ -370,29 +422,6 @@ from the current state of the grammar repo, without cleanup."
370422
"-I" "src"
371423
"src/scanner.cc" "-xc" "src/parser.c"
372424
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)))
373-
;; XXX: This is a hack for cross compilation (mainly for Apple Silicon).
374-
(target (cond
375-
((file-exists-p "src/scanner.cc")
376-
(tree-sitter-langs--call
377-
"c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
378-
"-I" "src"
379-
"src/scanner.cc" "-xc" "src/parser.c"
380-
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
381-
"-target" target))
382-
((file-exists-p "src/scanner.c")
383-
(tree-sitter-langs--call
384-
"cc" "-shared" "-fPIC" "-g" "-O2"
385-
"-I" "src"
386-
"src/scanner.c" "src/parser.c"
387-
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
388-
"-target" target))
389-
(:default
390-
(tree-sitter-langs--call
391-
"cc" "-shared" "-fPIC" "-g" "-O2"
392-
"-I" "src"
393-
"src/parser.c"
394-
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
395-
"-target" target))))
396425
((memq system-type '(berkeley-unix))
397426
(cond
398427
((file-exists-p "src/scanner.cc")

0 commit comments

Comments
 (0)