Skip to content

Commit

Permalink
Merge pull request #154 from buty4649/always-optimize
Browse files Browse the repository at this point in the history
Always use optimization flags
  • Loading branch information
buty4649 authored Jan 26, 2024
2 parents d916f4d + ec20361 commit 6c02314
Showing 1 changed file with 12 additions and 11 deletions.
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

0 comments on commit 6c02314

Please sign in to comment.