diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4cdae7c..70f9ac1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -24,7 +24,7 @@ jobs: path: build/cache key: ${{ runner.os }}-ccache - name: build - run: rake build:all release + run: rake build:all - name: Upload test binary (linux-amd64) uses: actions/upload-artifact@v3 @@ -46,6 +46,11 @@ jobs: with: name: rf-${{ github.sha }}-darwin-arm64 path: build/darwin-arm64/bin/rf + - name: Upload test binary (windows-amd64) + uses: actions/upload-artifact@v3 + with: + name: rf-${{ github.sha }}-windows-amd64 + path: build/windows-amd64/bin/rf.exe test-on-linux: needs: build @@ -86,3 +91,21 @@ jobs: run: | chmod +x build/bin/rf rake spec + + test-on-windows: + needs: build + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: rf-${{ github.sha }}-windows-amd64 + path: build/bin + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + - name: Install dependencies + run: bundle install + - name: Run test + run: rake spec diff --git a/Gemfile b/Gemfile index 6b0ad33..6ad05cd 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org/' gem 'rake' group 'test' do - gem 'aruba', '~> 2.1.0' + gem 'aruba', github: 'cucumber/aruba', branch: 'main' gem 'parallel_tests' gem 'rspec' gem 'rspec-parameterized', '>= 1.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 2777394..cfb71f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,18 +1,22 @@ -GEM - remote: https://rubygems.org/ +GIT + remote: https://github.com/cucumber/aruba.git + revision: 4994d939852d60d939e2f641bb33a282bb4005af + branch: main specs: aruba (2.1.0) bundler (>= 1.17, < 3.0) - childprocess (>= 2.0, < 5.0) contracts (>= 0.16.0, < 0.18.0) cucumber (>= 4.0, < 9.0) rspec-expectations (~> 3.4) thor (~> 1.0) + +GEM + remote: https://rubygems.org/ + specs: ast (2.4.2) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) builder (3.2.4) - childprocess (4.1.0) coderay (1.1.3) contracts (0.17) cucumber (8.0.0) @@ -117,7 +121,7 @@ PLATFORMS x86_64-linux DEPENDENCIES - aruba (~> 2.1.0) + aruba! parallel_tests rake rspec diff --git a/Rakefile b/Rakefile index 36dc218..b9041b2 100644 --- a/Rakefile +++ b/Rakefile @@ -16,14 +16,16 @@ def build_targets %w[ linux-amd64 linux-arm64 darwin-amd64 darwin-arm64 + windows-amd64 ] end def archive_binary_file(targets, version) FileUtils.mkdir_p 'release' targets.each do |target| - src = File.expand_path("build/#{target}/bin/rf") - dest = File.expand_path("release/rf-#{version}-#{target}") + ext = '.exe' if target =~ /windows/ + src = File.expand_path("build/#{target}/bin/rf#{ext}") + dest = File.expand_path("release/rf-#{version}-#{target}#{ext}") if target =~ /linux/ sh "tar -cf #{dest}.tar.gz -C #{File.dirname(src)} #{File.basename(src)}" diff --git a/build_config.rb b/build_config.rb index 3489550..98751fc 100644 --- a/build_config.rb +++ b/build_config.rb @@ -11,15 +11,13 @@ def debug_config(conf) conf.enable_debug end -def cc_command - command = %w[zig cc] - command.unshift 'ccache' if ENV['USE_CCACHE'] - command.join(' ') +def ccache + 'ccache ' if ENV['USE_CCACHE'] end def build_config(conf, target = nil, strip: false) [conf.cc, conf.linker].each do |cc| - cc.command = cc_command + cc.command = "#{ccache}zig cc" cc.flags += ['-target', target] if target end conf.cc.flags << '-s' if strip @@ -88,3 +86,28 @@ def build_config(conf, target = nil, strip: false) gem_config(conf) end end + +if build_targets.include?('windows-amd64') + MRuby::CrossBuild.new('windows-amd64') do |conf| + toolchain :gcc + + conf.build_target = 'x86_64-pc-linux-gnu' + conf.host_target = 'x86_64-w64-mingw32' + + [conf.cc, conf.linker].each do |cc| + cc.command = "#{ccache}#{conf.host_target}-gcc-posix" + cc.flags << '-static' + end + conf.cxx.command = "#{ccache}#{conf.host_target}-g++" + conf.archiver.command = "#{ccache}#{conf.host_target}-gcc-ar" + + conf.exts do |exts| + exts.object = '.obj' + exts.executable = '.exe' + exts.library = '.lib' + end + + debug_config(conf) + gem_config(conf) + end +end diff --git a/build_config.rb.lock b/build_config.rb.lock index 20a54bb..2da0d2c 100644 --- a/build_config.rb.lock +++ b/build_config.rb.lock @@ -39,3 +39,163 @@ builds: branch: master commit: 34a477d249b0d21671058be33aa75d04c3e981ba version: 0.0.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: master + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + linux-amd64: + https://github.com/mattn/mruby-json.git: + url: https://github.com/mattn/mruby-json.git + branch: master + commit: f99d9428025469f2400f93c53b185f65f963e507 + version: 0.0.0 + https://github.com/fastly/mruby-optparse.git: + url: https://github.com/fastly/mruby-optparse.git + branch: master + commit: e6397a090d1efe04d5dab57c63897f0d79bbad89 + version: 0.0.0 + https://github.com/mrbgems/mruby-yaml.git: + url: https://github.com/mrbgems/mruby-yaml.git + branch: master + commit: 123010195bf621e784ee9d4ff9144a4b8e9cbb6a + version: 0.1.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: fix-build-error-with-mingw + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + https://github.com/IceDragon200/mruby-catch-throw: + url: https://github.com/IceDragon200/mruby-catch-throw + branch: master + commit: 2b6eaff4232b4a9473b864df53c2917080af5dcf + version: 1.1.0 + https://github.com/iij/mruby-env.git: + url: https://github.com/iij/mruby-env.git + branch: master + commit: 056ae324451ef16a50c7887e117f0ea30921b71b + version: 0.0.0 + linux-arm64: + https://github.com/mattn/mruby-json.git: + url: https://github.com/mattn/mruby-json.git + branch: master + commit: f99d9428025469f2400f93c53b185f65f963e507 + version: 0.0.0 + https://github.com/fastly/mruby-optparse.git: + url: https://github.com/fastly/mruby-optparse.git + branch: master + commit: e6397a090d1efe04d5dab57c63897f0d79bbad89 + version: 0.0.0 + https://github.com/mrbgems/mruby-yaml.git: + url: https://github.com/mrbgems/mruby-yaml.git + branch: master + commit: 123010195bf621e784ee9d4ff9144a4b8e9cbb6a + version: 0.1.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: fix-build-error-with-mingw + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + https://github.com/IceDragon200/mruby-catch-throw: + url: https://github.com/IceDragon200/mruby-catch-throw + branch: master + commit: 2b6eaff4232b4a9473b864df53c2917080af5dcf + version: 1.1.0 + https://github.com/iij/mruby-env.git: + url: https://github.com/iij/mruby-env.git + branch: master + commit: 056ae324451ef16a50c7887e117f0ea30921b71b + version: 0.0.0 + darwin-amd64: + https://github.com/mattn/mruby-json.git: + url: https://github.com/mattn/mruby-json.git + branch: master + commit: f99d9428025469f2400f93c53b185f65f963e507 + version: 0.0.0 + https://github.com/fastly/mruby-optparse.git: + url: https://github.com/fastly/mruby-optparse.git + branch: master + commit: e6397a090d1efe04d5dab57c63897f0d79bbad89 + version: 0.0.0 + https://github.com/mrbgems/mruby-yaml.git: + url: https://github.com/mrbgems/mruby-yaml.git + branch: master + commit: 123010195bf621e784ee9d4ff9144a4b8e9cbb6a + version: 0.1.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: fix-build-error-with-mingw + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + https://github.com/IceDragon200/mruby-catch-throw: + url: https://github.com/IceDragon200/mruby-catch-throw + branch: master + commit: 2b6eaff4232b4a9473b864df53c2917080af5dcf + version: 1.1.0 + https://github.com/iij/mruby-env.git: + url: https://github.com/iij/mruby-env.git + branch: master + commit: 056ae324451ef16a50c7887e117f0ea30921b71b + version: 0.0.0 + darwin-arm64: + https://github.com/mattn/mruby-json.git: + url: https://github.com/mattn/mruby-json.git + branch: master + commit: f99d9428025469f2400f93c53b185f65f963e507 + version: 0.0.0 + https://github.com/fastly/mruby-optparse.git: + url: https://github.com/fastly/mruby-optparse.git + branch: master + commit: e6397a090d1efe04d5dab57c63897f0d79bbad89 + version: 0.0.0 + https://github.com/mrbgems/mruby-yaml.git: + url: https://github.com/mrbgems/mruby-yaml.git + branch: master + commit: 123010195bf621e784ee9d4ff9144a4b8e9cbb6a + version: 0.1.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: fix-build-error-with-mingw + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + https://github.com/IceDragon200/mruby-catch-throw: + url: https://github.com/IceDragon200/mruby-catch-throw + branch: master + commit: 2b6eaff4232b4a9473b864df53c2917080af5dcf + version: 1.1.0 + https://github.com/iij/mruby-env.git: + url: https://github.com/iij/mruby-env.git + branch: master + commit: 056ae324451ef16a50c7887e117f0ea30921b71b + version: 0.0.0 + windows-amd64: + https://github.com/mattn/mruby-json.git: + url: https://github.com/mattn/mruby-json.git + branch: master + commit: f99d9428025469f2400f93c53b185f65f963e507 + version: 0.0.0 + https://github.com/fastly/mruby-optparse.git: + url: https://github.com/fastly/mruby-optparse.git + branch: master + commit: e6397a090d1efe04d5dab57c63897f0d79bbad89 + version: 0.0.0 + https://github.com/mrbgems/mruby-yaml.git: + url: https://github.com/mrbgems/mruby-yaml.git + branch: master + commit: 123010195bf621e784ee9d4ff9144a4b8e9cbb6a + version: 0.1.0 + https://github.com/buty4649/mruby-onig-regexp.git: + url: https://github.com/buty4649/mruby-onig-regexp.git + branch: fix-build-error-with-mingw + commit: ce9bc7a8b4ff11a438c36826ed2c685237c96b05 + version: 0.0.0 + https://github.com/IceDragon200/mruby-catch-throw: + url: https://github.com/IceDragon200/mruby-catch-throw + branch: master + commit: 2b6eaff4232b4a9473b864df53c2917080af5dcf + version: 1.1.0 + https://github.com/iij/mruby-env.git: + url: https://github.com/iij/mruby-env.git + branch: master + commit: 056ae324451ef16a50c7887e117f0ea30921b71b + version: 0.0.0 diff --git a/mrbgem.rake b/mrbgem.rake index fa759b0..f0ca36a 100644 --- a/mrbgem.rake +++ b/mrbgem.rake @@ -11,10 +11,10 @@ MRuby::Gem::Specification.new('rf') do |spec| %w[ mruby-json - mruby-onig-regexp mruby-optparse mruby-yaml ].each do |mgem| spec.add_dependency mgem, mgem: end + spec.add_dependency 'mruby-onig-regexp', github: 'buty4649/mruby-onig-regexp', branch: 'fix-build-error-with-mingw' end diff --git a/spec/support/aruba.rb b/spec/support/aruba.rb index 5bfd45f..9332fb5 100644 --- a/spec/support/aruba.rb +++ b/spec/support/aruba.rb @@ -6,8 +6,15 @@ config.working_directory = working_directory end -def run_rf(args, input = nil) +def rf_path rf_path = File.expand_path('../../build/bin/rf', __dir__) + return rf_path if File.exist?(rf_path) + + "#{rf_path}.exe" +end + +def run_rf(args, input = nil) + @rf_path ||= rf_path command = run_command("#{rf_path} #{args}") if input