mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 13:06:38 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7b2baa363 | ||
|
d396165808
|
|||
| 66ccd9c6fd | |||
|
|
907f7babbc | ||
|
e030fee670
|
|||
|
|
0ea0596f69 | ||
| 03ed54ca78 |
2
.github/.release-please-manifest.json
vendored
2
.github/.release-please-manifest.json
vendored
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "0.6.53"
|
||||
".": "0.6.56"
|
||||
}
|
||||
|
||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -1,5 +1,31 @@
|
||||
# Changelog
|
||||
|
||||
## [0.6.56](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.55...v0.6.56) (2024-12-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **options:** add --patch option which accepts file path or URL ([#127](https://github.com/jimeh/build-emacs-for-macos/issues/127)) ([66ccd9c](https://github.com/jimeh/build-emacs-for-macos/commit/66ccd9c6fd077d558eae484cdbab831486fbfd58))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **patches:** improve chance of successful patch application by using -l ([d396165](https://github.com/jimeh/build-emacs-for-macos/commit/d396165808ab5852566e7ff6bcc23d47ddfdfdee))
|
||||
|
||||
## [0.6.55](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.54...v0.6.55) (2024-12-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **nix/deps:** update nixpkgs from 24.11-beta to 24.11 ([e030fee](https://github.com/jimeh/build-emacs-for-macos/commit/e030fee6704618b7ddefea7424dff4e94f43e84d))
|
||||
|
||||
## [0.6.54](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.53...v0.6.54) (2024-12-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **startup:** replace bundled site-start.el approach with a custom source patch ([#124](https://github.com/jimeh/build-emacs-for-macos/issues/124)) ([03ed54c](https://github.com/jimeh/build-emacs-for-macos/commit/03ed54ca78ce15b61f5c875f97410b3ff21ecd62))
|
||||
|
||||
## [0.6.53](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.52...v0.6.53) (2024-12-01)
|
||||
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ Options:
|
||||
--posix-spawn Apply posix-spawn patch (deprecated)
|
||||
--no-frame-refocus Apply no-frame-refocus patch (default: disabled)
|
||||
--[no-]poll Apply poll patch (deprecated)
|
||||
-p, --patch=URL Specify a custom patch file or URL to apply to the Emacs source (can be used multiple times)
|
||||
--[no-]fd-setsize SIZE Set an file descriptor (max open files) limit (default: 10000)
|
||||
--github-src-repo REPO Specify a GitHub repo to download source tarballs from (default: emacs-mirror/emacs)
|
||||
--[no-]github-auth Make authenticated GitHub API requests if GITHUB_TOKEN environment variable is set.(default: enabled)
|
||||
|
||||
@@ -79,6 +79,16 @@ module Output
|
||||
end
|
||||
end
|
||||
|
||||
module Helpers
|
||||
def valid_url?(uri)
|
||||
uri = URI.parse(uri)
|
||||
(uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)) &&
|
||||
uri.host.respond_to?(:empty?) && !uri.host.empty?
|
||||
rescue URI::InvalidURIError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
module System
|
||||
include Output
|
||||
|
||||
@@ -183,6 +193,7 @@ end
|
||||
class Build
|
||||
include Output
|
||||
include System
|
||||
include Helpers
|
||||
|
||||
DEFAULT_GITHUB_REPO = 'emacs-mirror/emacs'
|
||||
|
||||
@@ -408,6 +419,7 @@ class Build
|
||||
fatal 'Tarball extraction failed.' unless result
|
||||
|
||||
patches.each { |patch| apply_patch(patch, target) }
|
||||
apply_macos_startup_patch(target)
|
||||
|
||||
# Keep a copy of src after patches have been applied. This will be used to
|
||||
# embed C sources into the output Emacs.app bundle.
|
||||
@@ -900,6 +912,93 @@ class Build
|
||||
File.write(filename, content)
|
||||
end
|
||||
|
||||
MACOS_STARTUP_EL_CONTENT = <<~ELISP
|
||||
;;; macos-startup.el --- macOS specific startup actions -*- lexical-binding: t -*-
|
||||
|
||||
;; Maintainer: Jim Myhrberg <contact@jimeh.me>
|
||||
;; Keywords: macos, internal
|
||||
;; Homepage: https://github.com/jimeh/build-emacs-for-macos
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file contains macOS specific startup actions for self-contained
|
||||
;; macOS *.app bundles. It enables native-compilation via a bundled
|
||||
;; libgccjit, and for bundled C-sources to be found for documentation
|
||||
;; purposes,
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun macos-startup--in-app-bundle-p ()
|
||||
"Check if invoked from a macOS .app bundle."
|
||||
(and (eq system-type 'darwin)
|
||||
invocation-directory
|
||||
(string-match-p ".+\\.app/Contents/MacOS/?$" invocation-directory)))
|
||||
|
||||
(defun macos-startup--set-source-directory ()
|
||||
"Set `source-directory' so that C-sources can be located."
|
||||
(let* ((src-dir (expand-file-name "../Resources/src" invocation-directory)))
|
||||
(when (file-directory-p src-dir)
|
||||
(setq source-directory (file-name-directory src-dir)))))
|
||||
|
||||
(defun macos-startup--setup-library-path ()
|
||||
"Configure LIBRARY_PATH env var for native compilation on macOS.
|
||||
|
||||
Ensures LIBRARY_PATH includes paths to the libgccjit and gcc libraries
|
||||
which are bundled into the .app bundle. This allows native compilation
|
||||
to work without any external system dependencies aside from Xcode."
|
||||
(let* ((new-paths
|
||||
(list (expand-file-name "../Frameworks/gcc/lib" invocation-directory)
|
||||
(expand-file-name "../Frameworks/gcc/lib/apple-darwin" invocation-directory)
|
||||
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"))
|
||||
(valid-paths (delq nil (mapcar (lambda (path)
|
||||
(when (file-directory-p path)
|
||||
path))
|
||||
new-paths)))
|
||||
(existing-paths (split-string (or (getenv "LIBRARY_PATH") "") ":" t))
|
||||
(unique-paths (delete-dups (append valid-paths existing-paths))))
|
||||
|
||||
(when unique-paths
|
||||
(setenv "LIBRARY_PATH" (mapconcat 'identity unique-paths path-separator)))))
|
||||
|
||||
(defun macos-startup--init ()
|
||||
"Perform macOS specific startup operations."
|
||||
(when (macos-startup--in-app-bundle-p)
|
||||
(macos-startup--set-source-directory)
|
||||
(when (and (fboundp 'native-comp-available-p)
|
||||
(native-comp-available-p))
|
||||
(macos-startup--setup-library-path))))
|
||||
|
||||
(add-hook 'after-pdump-load-hook #'macos-startup--init)
|
||||
|
||||
;;; macos-startup.el ends here
|
||||
ELISP
|
||||
|
||||
def apply_macos_startup_patch(target)
|
||||
macos_startup_el = File.join(target, 'lisp', 'macos-startup.el')
|
||||
|
||||
unless File.exist?(macos_startup_el)
|
||||
info 'Adding macos-startup.el to lisp sources...'
|
||||
FileUtils.mkdir_p(File.dirname(macos_startup_el))
|
||||
File.write(macos_startup_el, MACOS_STARTUP_EL_CONTENT)
|
||||
end
|
||||
|
||||
loadup_el = File.join(target, 'lisp', 'loadup.el')
|
||||
loadup_content = File.read(loadup_el)
|
||||
|
||||
return if loadup_content.include?('(load "macos-startup")')
|
||||
|
||||
info 'Patching loadup.el to load macos-startup.el...'
|
||||
File.write(
|
||||
loadup_el,
|
||||
loadup_content.gsub(
|
||||
'(load "startup")',
|
||||
"(load \"startup\")\n(load \"macos-startup\")"
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def meta
|
||||
return @meta if @meta
|
||||
|
||||
@@ -1038,6 +1137,20 @@ class Build
|
||||
}
|
||||
end
|
||||
|
||||
# Custom patches.
|
||||
options[:patches].each do |patch_str|
|
||||
patch = {}
|
||||
if valid_url?(patch_str)
|
||||
patch[:url] = patch_str
|
||||
elsif File.exist?(patch_str)
|
||||
patch[:file] = patch_str
|
||||
else
|
||||
fatal "Patch file or URL not found: #{patch_str}"
|
||||
end
|
||||
|
||||
p << patch
|
||||
end
|
||||
|
||||
p.uniq
|
||||
end
|
||||
|
||||
@@ -1046,7 +1159,9 @@ class Build
|
||||
|
||||
if patch[:file]
|
||||
info 'Applying patch...'
|
||||
FileUtils.cd(target) { run_cmd('patch', '-f', '-p1', '-i', patch[:file]) }
|
||||
FileUtils.cd(target) do
|
||||
run_cmd('patch', '-f', '-p1', '-l', '-i', patch[:file])
|
||||
end
|
||||
elsif patch[:url]
|
||||
patch_dir = "#{target}/macos_patches"
|
||||
run_cmd('mkdir', '-p', patch_dir)
|
||||
@@ -1068,6 +1183,20 @@ class Build
|
||||
else
|
||||
apply_patch({ file: patch_file }, target)
|
||||
end
|
||||
elsif patch[:source]
|
||||
patch_dir = "#{target}/macos_patches"
|
||||
run_cmd('mkdir', '-p', patch_dir)
|
||||
|
||||
patch_file = File.join(patch_dir, 'patch-{num}.diff')
|
||||
num = 1
|
||||
while File.exist?(patch_file.gsub('{num}', num.to_s.rjust(3, '0')))
|
||||
num += 1
|
||||
end
|
||||
patch_file = patch_file.gsub('{num}', num.to_s.rjust(3, '0'))
|
||||
|
||||
File.write(patch_file, patch[:source])
|
||||
|
||||
apply_patch({ file: patch_file }, target)
|
||||
elsif patch[:replace]
|
||||
fatal 'Patch replace input error' unless patch[:replace].size == 3
|
||||
|
||||
@@ -1198,12 +1327,6 @@ class CLIHelperEmbedder < AbstractEmbedder
|
||||
end
|
||||
|
||||
class CSourcesEmbedder < AbstractEmbedder
|
||||
PATH_PATCH = <<~ELISP
|
||||
;; Allow Emacs to find bundled C sources.
|
||||
(setq source-directory
|
||||
(expand-file-name ".." (file-name-directory load-file-name)))
|
||||
ELISP
|
||||
|
||||
attr_reader :source_dir
|
||||
|
||||
def initialize(app, source_dir)
|
||||
@@ -1228,15 +1351,6 @@ class CSourcesEmbedder < AbstractEmbedder
|
||||
src_dir, target_dir, File.join('**', '*.{awk,c,cc,h,in,m,mk}')
|
||||
)
|
||||
end
|
||||
|
||||
if File.exist?(site_start_el_file) &&
|
||||
File.read(site_start_el_file).include?(PATH_PATCH)
|
||||
return
|
||||
end
|
||||
|
||||
debug "Patching '#{relative_app_path(site_start_el_file)}' to allow " \
|
||||
'Emacs to find bundled C sources'
|
||||
File.open(site_start_el_file, 'a') { |f| f.puts("\n#{PATH_PATCH}") }
|
||||
end
|
||||
|
||||
private
|
||||
@@ -1252,10 +1366,6 @@ class CSourcesEmbedder < AbstractEmbedder
|
||||
run_cmd('cp', '-pRL', f, target)
|
||||
end
|
||||
end
|
||||
|
||||
def site_start_el_file
|
||||
@site_start_el_file ||= File.join(resources_dir, 'lisp', 'site-start.el')
|
||||
end
|
||||
end
|
||||
|
||||
class LibEmbedder < AbstractEmbedder
|
||||
@@ -1521,49 +1631,13 @@ class GccLibEmbedder < AbstractEmbedder
|
||||
|
||||
FileUtils.rm(Dir[File.join(target_dir, '**', '.DS_Store')], force: true)
|
||||
|
||||
if target_darwin_dir != sanitized_target_darwin_dir
|
||||
run_cmd('mv', target_darwin_dir, sanitized_target_darwin_dir)
|
||||
end
|
||||
return unless target_darwin_dir != sanitized_target_darwin_dir
|
||||
|
||||
env_setup = ERB.new(NATIVE_COMP_ENV_VAR_TPL).result(gcc_info.get_binding)
|
||||
if File.exist?(site_start_el_file) &&
|
||||
File.read(site_start_el_file).include?(env_setup)
|
||||
return
|
||||
end
|
||||
|
||||
debug 'Setting up site-start.el for self-contained native-comp Emacs.app'
|
||||
File.open(site_start_el_file, 'a') { |f| f.puts("\n#{env_setup}") }
|
||||
run_cmd('mv', target_darwin_dir, sanitized_target_darwin_dir)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
NATIVE_COMP_ENV_VAR_TPL = <<~ELISP
|
||||
;; Set LIBRARY_PATH to point at bundled GCC and Xcode Command Line Tools to
|
||||
;; ensure native-comp works.
|
||||
(when (and (eq system-type 'darwin)
|
||||
(string-match-p "\\.app\\/Contents\\/MacOS\\/?$"
|
||||
invocation-directory))
|
||||
(let* ((library-path-env (getenv "LIBRARY_PATH"))
|
||||
(devtools-dir
|
||||
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib")
|
||||
(gcc-dir (expand-file-name
|
||||
"<%= app_bundle_target_lib_dir %>"
|
||||
invocation-directory))
|
||||
(darwin-dir (expand-file-name
|
||||
"<%= app_bundle_target_darwin_lib_dir %>"
|
||||
invocation-directory))
|
||||
(lib-paths (list)))
|
||||
|
||||
(if library-path-env
|
||||
(push library-path-env lib-paths))
|
||||
(if (file-directory-p devtools-dir)
|
||||
(push devtools-dir lib-paths))
|
||||
(push darwin-dir lib-paths)
|
||||
(push gcc-dir lib-paths)
|
||||
|
||||
(setenv "LIBRARY_PATH" (mapconcat 'identity lib-paths ":"))))
|
||||
ELISP
|
||||
|
||||
# Remove all rpaths from Mach-O library files except for @loader_path.
|
||||
def tidy_lib_rpaths(directory)
|
||||
Dir[File.join(directory, '**', '*.{dylib,so}')].each do |file_path|
|
||||
@@ -1607,10 +1681,6 @@ class GccLibEmbedder < AbstractEmbedder
|
||||
def source_darwin_dir
|
||||
gcc_info.darwin_lib_dir
|
||||
end
|
||||
|
||||
def site_start_el_file
|
||||
@site_start_el_file ||= File.join(resources_dir, 'lisp', 'site-start.el')
|
||||
end
|
||||
end
|
||||
|
||||
class GccInfo
|
||||
@@ -1784,228 +1854,265 @@ class GccInfo
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
use_nix_default = !ENV.fetch('IN_NIX_SHELL', '').empty?
|
||||
class CLIOptions
|
||||
include Output
|
||||
include Helpers
|
||||
|
||||
cli_options = {
|
||||
work_dir: File.expand_path(__dir__),
|
||||
native_full_aot: false,
|
||||
relink_eln: true,
|
||||
native_march: false,
|
||||
parallel: Etc.nprocessors,
|
||||
rsvg: true,
|
||||
dbus: true,
|
||||
use_nix: use_nix_default,
|
||||
xwidgets: true,
|
||||
tree_sitter: true,
|
||||
fd_setsize: 10_000,
|
||||
github_src_repo: nil,
|
||||
github_auth: true,
|
||||
dist_include: ['COPYING', 'configure_output.txt'],
|
||||
self_sign: true,
|
||||
archive: true,
|
||||
archive_keep: false,
|
||||
log_level: 'info'
|
||||
}
|
||||
|
||||
parser = OptionParser.new do |opts|
|
||||
opts.banner = <<~DOC
|
||||
Usage: ./build-emacs-for-macos [options] <branch/tag/sha>
|
||||
|
||||
Branch, tag, and SHA are from the emacs-mirror/emacs/emacs Github repo,
|
||||
available here: https://github.com/emacs-mirror/emacs
|
||||
|
||||
Options:
|
||||
DOC
|
||||
|
||||
opts.on(
|
||||
'--info',
|
||||
'Print environment info and detected library paths, then exit'
|
||||
) { |v| cli_options[:info] = v }
|
||||
|
||||
opts.on(
|
||||
'--preview',
|
||||
'Print preview details about build and exit.'
|
||||
) { |v| cli_options[:preview] = v }
|
||||
|
||||
opts.on(
|
||||
'-j',
|
||||
'--parallel COUNT',
|
||||
'Compile using COUNT parallel processes ' \
|
||||
"(detected: #{cli_options[:parallel]})"
|
||||
) { |v| cli_options[:parallel] = v }
|
||||
|
||||
opts.on(
|
||||
'--git-sha SHA',
|
||||
'Override detected git SHA of specified ' \
|
||||
'branch allowing builds of old commits'
|
||||
) { |v| cli_options[:git_sha] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]use-nix',
|
||||
'Use Nix instead of Homebrew to find dependencies ' \
|
||||
'(default: enabled if IN_NIX_SHELL is set)'
|
||||
) { |v| cli_options[:use_nix] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]xwidgets',
|
||||
'Enable/disable XWidgets if supported ' \
|
||||
'(default: enabled)'
|
||||
) { |v| cli_options[:xwidgets] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]tree-sitter',
|
||||
'Enable/disable tree-sitter if supported ' \
|
||||
'(default: enabled)'
|
||||
) { |v| cli_options[:tree_sitter] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-comp',
|
||||
'Enable/disable native-comp ' \
|
||||
'(default: enabled if supported)'
|
||||
) { |v| cli_options[:native_comp] = v }
|
||||
|
||||
opts.on(
|
||||
'--optimize',
|
||||
'Shorthand for --native-march --native-mtune --fomit-frame-pointer ' \
|
||||
'(default: disabled)'
|
||||
) do
|
||||
cli_options[:native_march] = true
|
||||
cli_options[:native_mtune] = true
|
||||
cli_options[:fomit_frame_pointer] = true
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-march',
|
||||
'Enable/disable -march=native CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| cli_options[:native_march] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-mtune',
|
||||
'Enable/disable -mtune=native CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| cli_options[:native_mtune] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]fomit-frame-pointer',
|
||||
'Enable/disable -fomit-frame-pointer CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| cli_options[:fomit_frame_pointer] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-full-aot',
|
||||
'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \
|
||||
'(default: disabled)'
|
||||
) { |v| cli_options[:native_full_aot] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]relink-eln-files',
|
||||
'Enable/disable re-linking shared libraries in bundled *.eln ' \
|
||||
'files (default: enabled)'
|
||||
) { |v| cli_options[:relink_eln] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]rsvg',
|
||||
'Enable/disable SVG image support via librsvg ' \
|
||||
'(default: enabled)'
|
||||
) { |v| cli_options[:rsvg] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]dbus',
|
||||
'Enable/disable dbus support (default: enabled)'
|
||||
) { |v| cli_options[:dbus] = v }
|
||||
|
||||
opts.on(
|
||||
'--no-titlebar',
|
||||
'Apply no-titlebar patch (default: disabled)'
|
||||
) { cli_options[:no_titlebar] = true }
|
||||
|
||||
opts.on('--posix-spawn', 'Apply posix-spawn patch (deprecated)') do
|
||||
warn '==> WARN: posix-spawn patch is deprecated and has no effect.'
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--no-frame-refocus',
|
||||
'Apply no-frame-refocus patch (default: disabled)'
|
||||
) { cli_options[:no_frame_refocus] = true }
|
||||
|
||||
opts.on('--[no-]poll', 'Apply poll patch (deprecated)') do
|
||||
warn '==> WARN: poll patch is deprecated and has no effect.'
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--[no-]fd-setsize SIZE',
|
||||
'Set an file descriptor (max open files) limit (default: 10000)'
|
||||
) { |v| cli_options[:fd_setsize] = v.respond_to?(:to_i) ? v.to_i : 0 }
|
||||
|
||||
opts.on(
|
||||
'--github-src-repo REPO',
|
||||
'Specify a GitHub repo to download source tarballs from ' \
|
||||
'(default: emacs-mirror/emacs)'
|
||||
) { |v| cli_options[:github_src_repo] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]github-auth',
|
||||
'Make authenticated GitHub API requests if GITHUB_TOKEN ' \
|
||||
'environment variable is set.' \
|
||||
'(default: enabled)'
|
||||
) { |v| cli_options[:github_auth] = v }
|
||||
|
||||
opts.on(
|
||||
'--work-dir DIR',
|
||||
'Specify a working directory where tarballs, sources, and ' \
|
||||
'builds will be stored and worked with'
|
||||
) { |v| cli_options[:work_dir] = v }
|
||||
|
||||
opts.on(
|
||||
'-o DIR',
|
||||
'--output DIR',
|
||||
'Output directory for finished builds ' \
|
||||
'(default: <work-dir>/builds)'
|
||||
) { |v| cli_options[:output] = v }
|
||||
|
||||
opts.on('--build-name NAME', 'Override generated build name') do |v|
|
||||
cli_options[:build_name] = v
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--dist-include x,y,z',
|
||||
'List of extra files to copy from Emacs source into build ' \
|
||||
'folder/archive (default: COPYING)'
|
||||
) { |v| cli_options[:dist_include] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]self-sign',
|
||||
'Enable/disable self-signing of Emacs.app (default: enabled)'
|
||||
) { |v| cli_options[:self_sign] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]archive',
|
||||
'Enable/disable creating *.tbz archive (default: enabled)'
|
||||
) { |v| cli_options[:archive] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]archive-keep-build-dir',
|
||||
'Enable/disable keeping source folder for archive ' \
|
||||
'(default: disabled)'
|
||||
) { |v| cli_options[:archive_keep] = v }
|
||||
|
||||
opts.on(
|
||||
'--log-level LEVEL',
|
||||
'Build script log level (default: info)'
|
||||
) { |v| cli_options[:log_level] = v }
|
||||
|
||||
opts.on(
|
||||
'--plan FILE',
|
||||
'Follow given plan file, instead of using given git ref/sha'
|
||||
) { |v| cli_options[:plan] = v }
|
||||
def self.parse(args)
|
||||
inst = new
|
||||
inst.parse!(args)
|
||||
inst.options
|
||||
end
|
||||
|
||||
begin
|
||||
parser.parse!
|
||||
def parse!(args)
|
||||
parser.parse!(args)
|
||||
rescue OptionParser::InvalidOption => e
|
||||
fatal e.message
|
||||
end
|
||||
|
||||
Output.log_level = cli_options[:log_level]
|
||||
def options
|
||||
@options ||= defaults.dup.tap do |o|
|
||||
o.each { |k, v| o[k] = v.dup if v.is_a?(Array) }
|
||||
end
|
||||
end
|
||||
|
||||
def defaults
|
||||
{
|
||||
work_dir: File.expand_path(__dir__),
|
||||
native_full_aot: false,
|
||||
relink_eln: true,
|
||||
native_march: false,
|
||||
parallel: Etc.nprocessors,
|
||||
rsvg: true,
|
||||
dbus: true,
|
||||
use_nix: !ENV.fetch('IN_NIX_SHELL', '').empty?,
|
||||
xwidgets: true,
|
||||
tree_sitter: true,
|
||||
fd_setsize: 10_000,
|
||||
github_src_repo: nil,
|
||||
github_auth: true,
|
||||
dist_include: ['COPYING', 'configure_output.txt'],
|
||||
self_sign: true,
|
||||
archive: true,
|
||||
archive_keep: false,
|
||||
patches: [],
|
||||
log_level: 'info'
|
||||
}
|
||||
end
|
||||
|
||||
def parser
|
||||
@parser ||= OptionParser.new do |opts|
|
||||
opts.banner = <<~DOC
|
||||
Usage: ./build-emacs-for-macos [options] <branch/tag/sha>
|
||||
|
||||
Branch, tag, and SHA are from the emacs-mirror/emacs/emacs Github repo,
|
||||
available here: https://github.com/emacs-mirror/emacs
|
||||
|
||||
Options:
|
||||
DOC
|
||||
|
||||
opts.on(
|
||||
'--info',
|
||||
'Print environment info and detected library paths, then exit'
|
||||
) { |v| options[:info] = v }
|
||||
|
||||
opts.on(
|
||||
'--preview',
|
||||
'Print preview details about build and exit.'
|
||||
) { |v| options[:preview] = v }
|
||||
|
||||
opts.on(
|
||||
'-j',
|
||||
'--parallel COUNT',
|
||||
'Compile using COUNT parallel processes ' \
|
||||
"(detected: #{options[:parallel]})"
|
||||
) { |v| options[:parallel] = v }
|
||||
|
||||
opts.on(
|
||||
'--git-sha SHA',
|
||||
'Override detected git SHA of specified ' \
|
||||
'branch allowing builds of old commits'
|
||||
) { |v| options[:git_sha] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]use-nix',
|
||||
'Use Nix instead of Homebrew to find dependencies ' \
|
||||
'(default: enabled if IN_NIX_SHELL is set)'
|
||||
) { |v| options[:use_nix] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]xwidgets',
|
||||
'Enable/disable XWidgets if supported ' \
|
||||
'(default: enabled)'
|
||||
) { |v| options[:xwidgets] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]tree-sitter',
|
||||
'Enable/disable tree-sitter if supported ' \
|
||||
'(default: enabled)'
|
||||
) { |v| options[:tree_sitter] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-comp',
|
||||
'Enable/disable native-comp ' \
|
||||
'(default: enabled if supported)'
|
||||
) { |v| options[:native_comp] = v }
|
||||
|
||||
opts.on(
|
||||
'--optimize',
|
||||
'Shorthand for --native-march --native-mtune --fomit-frame-pointer ' \
|
||||
'(default: disabled)'
|
||||
) do
|
||||
options[:native_march] = true
|
||||
options[:native_mtune] = true
|
||||
options[:fomit_frame_pointer] = true
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-march',
|
||||
'Enable/disable -march=native CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| options[:native_march] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-mtune',
|
||||
'Enable/disable -mtune=native CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| options[:native_mtune] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]fomit-frame-pointer',
|
||||
'Enable/disable -fomit-frame-pointer CFLAG ' \
|
||||
'(default: disabled)'
|
||||
) { |v| options[:fomit_frame_pointer] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]native-full-aot',
|
||||
'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \
|
||||
'(default: disabled)'
|
||||
) { |v| options[:native_full_aot] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]relink-eln-files',
|
||||
'Enable/disable re-linking shared libraries in bundled *.eln ' \
|
||||
'files (default: enabled)'
|
||||
) { |v| options[:relink_eln] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]rsvg',
|
||||
'Enable/disable SVG image support via librsvg ' \
|
||||
'(default: enabled)'
|
||||
) { |v| options[:rsvg] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]dbus',
|
||||
'Enable/disable dbus support (default: enabled)'
|
||||
) { |v| options[:dbus] = v }
|
||||
|
||||
opts.on(
|
||||
'--no-titlebar',
|
||||
'Apply no-titlebar patch (default: disabled)'
|
||||
) { options[:no_titlebar] = true }
|
||||
|
||||
opts.on('--posix-spawn', 'Apply posix-spawn patch (deprecated)') do
|
||||
warn '==> WARN: posix-spawn patch is deprecated and has no effect.'
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--no-frame-refocus',
|
||||
'Apply no-frame-refocus patch (default: disabled)'
|
||||
) { options[:no_frame_refocus] = true }
|
||||
|
||||
opts.on('--[no-]poll', 'Apply poll patch (deprecated)') do
|
||||
warn '==> WARN: poll patch is deprecated and has no effect.'
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'-p=URL', '--patch=URL',
|
||||
'Specify a custom patch file or URL to apply to the Emacs source ' \
|
||||
'(can be used multiple times)'
|
||||
) do |v|
|
||||
if !valid_url?(v) && !File.exist?(v)
|
||||
fatal "Patch is not a URL or file: #{v}"
|
||||
end
|
||||
options[:patches] << v
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--[no-]fd-setsize SIZE',
|
||||
'Set an file descriptor (max open files) limit (default: 10000)'
|
||||
) { |v| options[:fd_setsize] = v.respond_to?(:to_i) ? v.to_i : 0 }
|
||||
|
||||
opts.on(
|
||||
'--github-src-repo REPO',
|
||||
'Specify a GitHub repo to download source tarballs from ' \
|
||||
'(default: emacs-mirror/emacs)'
|
||||
) { |v| options[:github_src_repo] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]github-auth',
|
||||
'Make authenticated GitHub API requests if GITHUB_TOKEN ' \
|
||||
'environment variable is set.' \
|
||||
'(default: enabled)'
|
||||
) { |v| options[:github_auth] = v }
|
||||
|
||||
opts.on(
|
||||
'--work-dir DIR',
|
||||
'Specify a working directory where tarballs, sources, and ' \
|
||||
'builds will be stored and worked with'
|
||||
) { |v| options[:work_dir] = v }
|
||||
|
||||
opts.on(
|
||||
'-o DIR',
|
||||
'--output DIR',
|
||||
'Output directory for finished builds ' \
|
||||
'(default: <work-dir>/builds)'
|
||||
) { |v| options[:output] = v }
|
||||
|
||||
opts.on('--build-name NAME', 'Override generated build name') do |v|
|
||||
options[:build_name] = v
|
||||
end
|
||||
|
||||
opts.on(
|
||||
'--dist-include x,y,z',
|
||||
'List of extra files to copy from Emacs source into build ' \
|
||||
'folder/archive (default: COPYING)'
|
||||
) { |v| options[:dist_include] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]self-sign',
|
||||
'Enable/disable self-signing of Emacs.app (default: enabled)'
|
||||
) { |v| options[:self_sign] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]archive',
|
||||
'Enable/disable creating *.tbz archive (default: enabled)'
|
||||
) { |v| options[:archive] = v }
|
||||
|
||||
opts.on(
|
||||
'--[no-]archive-keep-build-dir',
|
||||
'Enable/disable keeping source folder for archive ' \
|
||||
'(default: disabled)'
|
||||
) { |v| options[:archive_keep] = v }
|
||||
|
||||
opts.on(
|
||||
'--log-level LEVEL',
|
||||
'Build script log level (default: info)'
|
||||
) { |v| options[:log_level] = v }
|
||||
|
||||
opts.on(
|
||||
'--plan FILE',
|
||||
'Follow given plan file, instead of using given git ref/sha'
|
||||
) { |v| options[:plan] = v }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
begin
|
||||
cli_options = CLIOptions.parse(ARGV)
|
||||
|
||||
Output.log_level = cli_options.delete(:log_level)
|
||||
work_dir = cli_options.delete(:work_dir)
|
||||
build = Build.new(work_dir, ARGV.shift, cli_options)
|
||||
|
||||
|
||||
8
flake.lock
generated
8
flake.lock
generated
@@ -20,16 +20,16 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1731603435,
|
||||
"narHash": "sha256-CqCX4JG7UiHvkrBTpYC3wcEurvbtTADLbo3Ns2CEoL8=",
|
||||
"lastModified": 1732981179,
|
||||
"narHash": "sha256-F7thesZPvAMSwjRu0K8uFshTk3ZZSNAsXTIFvXBT+34=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296",
|
||||
"rev": "62c435d93bf046a5396f3016472e8f7c8e2aed65",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "24.11-beta",
|
||||
"ref": "nixos-24.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user