Skip to content

Commit

Permalink
ci: cross-compiling to aarch64-unknown-linux-gnu on GitHub Actions (#894
Browse files Browse the repository at this point in the history
)
  • Loading branch information
l2dy authored Dec 29, 2024
1 parent 789f559 commit 3ce10ca
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 24 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
- os: windows-2019
emacs-version: '27.2'
target: ""
- os: ubuntu-20.04
emacs-version: '28.2'
# Cross build
target: aarch64-unknown-linux-gnu
- os: macos-13
emacs-version: '28.2'
# Cross build
Expand All @@ -47,6 +51,12 @@ jobs:
- uses: actions/checkout@v4
- run: .github/script/setup

# Cross build
- uses: mlugg/setup-zig@v1
if: matrix.target == 'aarch64-unknown-linux-gnu'
with:
version: 0.13.0

- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
emacs-version: '27.2'
ext: so
host: x86_64-unknown-linux-gnu
- os: ubuntu-20.04
bundle_os: linux
emacs-version: '27.2'
ext: so
target: aarch64-unknown-linux-gnu
- os: windows-2019
bundle_os: windows
emacs-version: '27.2'
Expand All @@ -44,6 +49,12 @@ jobs:
- uses: actions/checkout@v4
- run: .github/script/setup

# Cross build
- uses: mlugg/setup-zig@v1
if: matrix.target == 'aarch64-unknown-linux-gnu'
with:
version: 0.13.0

- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand Down
77 changes: 53 additions & 24 deletions tree-sitter-langs-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ If VERSION and OS are not spcified, use the defaults of
;; FIX: Implement this correctly, refactoring 'OS' -> 'platform'.
(pcase os
("windows" "x86_64-pc-windows-msvc")
("linux" "x86_64-unknown-linux-gnu")
("linux" (if (string-prefix-p "aarch64" system-configuration)
"aarch64-unknown-linux-gnu"
"x86_64-unknown-linux-gnu"))
("freebsd" "x86_64-unknown-freebsd")
("macos" (if (string-prefix-p "aarch64" system-configuration)
"aarch64-apple-darwin"
Expand Down Expand Up @@ -314,6 +316,7 @@ from the current state of the grammar repo, without cleanup."
(setq target
(pcase (format "%s" target)
;; Rust's triple -> system toolchain's triple
("aarch64-unknown-linux-gnu" "aarch64-linux-gnu")
("aarch64-apple-darwin" "arm64-apple-macos11")
("nil" nil)
(_ (error "Unsupported cross-compilation target %s" target))))
Expand Down Expand Up @@ -360,6 +363,55 @@ from the current state of the grammar repo, without cleanup."
(default-directory (file-name-as-directory (concat dir path))))
(tree-sitter-langs--call "tree-sitter" "generate")
(cond
(target (cond
;; XXX: This is a hack for cross compilation on Linux.
((string-suffix-p "-linux-gnu" target)
(cond
((file-exists-p "src/scanner.cc")
(tree-sitter-langs--call
"zig" "c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
"-I" "src"
"src/scanner.cc" "-xc" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
((file-exists-p "src/scanner.c")
(tree-sitter-langs--call
"zig" "cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/scanner.c" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
(:default
(tree-sitter-langs--call
"zig" "cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))))
;; XXX: This is a hack for cross compilation for Apple Silicon.
((string-match-p "macos" target)
(cond
((file-exists-p "src/scanner.cc")
(tree-sitter-langs--call
"c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
"-I" "src"
"src/scanner.cc" "-xc" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
((file-exists-p "src/scanner.c")
(tree-sitter-langs--call
"cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/scanner.c" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
(:default
(tree-sitter-langs--call
"cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))))))
((and (memq system-type '(gnu/linux))
(file-exists-p "src/scanner.cc"))
;; XXX: Modified from
Expand All @@ -370,29 +422,6 @@ from the current state of the grammar repo, without cleanup."
"-I" "src"
"src/scanner.cc" "-xc" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)))
;; XXX: This is a hack for cross compilation (mainly for Apple Silicon).
(target (cond
((file-exists-p "src/scanner.cc")
(tree-sitter-langs--call
"c++" "-shared" "-fPIC" "-fno-exceptions" "-g" "-O2"
"-I" "src"
"src/scanner.cc" "-xc" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
((file-exists-p "src/scanner.c")
(tree-sitter-langs--call
"cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/scanner.c" "src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))
(:default
(tree-sitter-langs--call
"cc" "-shared" "-fPIC" "-g" "-O2"
"-I" "src"
"src/parser.c"
"-o" (format "%sbin/%s.so" tree-sitter-langs-grammar-dir lang-symbol)
"-target" target))))
((memq system-type '(berkeley-unix))
(cond
((file-exists-p "src/scanner.cc")
Expand Down

0 comments on commit 3ce10ca

Please sign in to comment.