Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use optimization flags #154

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ def debug_config(conf)
conf.enable_debug
end

def build_config(conf, target = nil, optimize: false)
def build_config(conf, target = nil, strip: false)
flags = %w[-O3]
flags += ['-target', target] if target
flags += %w[-mtune=native -march=native] if target == 'x86_64-linux-musl'
flags << '-s' if strip

[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc'
cc.flags += ['-target', target] if target
if optimize
cc.flags += %w[-s -O3]
cc.flags += %w[-mtune=native -march=native] if target == 'x86_64-linux-musl'
end
cc.flags += flags
end

conf.archiver.command = 'zig ar'
Expand All @@ -28,7 +29,7 @@ def build_config(conf, target = nil, optimize: false)
end

MRuby::Build.new do |conf|
build_config(conf, optimize: true)
build_config(conf, strip: true)
debug_config(conf)
gem_config(conf)
end
Expand All @@ -42,7 +43,7 @@ def build_config(conf, target = nil, optimize: false)
next unless build_targets.include?(arch)

MRuby::CrossBuild.new(arch) do |conf|
build_config(conf, target, optimize: true)
build_config(conf, target, strip: true)
debug_config(conf)
gem_config(conf)
end
Expand All @@ -52,7 +53,7 @@ def build_config(conf, target = nil, optimize: false)
MRuby::CrossBuild.new('darwin-amd64') do |conf|
macos_sdk = ENV.fetch('MACOSX_SDK_PATH').shellescape

build_config(conf, 'x86_64-macos', optimize: true)
build_config(conf, 'x86_64-macos', strip: true)
conf.cc.flags += ['-Wno-overriding-t-option', '-mmacosx-version-min=10.14',
'-isysroot', macos_sdk, '-iwithsysroot', '/usr/include',
'-iframeworkwithsysroot', '/System/Library/Frameworks']
Expand All @@ -71,7 +72,7 @@ def build_config(conf, target = nil, optimize: false)
MRuby::CrossBuild.new('darwin-arm64') do |conf|
macos_sdk = ENV.fetch('MACOSX_SDK_PATH').shellescape

build_config(conf, 'aarch64-macos', optimize: true)
build_config(conf, 'aarch64-macos', strip: true)
conf.cc.flags += ['-Wno-overriding-t-option', '-mmacosx-version-min=11.1',
'-isysroot', macos_sdk, '-iwithsysroot', '/usr/include',
'-iframeworkwithsysroot', '/System/Library/Frameworks']
Expand All @@ -96,7 +97,7 @@ def build_config(conf, target = nil, optimize: false)

[conf.cc, conf.linker].each do |cc|
cc.command = "#{conf.host_target}-gcc-posix"
cc.flags += %w[-static -O3]
cc.flags += %w[-static -O3 -s]
end
conf.cc.defines += %w[MRB_STR_LENGTH_MAX=0 MRB_UTF8_STRING MRUBY_YAML_NO_CANONICAL_NULL
MRB_IREP_LVAR_MERGE_LIMIT=240]
Expand Down