From ca2d4c38f69c434c77c266594104bfbf34ad5221 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 7 Jun 2021 23:12:52 +0100 Subject: [PATCH] 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|