From 0ab94da15309b04978982369bdfa17e03e9b6329 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 20 Sep 2020 14:05:37 +0100 Subject: [PATCH] feat(native_comp)!: add support for NATIVE_FULL_AOT, replacing NATIVE_FAST_BOOT The feature/native-comp branch no longer supports the use of the NATIVE_FAST_BOOT environment variable. It has been replaced by NATIVE_FULL_AOT (Ahead of Time compilation). As the new environment variable's value is opposite of the old one, it is disabled by default. Under the hood, the --[no-]native-full-aot option still sets the NATIVE_FAST_BOOT environment variable as needed to ensure it works as expected when producing builds against older commits, and also newer ones. BREAKING CHANGE: Deprecate `--[no-]native-fast-boot` option in favor of `--[no-]native-full-aot` --- README.md | 19 +++--- build-emacs-for-macos | 155 ++++++++++++++++++++++++------------------ 2 files changed, 98 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 92d68cd..d1ace73 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ For reference, my machine is: - 13-inch MacBook Pro (2020), 10th-gen 2.3 GHz Quad-Core Intel Core i7 (4c/8t) - macOS 10.15.6 (19G2021) -- Xcode 11.6 +- Xcode 11.7 ## Limitations @@ -71,15 +71,16 @@ available here: https://github.com/emacs-mirror/emacs Options: -j, --parallel COUNT Compile using COUNT parallel processes (detected: 8) --git-sha SHA Override detected git SHA of specified branch allowing builds of old commits - --[no-]xwidgets Enable/disable XWidgets (default: enabled) + --[no-]xwidgets Enable/disable XWidgets (default: enabled if supported) --[no-]native-comp Enable/disable native-comp (default: enabled if supported) - --[no-]native-fast-boot Enable/disable NATIVE_FAST_BOOT (default: enabled if native-comp supported) + --[no-]native-full-aot Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation (default: disabled) --[no-]native-comp-macos-fixes Enable/disable fix based on feature/native-comp-macos-fixes branch (default: enabled if native-comp supported) --[no-]launcher Enable/disable embedded launcher script (default: enabled if native-comp is enabled) --rsvg Enable SVG image support via librsvg, can yield a unstable build (default: disabled) --no-titlebar Apply no-titlebar patch (default: disabled) --no-frame-refocus Apply no-frame-refocus patch (default: disabled) + --[no-]native-fast-boot DEPRECATED: use --[no-]native-full-aot instead ``` Resulting applications are saved to the `builds` directory in a bzip2 compressed @@ -138,13 +139,13 @@ And finally to build a Emacs.app with native compilation enabled, run: ./build-emacs-for-macos feature/native-comp ``` -By default `NATIVE_FAST_BOOT` is enabled which ensures a fast build by native +By default `NATIVE_FULL_AOT` is disabled which ensures a fast build by native compiling as few lisp source files as possible to build the app. Any remaining lisp files will be dynamically compiled in the background the first time you use them. -On my machine it takes around 10-15 minutes to build Emacs.app with -`NATIVE_FAST_BOOT` enabled. With it disabled it takes around 25 minutes. +On my machine it takes around 10 minutes to build Emacs.app with +`NATIVE_FULL_AOT` disabled. With it enabled it takes around 20-25 minutes. ### Configuration @@ -169,14 +170,16 @@ said directory which have a file size of zero bytes: ```elisp (when (boundp 'comp-eln-load-path) - (let ((eln-cache-dir (expand-file-name "cache/eln-cache/" user-emacs-directory)) + (let ((eln-cache-dir (expand-file-name "cache/eln-cache/" + user-emacs-directory)) (find-exec (executable-find "find"))) (setcar comp-eln-load-path eln-cache-dir) ;; Quitting emacs while native compilation in progress can leave zero byte ;; sized *.eln files behind. Hence delete such files during startup. (when find-exec (call-process find-exec nil nil nil eln-cache-dir - "-name" "*.eln" "-size" "0" "-delete")))) + "-name" "*.eln" "-size" "0" "-delete" "-or" + "-name" "*.eln.tmp" "-size" "0" "-delete")))) ``` ### Issues diff --git a/build-emacs-for-macos b/build-emacs-for-macos index c04d6c9..951ed1f 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -256,7 +256,6 @@ class Build apply_native_comp_macos_fixes end - ENV['NATIVE_FAST_BOOT'] = '1' if options[:native_fast_boot] ENV['CFLAGS'] = [ "-I#{gcc_dir}/include", '-O2', @@ -321,6 +320,15 @@ class Build make_flags = [] make_flags += ['-j', options[:parallel].to_s] if options[:parallel] + if options[:native_full_aot] + info 'Using NATIVE_FULL_AOT=1' + make_flags << 'NATIVE_FULL_AOT=1' + ENV.delete('NATIVE_FAST_BOOT') + else + ENV.delete('NATIVE_FULL_AOT') + ENV['NATIVE_FAST_BOOT'] = '1' + end + if options[:native_comp] make_flags << "BYTE_COMPILE_EXTRA_FLAGS=--eval '(setq comp-speed 2)'" end @@ -795,79 +803,90 @@ end if __FILE__ == $PROGRAM_NAME cli_options = { macos_fixes: true, - native_fast_boot: true, + native_full_aot: false, parallel: Etc.nprocessors, rsvg: false, xwidgets: true } - OptionParser.new do |opts| - opts.banner = <<~DOC - Usage: ./build-emacs-for-macos [options] - - 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('-j', '--parallel COUNT', - 'Compile using COUNT parallel processes ' \ - "(detected: #{cli_options[:parallel]})") do |v| - cli_options[:parallel] = v - end - - opts.on('--git-sha SHA', 'Override detected git SHA of specified branch ' \ - 'allowing builds of old commits') do |v| - cli_options[:git_sha] = v - end - - opts.on('--[no-]xwidgets', - 'Enable/disable XWidgets ' \ - '(default: enabled)') do |v| - cli_options[:xwidgets] = v - end - - opts.on('--[no-]native-comp', - 'Enable/disable native-comp ' \ - '(default: enabled if supported)') do |v| - cli_options[:native_comp] = v - end - - opts.on('--[no-]native-fast-boot', - 'Enable/disable NATIVE_FAST_BOOT ' \ - '(default: enabled if native-comp supported)') do |v| - cli_options[:native_fast_boot] = v - end - - opts.on('--[no-]native-comp-macos-fixes', - 'Enable/disable fix based on feature/native-comp-macos-fixes ' \ - 'branch (default: enabled if native-comp supported)') do |v| - cli_options[:macos_fixes] = v - end - - opts.on('--[no-]launcher', - 'Enable/disable embedded launcher script ' \ - '(default: enabled if native-comp is enabled)') do |v| - cli_options[:launcher] = v - end - - opts.on('--rsvg', 'Enable SVG image support via librsvg, ' \ - 'can yield a unstable build (default: disabled)') do - cli_options[:rsvg] = true - end - - opts.on('--no-titlebar', 'Apply no-titlebar patch (default: disabled)') do - cli_options[:no_titlebar] = true - end - - opts.on('--no-frame-refocus', - 'Apply no-frame-refocus patch (default: disabled)') do - cli_options[:no_frame_refocus] = true - end - end.parse! - begin + OptionParser.new do |opts| + opts.banner = <<~DOC + Usage: ./build-emacs-for-macos [options] + + 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('-j', '--parallel COUNT', + 'Compile using COUNT parallel processes ' \ + "(detected: #{cli_options[:parallel]})") do |v| + cli_options[:parallel] = v + end + + opts.on('--git-sha SHA', 'Override detected git SHA of specified ' \ + 'branch allowing builds of old commits') do |v| + cli_options[:git_sha] = v + end + + opts.on('--[no-]xwidgets', + 'Enable/disable XWidgets ' \ + '(default: enabled if supported)') do |v| + cli_options[:xwidgets] = v + end + + opts.on('--[no-]native-comp', + 'Enable/disable native-comp ' \ + '(default: enabled if supported)') do |v| + cli_options[:native_comp] = v + end + + opts.on('--[no-]native-full-aot', + 'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \ + '(default: disabled)') do |v| + cli_options[:native_full_aot] = v + end + + opts.on('--[no-]native-comp-macos-fixes', + 'Enable/disable fix based on feature/native-comp-macos-fixes ' \ + 'branch (default: enabled if native-comp supported)') do |v| + cli_options[:macos_fixes] = v + end + + opts.on('--[no-]launcher', + 'Enable/disable embedded launcher script ' \ + '(default: enabled if native-comp is enabled)') do |v| + cli_options[:launcher] = v + end + + opts.on('--rsvg', 'Enable SVG image support via librsvg, ' \ + 'can yield a unstable build (default: disabled)') do + cli_options[:rsvg] = true + end + + opts.on('--no-titlebar', 'Apply no-titlebar patch (default: disabled)') do + cli_options[:no_titlebar] = true + end + + opts.on('--no-frame-refocus', + 'Apply no-frame-refocus patch (default: disabled)') do + cli_options[:no_frame_refocus] = true + end + + opts.on('--[no-]native-fast-boot', + 'DEPRECATED: use --[no-]native-full-aot instead') do |v| + if v + raise Error, '--native-fast-boot option is deprecated, ' \ + 'use --no-native-full-aot instead' + else + raise Error, '--no-native-fast-boot option is deprecated, ' \ + 'use --native-full-aot instead' + end + end + end.parse! + Build.new(File.expand_path(__dir__), ARGV.shift, cli_options).build rescue Error => e warn "ERROR: #{e.message}"