diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 79bf248..120a48d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,6 +1,7 @@ name: build and test on: + workflow_dispatch: pull_request: jobs: @@ -17,18 +18,37 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: 3.2 + - name: Build cache + uses: actions/cache@v3 + with: + path: build/ + key: ${{ runner.os }}-ccache - name: build - run: rake build:ci + run: rake build:all release + - name: Upload test binary (linux-amd64) uses: actions/upload-artifact@v3 with: name: rf-${{ github.sha }}-linux-amd64 path: build/linux-amd64/bin/rf + - name: Upload test binary (linux-arm64) + uses: actions/upload-artifact@v3 + with: + name: rf-${{ github.sha }}-linux-arm64 + path: build/linux-arm64/bin/rf - name: Upload test binary (darwin-amd64) uses: actions/upload-artifact@v3 with: name: rf-${{ github.sha }}-darwin-amd64 path: build/darwin-amd64/bin/rf + - name: Upload test binary (darwin-arm64) + uses: actions/upload-artifact@v3 + with: + name: rf-${{ github.sha }}-darwin-arm64 + path: build/darwin-arm64/bin/rf + + - name: Cleanup build directory + run: rake clean test-on-linux: needs: build diff --git a/.github/workflows/rubocop.yaml b/.github/workflows/rubocop.yaml index 6f949c3..503a676 100644 --- a/.github/workflows/rubocop.yaml +++ b/.github/workflows/rubocop.yaml @@ -1,10 +1,10 @@ name: rubocop on: - pull_request: + pull_request: jobs: - build: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@master diff --git a/Rakefile b/Rakefile index 153b45c..36dc218 100644 --- a/Rakefile +++ b/Rakefile @@ -19,10 +19,6 @@ def build_targets ] end -def ci_build_targets - %w[linux-amd64 darwin-amd64] -end - def archive_binary_file(targets, version) FileUtils.mkdir_p 'release' targets.each do |target| @@ -47,14 +43,18 @@ end namespace :build do desc 'Build the project for all targets' task 'all' do - env = ["MRUBY_BUILD_TARGETS=#{build_targets.join(',')}"] - docker_run(env:) + build_targets.each do |target| + Rake::Task["build:#{target}"].invoke + end end - desc 'Build the project for CI' - task 'ci' do - env = ["MRUBY_BUILD_TARGETS=#{ci_build_targets.join(',')}"] - docker_run(env:) + build_targets.each do |target| + desc "Build the project for #{target}" + task target do + env = ["MRUBY_BUILD_TARGETS=#{target}"] + env += ['USE_CCACHE=1', "CCACHE_DIR=build/ccache/#{target}"] unless ENV['CCACHE_DISABLE'] + docker_run(env:) + end end end @@ -65,12 +65,13 @@ end desc 'Deep cleanup build cache' task 'deep_clean' do - docker_run(cmd: 'deep_clean') + env = ["MRUBY_BUILD_TARGETS=#{build_targets.join(',')}"] + docker_run(cmd: 'deep_clean', env:) end desc 'Release the project' task release: %w[clean build:all] do - archive_binary_file(build_targets, "v#{RF::VERSION}") + archive_binary_file(build_targets, "v#{Rf::VERSION}") end desc 'Run RSpec with parallel_rspec' diff --git a/build_config.rb b/build_config.rb index 04b9a47..3489550 100644 --- a/build_config.rb +++ b/build_config.rb @@ -11,21 +11,26 @@ def debug_config(conf) conf.enable_debug end -def linux_build_config(conf, target = nil, strip: false) - commands = %w[zig cc] - commands << '-s' if strip - commands += ['-target', target] if target - commands = commands.shelljoin - - conf.cc.command = commands - conf.linker.command = commands +def cc_command + command = %w[zig cc] + command.unshift 'ccache' if ENV['USE_CCACHE'] + command.join(' ') +end + +def build_config(conf, target = nil, strip: false) + [conf.cc, conf.linker].each do |cc| + cc.command = cc_command + cc.flags += ['-target', target] if target + end + conf.cc.flags << '-s' if strip + conf.archiver.command = 'zig ar' conf.cc.defines += %w[MRB_STR_LENGTH_MAX=0 MRB_UTF8_STRING] conf.host_target = target if target end MRuby::Build.new do |conf| - linux_build_config(conf) + build_config(conf) debug_config(conf) gem_config(conf) end @@ -39,7 +44,7 @@ def linux_build_config(conf, target = nil, strip: false) next unless build_targets.include?(arch) MRuby::CrossBuild.new(arch) do |conf| - linux_build_config(conf, target, strip: true) + build_config(conf, target, strip: true) debug_config(conf) gem_config(conf) end @@ -49,11 +54,12 @@ def linux_build_config(conf, target = nil, strip: false) MRuby::CrossBuild.new('darwin-amd64') do |conf| macos_sdk = ENV.fetch('MACOSX_SDK_PATH').shellescape - command = ['zig', 'cc', '-target', 'x86_64-macos', '-Wno-overriding-t-option', '-mmacosx-version-min=10.14'] - conf.cc.command = (command + ['-isysroot', macos_sdk, '-iwithsysroot', - '/usr/include', '-iframeworkwithsysroot', - '/System/Library/Frameworks']).join(' ') - conf.linker.command = (command + ['--sysroot', macos_sdk, '-F/System/Library/Frameworks', '-L/usr/lib']).shelljoin + 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'] + conf.linker.flags += ['-Wno-overriding-t-option', '-mmacosx-version-min=10.14', + '--sysroot', macos_sdk, '-F/System/Library/Frameworks', '-L/usr/lib'] conf.archiver.command = 'zig ar' ENV['RANLIB'] ||= 'zig ranlib' conf.host_target = 'x86_64-darwin' @@ -67,14 +73,16 @@ def linux_build_config(conf, target = nil, strip: false) MRuby::CrossBuild.new('darwin-arm64') do |conf| macos_sdk = ENV.fetch('MACOSX_SDK_PATH').shellescape - command = ['zig', 'cc', '-target', 'aarch64-macos', '-Wno-overriding-t-option', '-mmacosx-version-min=11.1'] - conf.cc.command = (command + ['-isysroot', macos_sdk, '-iwithsysroot', - '/usr/include', '-iframeworkwithsysroot', - '/System/Library/Frameworks']).join(' ') - conf.linker.command = (command + ['--sysroot', macos_sdk, '-F/System/Library/Frameworks', '-L/usr/lib']).shelljoin + 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'] + conf.linker.flags += ['-Wno-overriding-t-option', '-mmacosx-version-min=11.1', + '--sysroot', macos_sdk, '-F/System/Library/Frameworks', '-L/usr/lib'] + conf.archiver.command = 'zig ar' ENV['RANLIB'] ||= 'zig ranlib' - conf.host_target = 'x86_64-darwin' + conf.host_target = 'aarch64-darwin' debug_config(conf) gem_config(conf)