From 07ebb2811a24b4c0d65490803af172bb192fc77d Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 14:31:59 +0100 Subject: [PATCH 01/10] Ruby: Test `rake-cross-compiler` --- .github/workflows/build-gems.yml | 3 +++ Gemfile | 2 +- Gemfile.lock | 10 ++++++++-- Rakefile | 28 ++++++++++++---------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-gems.yml b/.github/workflows/build-gems.yml index e134f1efb..6260f2544 100644 --- a/.github/workflows/build-gems.yml +++ b/.github/workflows/build-gems.yml @@ -85,6 +85,9 @@ jobs: - name: Compile Herb run: bundle exec rake make + - name: Setup Cross-Ruby Configs + run: bundle exec rake gem:prepare + - name: Build gem run: | if [ "${{ matrix.target }}" = "default" ]; then diff --git a/Gemfile b/Gemfile index 0f502102d..ca5aae259 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "maxitest" gem "minitest-difftastic", "~> 0.2" gem "rake", "~> 13.2" gem "rake-compiler", "~> 1.3" -gem "rake-compiler-dock", "1.11.0.rc1" +gem "rake-cross-compiler", github: "marcoroth/rake-cross-compiler" gem "reline", "~> 0.6" gem "rubocop", "~> 1.71" diff --git a/Gemfile.lock b/Gemfile.lock index 799dc4e42..534a76103 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/marcoroth/rake-cross-compiler.git + revision: 180bdb7d9c023d652423ea00714c43705b244b52 + specs: + rake-cross-compiler (0.0.1) + rake (>= 13.0) + GIT remote: https://github.com/ruby/prism.git revision: df554035afb63c754b9edbe531ff48e6569eaf07 @@ -110,7 +117,6 @@ GEM rake (13.3.1) rake-compiler (1.3.1) rake - rake-compiler-dock (1.11.0.rc1) rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) @@ -192,7 +198,7 @@ DEPENDENCIES prism! rake (~> 13.2) rake-compiler (~> 1.3) - rake-compiler-dock (= 1.11.0.rc1) + rake-cross-compiler! rbs-inline (~> 0.12) reline (~> 0.6) rubocop (~> 1.71) diff --git a/Rakefile b/Rakefile index 4f78fec4d..3b6d6ddd4 100644 --- a/Rakefile +++ b/Rakefile @@ -58,34 +58,29 @@ begin end task "gem:native" do - require "rake_compiler_dock" + require "rake/cross/compiler" sh "bundle config set cache_all true" PLATFORMS.each do |platform| - RakeCompilerDock.sh "bundle --local && rake native:#{platform} gem", platform: platform + Rake::Cross::Compiler.sh "bundle --local && rake native:#{platform} gem", platform: platform end - RakeCompilerDock.sh "bundle --local && rake java gem", rubyvm: :jruby + # RakeCompilerDock.sh "bundle --local && rake java gem", rubyvm: :jruby rescue LoadError - abort "rake_compiler_dock is required to build native gems" + abort "rake-cross-compiler is required to build native gems" end namespace "gem" do task "prepare" do - require "rake_compiler_dock" - require "io/console" - - sh "bundle config set cache_all true" - sh "cp ~/.gem/gem-*.pem build/gem/ || true" + require "rake/cross/compiler" gemspec_path = File.expand_path("./herb.gemspec", __dir__) spec = eval(File.read(gemspec_path), binding, gemspec_path) - RakeCompilerDock.set_ruby_cc_version(spec.required_ruby_version.as_list) - - # ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ") + Rake::Cross::Compiler.set_ruby_cc_version(spec.required_ruby_version, platforms: PLATFORMS) + Rake::Cross::Compiler.setup_cross_ruby(platforms: PLATFORMS) rescue LoadError - abort "rake_compiler_dock is required for this task" + abort "rake-cross-compiler is required for this task" end exttask.cross_platform.each do |platform| @@ -94,9 +89,10 @@ begin desc "Build the native gem for #{platform}" task platform => "prepare" do - RakeCompilerDock.sh( - "bundle --local && rake native:#{platform} gem RUBY_CC_VERSION='#{ENV.fetch("RUBY_CC_VERSION", nil)}'", - platform: platform + Rake::Cross::Compiler.sh( + "bundle --local && rake native:#{platform} gem", + platform: platform, + ruby_cc_version: ENV.fetch("RUBY_CC_VERSION", nil) ) end end From c21c68f6f9221e7e4508262ea2eeb3f26d8e1466 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 14:39:27 +0100 Subject: [PATCH 02/10] Remove Ruby 4.0 --- herb.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/herb.gemspec b/herb.gemspec index cfdac9d86..d90f473c3 100644 --- a/herb.gemspec +++ b/herb.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://herb-tools.dev" spec.license = "MIT" - spec.required_ruby_version = ">= 3.0.0" + spec.required_ruby_version = [">= 3.0.0", "< 4.0"] spec.require_paths = ["lib"] spec.files = Dir[ From db2bdb0bc6d1577c7073051ec4f80846966b3966 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 14:52:40 +0100 Subject: [PATCH 03/10] Run vendor prism --- .github/workflows/build-gems.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-gems.yml b/.github/workflows/build-gems.yml index 6260f2544..921b2fa8d 100644 --- a/.github/workflows/build-gems.yml +++ b/.github/workflows/build-gems.yml @@ -79,6 +79,9 @@ jobs: - name: bundle install run: bundle install + - name: Vendor Prism + run: bundle exec rake prism:vendor + - name: Render Templates run: bundle exec rake templates From 091e59d5ddde0c8d7faf3f15e80a67b605aa6268 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 15:27:41 +0100 Subject: [PATCH 04/10] Skip header checks --- .github/workflows/build-gems.yml | 3 --- ext/herb/extconf.rb | 12 +++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-gems.yml b/.github/workflows/build-gems.yml index 921b2fa8d..6260f2544 100644 --- a/.github/workflows/build-gems.yml +++ b/.github/workflows/build-gems.yml @@ -79,9 +79,6 @@ jobs: - name: bundle install run: bundle install - - name: Vendor Prism - run: bundle exec rake prism:vendor - - name: Render Templates run: bundle exec rake templates diff --git a/ext/herb/extconf.rb b/ext/herb/extconf.rb index 3e07accf6..fbad2eede 100644 --- a/ext/herb/extconf.rb +++ b/ext/herb/extconf.rb @@ -66,12 +66,14 @@ puts "Sources to be compiled: #{$srcs.inspect}" -abort("could not find prism.h") unless find_header("prism.h") -abort("could not find herb.h") unless find_header("herb.h") +unless defined?(CROSS_COMPILING) && CROSS_COMPILING + abort("could not find prism.h") unless find_header("prism.h") + abort("could not find herb.h") unless find_header("herb.h") -abort("could not find nodes.h (run `ruby templates/template.rb` to generate the file)") unless find_header("nodes.h") -abort("could not find extension.h") unless find_header("extension.h") -abort("could not find extension_helpers.h") unless find_header("extension_helpers.h") + abort("could not find nodes.h (run `ruby templates/template.rb` to generate the file)") unless find_header("nodes.h") + abort("could not find extension.h") unless find_header("extension.h") + abort("could not find extension_helpers.h") unless find_header("extension_helpers.h") +end create_header create_makefile("#{extension_name}/#{extension_name}") From 3869eacb17b9c3d03d591c7707b31a4948352d24 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 15:40:24 +0100 Subject: [PATCH 05/10] Update rake-cross-compiler --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 534a76103..8c1631c9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/marcoroth/rake-cross-compiler.git - revision: 180bdb7d9c023d652423ea00714c43705b244b52 + revision: febcf430533d4187ae12cc84a3ffcb5d7ffc54a6 specs: rake-cross-compiler (0.0.1) rake (>= 13.0) From 3c2c3f878c77b5caeefd141bf6b5df93097cca07 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 15:54:15 +0100 Subject: [PATCH 06/10] Update rake-cross-compiler --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8c1631c9f..ebee72fdb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/marcoroth/rake-cross-compiler.git - revision: febcf430533d4187ae12cc84a3ffcb5d7ffc54a6 + revision: 9ff449d0d7c65dad619a78c22ae377f79e969c33 specs: rake-cross-compiler (0.0.1) rake (>= 13.0) From b8542b52e4afffb1fa1d586990cdcc2ab7fd5b24 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 15:59:25 +0100 Subject: [PATCH 07/10] Bundle cache --- .github/workflows/build-gems.yml | 8 +++----- Gemfile.lock | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-gems.yml b/.github/workflows/build-gems.yml index 6260f2544..9c699c634 100644 --- a/.github/workflows/build-gems.yml +++ b/.github/workflows/build-gems.yml @@ -74,10 +74,8 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - bundler-cache: false - - - name: bundle install - run: bundle install + ruby-version: '3.4' + bundler-cache: true - name: Render Templates run: bundle exec rake templates @@ -131,7 +129,7 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: '3.4' - bundler-cache: false + bundler-cache: true - name: Download gem artifacts uses: actions/download-artifact@v4 diff --git a/Gemfile.lock b/Gemfile.lock index ebee72fdb..347faeba0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/marcoroth/rake-cross-compiler.git - revision: 9ff449d0d7c65dad619a78c22ae377f79e969c33 + revision: c886a66dd8e0957a201a8b629058dd3340f85a42 specs: rake-cross-compiler (0.0.1) rake (>= 13.0) From ea9ba4ccc88474a6ae81b764ba0196c4b8273b91 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 16:14:01 +0100 Subject: [PATCH 08/10] Don't install LLVM in build-gems.yml workflow --- .github/workflows/build-gems.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-gems.yml b/.github/workflows/build-gems.yml index 9c699c634..b5ea4c9a5 100644 --- a/.github/workflows/build-gems.yml +++ b/.github/workflows/build-gems.yml @@ -62,15 +62,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Add LLVM apt Repo - run: |- - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-21 main" - sudo apt update - - - name: Install APT dependencies - run: xargs sudo apt-get install -y --no-install-recommends < Aptfile - - name: Setup Ruby uses: ruby/setup-ruby@v1 with: @@ -80,8 +71,8 @@ jobs: - name: Render Templates run: bundle exec rake templates - - name: Compile Herb - run: bundle exec rake make + - name: Vendor Prism + run: bundle exec rake prism:vendor - name: Setup Cross-Ruby Configs run: bundle exec rake gem:prepare From 066c250da8a0e0fc677c10e4118c72b34637bdf1 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 20:41:27 +0100 Subject: [PATCH 09/10] Also try to compile for Ruby 4.0 --- herb.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/herb.gemspec b/herb.gemspec index d90f473c3..cfdac9d86 100644 --- a/herb.gemspec +++ b/herb.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://herb-tools.dev" spec.license = "MIT" - spec.required_ruby_version = [">= 3.0.0", "< 4.0"] + spec.required_ruby_version = ">= 3.0.0" spec.require_paths = ["lib"] spec.files = Dir[ From be631d7ba7c06132936f2df49fbe661b4cb2fefb Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sat, 20 Dec 2025 21:11:59 +0100 Subject: [PATCH 10/10] Update rake-cross-compiler --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 347faeba0..41d7cf8c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/marcoroth/rake-cross-compiler.git - revision: c886a66dd8e0957a201a8b629058dd3340f85a42 + revision: 0e6070af00050ce0fcb580e5478f92661dfe23e0 specs: rake-cross-compiler (0.0.1) rake (>= 13.0)