Compare commits

..

12 Commits

Author SHA1 Message Date
github-actions[bot]
f7b2baa363 chore(master): release 0.6.56 (#128)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-03 03:23:24 +00:00
d396165808 fix(patches): improve chance of successful patch application by using -l
This causes patch to ignore whitespace changes, which should make it
more likely to apply patches which may not be an exact match.
2024-12-03 03:21:31 +00:00
66ccd9c6fd feat(options): add --patch option which accepts file path or URL (#127)
This allows users to easily apply custom patches from a file on disk, or
from a URL. It's particularly hady to quickly test out a changeset from
a GitHub commit/diff or elsewhere.
2024-12-03 03:14:14 +00:00
github-actions[bot]
907f7babbc chore(master): release 0.6.55 (#126)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-03 00:19:59 +00:00
e030fee670 feat(nix/deps): update nixpkgs from 24.11-beta to 24.11 2024-12-03 00:18:35 +00:00
github-actions[bot]
0ea0596f69 chore(master): release 0.6.54 (#125)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-01 12:37:14 +00:00
03ed54ca78 feat(startup): replace bundled site-start.el approach with a custom source patch (#124)
Because we bundle libgccjit and gcc libraries, as well as C sources into
the Emacs .app bundle itself, some extra setup is required during
startup of Emacs to ensure that native compliation works, and C sources
are found when needed.

Previously this was done by adding a custom site-start.el file to the
Emacs.app bundle, which was loaded at startup. This approach had some
issues, namely that when launching Emacs with `-Q` or `--no-site-file`,
the file was not loaded, preventing native compilation from working.

Here we replace the site-start.el approach with a custom patch adding
macos-startup.el, which adds a hook to `after-pdump-load-hook`. This
ensures that the startup code is always run, and before any user
configuration is loaded.
2024-12-01 12:35:42 +00:00
github-actions[bot]
9d98b6340b chore(master): release 0.6.53 (#123)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-01 03:51:49 +00:00
cbac633efb docs(readme): update with current status and nix environment details 2024-12-01 03:50:56 +00:00
db723817bf fix(help): correct formatting of help text output 2024-12-01 03:50:55 +00:00
github-actions[bot]
509d8bf0b8 chore(master): release 0.6.52 (#122)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-11-30 22:11:44 +00:00
d7723ee766 fix(nix/flake): rename flake-package-versions.txt to flake.pkgs 2024-11-30 22:10:50 +00:00
8 changed files with 459 additions and 300 deletions

View File

@@ -1,3 +1,3 @@
{
".": "0.6.51"
".": "0.6.56"
}

View File

@@ -1,5 +1,45 @@
# 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)
### Bug Fixes
* **help:** correct formatting of help text output ([db72381](https://github.com/jimeh/build-emacs-for-macos/commit/db723817bf6c0ac85da1790a1d50fbea774cc0c0))
## [0.6.52](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.51...v0.6.52) (2024-11-30)
### Bug Fixes
* **nix/flake:** rename flake-package-versions.txt to flake.pkgs ([d7723ee](https://github.com/jimeh/build-emacs-for-macos/commit/d7723ee766574b6597997de7c54fb7ed7f37965c))
## [0.6.51](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.50...v0.6.51) (2024-11-28)

View File

@@ -137,7 +137,7 @@ gen:
.PHONY: nix-flake-update
nix-flake-update:
nix flake update \
&& $(MAKE) flake-package-versions.txt
&& $(MAKE) flake.pkgs
.SILENT: flake-package-versions
flake-package-versions:
@@ -146,8 +146,8 @@ flake-package-versions:
$$(echo $$PATH | tr ":" "\n" | grep "/nix/store" | sort -u) \
| jq -r ".[].name" | sort -u'
flake-package-versions.txt: flake.nix flake.lock
$(MAKE) flake-package-versions > flake-package-versions.txt
flake.pkgs: flake.nix flake.lock
$(MAKE) flake-package-versions > "$@"
#
# Dependencies

View File

@@ -73,23 +73,26 @@ make bootstrap
## Status
As of writing (2023-11-20) it works for me on my machine and for the nightly
As of writing (2024-11-30) it works for me on my machine and for the nightly
builds in [jimeh/emacs-builds](https://github.com/jimeh/emacs-builds). Your luck
may vary.
I have successfully built:
- `emacs-29.1` release tag.
- `master` branch (Emacs 30.x).
- `emacs-29.4` release tag.
- `emacs-30.0.92` pretest tag.
- `master` branch (Emacs 31.x).
For reference, my machine is:
- 14-inch MacBook Pro (2023), Apple M3 Pro (11-cores)
- macOS Sonoma 14.1.1 (23B2082)
- Xcode 15.0.1 (15A507)
- 14-inch MacBook Pro (2023), Apple M3 Max (16-cores)
- macOS Sonoma 15.1.1 (24B91)
- Xcode 16.1 (16B40)
Nightly builds are built with GitHub Actions on GitHub-hosted runners, using
`macos-12` for Intel builds, and `macos-13-xlarge` for Apple Silicon builds.
The [nightly builds](https://github.com/jimeh/emacs-builds) are built with
GitHub Actions on GitHub-hosted runners, using `macos-13` for Intel builds, and
`macos-14` for Apple Silicon builds. The build environment is managed with Nix,
and targets the macOS 11 SDK.
## Usage
@@ -105,6 +108,11 @@ Or you can run the build script via `nix develop`:
nix develop --command ./build-emacs-for-macos --help
```
The Nix environment defaults to targeting the macOS 11 SDK, which makes Emacs
builds compatible with macOS 11.3 or later. You can easily target later macOS
SDKs. Versions 11 to 15 are available. For example, to target the macOS 12 SDK,
run `nix develop .#macos12`
### Homebrew
Run `make boostrap` to ensure all Ruby and Homebrew dependencies are installed.
@@ -126,7 +134,10 @@ Options:
--[no-]xwidgets Enable/disable XWidgets if supported (default: enabled)
--[no-]tree-sitter Enable/disable tree-sitter if supported (default: enabled)
--[no-]native-comp Enable/disable native-comp (default: enabled if supported)
--[no-]native-march Enable/disable -march=native CFLAG(default: disabled)
--optimize Shorthand for --native-march --native-mtune --fomit-frame-pointer (default: disabled)
--[no-]native-march Enable/disable -march=native CFLAG (default: disabled)
--[no-]native-mtune Enable/disable -mtune=native CFLAG (default: disabled)
--[no-]fomit-frame-pointer Enable/disable -fomit-frame-pointer CFLAG (default: disabled)
--[no-]native-full-aot Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation (default: disabled)
--[no-]relink-eln-files Enable/disable re-linking shared libraries in bundled *.eln files (default: enabled)
--[no-]rsvg Enable/disable SVG image support via librsvg (default: enabled)
@@ -135,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)
@@ -168,10 +180,10 @@ as of writing) and build Emacs.app from it:
./build-emacs-for-macos
```
To build the stable `emacs-29.1` release git tag run:
To build the stable `emacs-29.4` release git tag run:
```
./build-emacs-for-macos emacs-29.1
./build-emacs-for-macos emacs-29.4
```
All sources as downloaded as tarballs from the

View File

@@ -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
View File

@@ -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"
}

View File

@@ -2,7 +2,7 @@
description = "Development environment flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.11-beta";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};