From 55a7a9457aae72e65c3a694fc1a3c3a9bbe04e89 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 29 May 2019 22:34:38 +0100 Subject: [PATCH] Enable LTO and -march=native -march=native is only enabled when not cross-compiling --- Rakefile | 2 ++ ext/extconf.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 226e18af..4db941d3 100644 --- a/Rakefile +++ b/Rakefile @@ -14,6 +14,8 @@ Rake::ExtensionTask.new('libsass', gem_spec) do |ext| # Link C++ stdlib statically when building binary gems. ext.cross_config_options << '--enable-static-stdlib' + ext.cross_config_options << '--disable-march-native' + ext.cross_compiling do |spec| spec.files.reject! { |path| File.fnmatch?('ext/*', path) } diff --git a/ext/extconf.rb b/ext/extconf.rb index 42427b80..03ac4b08 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -14,11 +14,23 @@ $CXXFLAGS << ' -std=c++11' -# Link stdlib statically when building binary gems. -if enable_config('static-stdlib') +# Set to true when building binary gems +if enable_config('static-stdlib', false) $LDFLAGS << ' -static-libgcc -static-libstdc++' end +# Set to false when building binary gems +if enable_config('march-native', true) + $CFLAGS << ' -march=native' + $CXXFLAGS << ' -march=native' +end + +if enable_config('lto', true) + $CFLAGS << ' -flto' + $CXXFLAGS << ' -flto' + $LDFLAGS << ' -flto' +end + # Disable noisy compilation warnings. $warnflags = '' $CFLAGS.gsub!(/[\s+](-ansi|-std=[^\s]+)/, '')