From bd8187065928b9f79de8b14222c98f8dc34bfe5f Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 7 Jun 2021 23:03:52 +0100 Subject: [PATCH 1/2] fix(native_comp): crash on launch when gcc homebrew package was not installed It turns out all *.eln files link against the libgcc dylib in homebrew: /usr/local/lib/gcc/11/libgcc_s.1.dylib So here we find all *.eln files in all relevant paths they may be depending on how old of a native-comp source tree we're building, and copy in any shared libs that resides within the homebrew prefix. Just like we do for all other binaries that we copy libs for. --- build-emacs-for-macos | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/build-emacs-for-macos b/build-emacs-for-macos index 3ca9a3a..cd3fc27 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -652,11 +652,35 @@ class LibEmbedder < AbstractEmbedder FileUtils.cd(File.dirname(app)) do copy_libs(binary) copy_extra_libs(extra_libs, binary) if extra_libs.any? + if eln_files.any? + info "Embedding libraries for #{eln_files.size} *.eln files " \ + 'within Emacs.app' + rel_path = Pathname.new(lib_dir).relative_path_from( + Pathname.new(File.dirname(binary)) + ).to_s + eln_files.each { |f| copy_libs(f, rel_path) } + end end end private + def eln_files + @eln_files ||= Dir[ + File.join( + app, 'Contents', 'Resources', 'native-lisp', '**', '*.eln' + ), + File.join( + app, 'Contents', 'MacOS', 'lib', 'emacs', '**', + 'native-lisp', '**', '*.eln' + ), + File.join( + app, 'Contents', 'MacOS', 'libexec', 'emacs', '**', + 'eln-cache', '**', '*.eln' + ) + ] + end + def copy_libs(exe, rel_path = nil) exe_file = File.basename(exe) rel_path ||= Pathname.new(lib_dir).relative_path_from( From ca2d4c38f69c434c77c266594104bfbf34ad5221 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 7 Jun 2021 23:12:52 +0100 Subject: [PATCH 2/2] fix(compiling): improve portability of builds This makes the -march=native CFLAG optional, and disabled by default, but still available through a new --native-march flag. It should make builds more portable between machines, as previously it was very common to get a CPU architecture error on launch if you moved the build to a different machine running a different generation of a Intel CPU. From what I've understood, when using the -march=native CFLAG clang will make as many optimizations possible based on the exact set of CPU instructions available on the specific CPU it's compiling on. In theory this leads to a more optimized build, though I haven't personally noticed any difference. But it also leads to less portable builds, for example builds from a Intel-based 2020 MacBook Pro just crash with a unsupported CPU architecture error when run on a Intel-based 2016 MacBook Pro. --- README.md | 1 + build-emacs-for-macos | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eadb3bd..2566cff 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Options: --git-sha SHA Override detected git SHA of specified branch allowing builds of old commits --[no-]xwidgets Enable/disable XWidgets 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) --[no-]native-full-aot Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation (default: disabled) --[no-]rsvg Enable/disable SVG image support via librsvg (default: enabled) --no-titlebar Apply no-titlebar patch (default: disabled) diff --git a/build-emacs-for-macos b/build-emacs-for-macos index cd3fc27..2b81054 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -267,7 +267,7 @@ class Build "-I#{File.join(gcc_info.root_dir, 'include')}", "-I#{File.join(gcc_info.libgccjit_root_dir, 'include')}", '-O2', - '-march=native', + (options[:native_march] ? '-march=native' : nil), ENV['CFLAGS'] ].compact.join(' ') @@ -904,6 +904,7 @@ if __FILE__ == $PROGRAM_NAME cli_options = { work_dir: File.expand_path(__dir__), native_full_aot: false, + native_march: false, parallel: Etc.nprocessors, rsvg: true, xwidgets: true, @@ -945,6 +946,12 @@ if __FILE__ == $PROGRAM_NAME cli_options[:native_comp] = v end + opts.on('--[no-]native-march', + 'Enable/disable -march=native CFLAG' \ + '(default: disabled)') do |v| + cli_options[:native_march] = v + end + opts.on('--[no-]native-full-aot', 'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \ '(default: disabled)') do |v|