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

Use ccache #9

Merged
merged 9 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
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
22 changes: 21 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build and test

on:
workflow_dispatch:
pull_request:

jobs:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rubocop.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: rubocop

on:
pull_request:
pull_request:

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand Down
25 changes: 13 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -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'
Expand Down
50 changes: 29 additions & 21 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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)
Expand Down