Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tsc-dyn-get to download platform-specific binaries #206

Merged
merged 1 commit into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
- Added customization option `tsc-dyn-get-from`, which is a list of sources to get the dynamic module `tsc-dyn` from. Its default value is `(:github :compilation)`.
- Made `tree-sitter-hl`'s region-fontification function fall back to the underlying non-tree-sitter function when called outside of `tree-sitter-hl-mode`. This fixes an issue where `jupyter-repl-mode`'s [input cells are not highlighted](https://github.com/nnicandro/emacs-jupyter/issues/363).
- Updated `tsc-dyn-get` to download platform-specific binaries (mainly for Apple Silicon).

## [0.16.1] - 2021-12-11
- Modified CI pipelines to publish additional pre-built dynamic modules. Their filenames include the platform they are built for. The files without platform in name will eventually be deprecated.
Expand Down
34 changes: 25 additions & 9 deletions core/tsc-dyn-get.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,20 @@ this to nil."
(_ "so")))

(defun tsc-dyn-get--file ()
"Return the dynamic module filename, which is system-dependent."
"Return the dynamic module filename, which is OS-dependent."
(format "tsc-dyn.%s" (tsc-dyn-get--ext)))

;;; TODO: Make this correct.
(defun tsc-dyn-get--system-specific-file ()
"Return the dynamic module filename, which is system-dependent."
(pcase system-type
('windows-nt "tsc-dyn.x86_64-pc-windows-msvc.dll")
('darwin (if (string-prefix-p "x86_64" system-configuration)
"tsc-dyn.x86_64-apple-darwin.dylib"
"tsc-dyn.aarch64-apple-darwin.dylib"))
((or 'gnu 'gnu/linux 'gnu/kfreebsd)
"tsc-dyn.x86_64-unknown-linux-gnu.so")))

(defun tsc-dyn-get--log (format-string &rest args)
(apply #'message (concat "tsc-dyn-get: " format-string) args))

Expand Down Expand Up @@ -123,19 +134,24 @@ This function records the downloaded version in the manifest
(let* ((bin-dir (tsc-dyn-get--dir))
(default-directory bin-dir)
(_ (unless (file-directory-p bin-dir) (make-directory bin-dir)))
(dyn-file (tsc-dyn-get--file))
(gz-file (format "%s.gz" dyn-file))
(uncompressed? (version< "0.7.0" version))
(system-specific? (version<= "0.16.1" version))
(local-name (tsc-dyn-get--file))
(remote-name (format "%s%s"
(if system-specific?
(tsc-dyn-get--system-specific-file)
local-name)
(if uncompressed? "" ".gz")))
(url (format "https://github.com/emacs-tree-sitter/elisp-tree-sitter/releases/download/%s/%s"
version (if uncompressed? dyn-file gz-file))))
version remote-name)))
(tsc-dyn-get--log "Downloading %s" url)
(if uncompressed?
(tsc-dyn-get--url-copy-file url dyn-file :ok-if-already-exists)
(tsc-dyn-get--url-copy-file url gz-file)
(when (file-exists-p dyn-file)
(delete-file dyn-file))
(tsc-dyn-get--url-copy-file url local-name :ok-if-already-exists)
(tsc-dyn-get--url-copy-file url remote-name)
(when (file-exists-p local-name)
(delete-file local-name))
;; XXX: Uncompressing with `dired-compress-file' doesn't work on Windows.
(dired-compress-file gz-file))
(dired-compress-file remote-name))
(with-temp-file tsc-dyn-get--version-file
(let ((coding-system-for-write 'utf-8))
(insert version)))))
Expand Down