Skip to content

Commit

Permalink
Improved runtime performance by adding build-time optimization options
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Jan 6, 2024
1 parent 80224d3 commit be2e327
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
17 changes: 10 additions & 7 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ def debug_config(conf)
conf.enable_debug
end

def build_config(conf, target = nil, strip: false)
def build_config(conf, target = nil, optimize: false)
[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc'
cc.flags += ['-target', target] if target
cc.flags << '-s' if strip
if optimize
cc.flags += %w[-s -O3]
cc.flags += %w[-mtune=native -march=native] if target == 'x86_64-linux-musl'
end
end

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

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

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

build_config(conf, 'x86_64-macos', strip: true)
build_config(conf, 'x86_64-macos', optimize: 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 @@ -68,7 +71,7 @@ def build_config(conf, target = nil, strip: false)
MRuby::CrossBuild.new('darwin-arm64') do |conf|
macos_sdk = ENV.fetch('MACOSX_SDK_PATH').shellescape

build_config(conf, 'aarch64-macos', strip: true)
build_config(conf, 'aarch64-macos', optimize: 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 @@ -93,7 +96,7 @@ def build_config(conf, target = nil, strip: false)

[conf.cc, conf.linker].each do |cc|
cc.command = "#{conf.host_target}-gcc-posix"
cc.flags << '-static'
cc.flags += %w[-static -O3 -mtune=native -march=native]
end
conf.cc.defines += %w[MRB_STR_LENGTH_MAX=0 MRB_UTF8_STRING MRUBY_YAML_NO_CANONICAL_NULL]
conf.cxx.command = "#{conf.host_target}-g++"
Expand Down
20 changes: 20 additions & 0 deletions build_config.rb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ builds:
branch: master
commit: bb773da39517f3ae7232538c7e9c476d45f3d9b7
version: 0.0.0
https://github.com/mrbgems/mruby-tempfile.git:
url: https://github.com/mrbgems/mruby-tempfile.git
branch: master
commit: 48073012c932f540dc3773b2dc6b079caf71a70d
version: 0.0.0
linux-arm64:
https://github.com/mattn/mruby-json.git:
url: https://github.com/mattn/mruby-json.git
Expand Down Expand Up @@ -121,6 +126,11 @@ builds:
branch: master
commit: bb773da39517f3ae7232538c7e9c476d45f3d9b7
version: 0.0.0
https://github.com/mrbgems/mruby-tempfile.git:
url: https://github.com/mrbgems/mruby-tempfile.git
branch: master
commit: 48073012c932f540dc3773b2dc6b079caf71a70d
version: 0.0.0
darwin-amd64:
https://github.com/mattn/mruby-json.git:
url: https://github.com/mattn/mruby-json.git
Expand Down Expand Up @@ -157,6 +167,11 @@ builds:
branch: master
commit: bb773da39517f3ae7232538c7e9c476d45f3d9b7
version: 0.0.0
https://github.com/mrbgems/mruby-tempfile.git:
url: https://github.com/mrbgems/mruby-tempfile.git
branch: master
commit: 48073012c932f540dc3773b2dc6b079caf71a70d
version: 0.0.0
darwin-arm64:
https://github.com/mattn/mruby-json.git:
url: https://github.com/mattn/mruby-json.git
Expand Down Expand Up @@ -193,6 +208,11 @@ builds:
branch: master
commit: bb773da39517f3ae7232538c7e9c476d45f3d9b7
version: 0.0.0
https://github.com/mrbgems/mruby-tempfile.git:
url: https://github.com/mrbgems/mruby-tempfile.git
branch: master
commit: 48073012c932f540dc3773b2dc6b079caf71a70d
version: 0.0.0
windows-amd64:
https://github.com/mattn/mruby-json.git:
url: https://github.com/mattn/mruby-json.git
Expand Down

0 comments on commit be2e327

Please sign in to comment.