@@ -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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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 " %s bin/%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