Skip to content

Commit 9193d2f

Browse files
committed
Fix precompiled gem not working on a different linux machine:
- I tried installing a gem precompiled on a CI machine in a completely different environment and the binary doesn't work. I have two different problems: 1. Same as on MacOS where `libruby.so` is linked on a path that doesn't exist. I fixed the issue the same way as I did on MacOS but tweaked the logic to modify the makfile (the previous regex wouldn't work if `-l$(LIBRUBYSO)` was in between other flags). 2. This one is more tricky and the solution is a bandaid. On ubuntu-24.04 (ubuntu-latest), the glibc version is 2.38, and it's relatively new. Any system using a older glibc version will not be able to use the precompiled binaries because glibc versions aren't backward compatible. In this commit, I modified the GitHub runner to use ubuntu 22.04, which has glibc to 2.35. This should allow slighltly older linux versions to install our precompiled gems. Ultimately, glibc 2.35 may still be too recent (released on 2022-02), and maybe a more acceptable version should be glibc 2.31 which was released in 2020. At least that's what Rake Compiler Dock uses and I haven't seen people complaining that they'd like the precompiled gems to support even older linux distro. We can't downgrade glibc to version 2.31, it will crash the CI machine. So I don't think we have any other way but to build a docker image and do the compilation in docker.
1 parent d9cd94d commit 9193d2f

File tree

10 files changed

+29
-25
lines changed

10 files changed

+29
-25
lines changed

.github/actions/easy_compile/dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28274,7 +28274,7 @@ function rubyBuilderURL(rubyVersion) {
2827428274
let platform = os.platform();
2827528275

2827628276
if (platform == "linux") {
28277-
platform = "ubuntu-24.04"; // Not great but this is a quick workaround
28277+
platform = "ubuntu-22.04"; // Not great but this is a quick workaround
2827828278
}
2827928279

2828028280
return `${rubyReleasesUrl}/ruby-${rubyVersion}/ruby-${rubyVersion}-${platform}-${os.arch()}.tar.gz`;

.github/actions/easy_compile/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function rubyBuilderURL(rubyVersion) {
7373
let platform = os.platform();
7474

7575
if (platform == "linux") {
76-
platform = "ubuntu-24.04"; // Not great but this is a quick workaround
76+
platform = "ubuntu-22.04"; // Not great but this is a quick workaround
7777
}
7878

7979
return `${rubyReleasesUrl}/ruby-${rubyVersion}/ruby-${rubyVersion}-${platform}-${os.arch()}.tar.gz`;

.github/workflows/e2e-dummy-gem.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: "Cross compile the gem on different ruby versions"
77
strategy:
88
matrix:
9-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
9+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
1010
runs-on: "${{ matrix.os }}"
1111
steps:
1212
- name: "Checkout code"
@@ -29,7 +29,7 @@ jobs:
2929
needs: compile
3030
strategy:
3131
matrix:
32-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
32+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
3333
rubies: ["3.4.7", "3.1.7"]
3434
type: ["cross", "native"]
3535
runs-on: "${{ matrix.os }}"
@@ -54,7 +54,7 @@ jobs:
5454
needs: test
5555
strategy:
5656
matrix:
57-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
57+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
5858
runs-on: "${{ matrix.os }}"
5959
steps:
6060
- name: "Checkout code"

.github/workflows/gem-compile.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
name: "Cross compile the gem on different ruby versions"
1515
strategy:
1616
matrix:
17-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
17+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
1818
runs-on: "${{ matrix.os }}"
1919
steps:
2020
- name: "Install gperf"
2121
if: ${{ matrix.os == 'windows-latest' }}
2222
run: choco install gperf
2323
- name: "Install gperf"
24-
if: ${{ matrix.os == 'ubuntu-latest' }}
24+
if: ${{ matrix.os == 'ubuntu-22.04' }}
2525
run: sudo apt-get -qy install gperf
2626
- name: "Checkout code"
2727
uses: "actions/checkout@v5"
@@ -43,7 +43,7 @@ jobs:
4343
needs: compile
4444
strategy:
4545
matrix:
46-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
46+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
4747
rubies: ["3.4.7", "3.1.7"]
4848
type: ["cross", "native"]
4949
runs-on: "${{ matrix.os }}"
@@ -68,7 +68,7 @@ jobs:
6868
needs: test
6969
strategy:
7070
matrix:
71-
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
71+
os: ["macos-latest", "ubuntu-22.04", "windows-latest"]
7272
runs-on: "${{ matrix.os }}"
7373
steps:
7474
- name: "Setup Ruby"

lib/easy_compile/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def clobber
9393
method_option "test-command", type: "string", required: false, desc: "The test command to run. Defaults to running `bundle exec rake test` and `bundle exec rake spec`."
9494
def ci_template
9595
# os = ["macos-latest", "macos-15-intel", "ubuntu-latest", "windows-latest"]
96-
os = ["macos-latest", "ubuntu-latest"] # Just this for now because the CI takes too long otherwise.
96+
os = ["macos-latest", "ubuntu-22.04"] # Just this for now because the CI takes too long otherwise.
9797

9898
ruby_requirements = compilation_task.gemspec.required_ruby_version
9999
latest_supported_ruby_version = RubySeries.latest_version_for_requirements(ruby_requirements)

lib/easy_compile/compilation_tasks.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def define_task(path)
8484
ext.cross_compile = true
8585
end
8686

87-
disable_shared if darwin?
87+
disable_shared unless Gem.win_platform?
8888
ensure
8989
self.binary_name = nil
9090
end
@@ -106,9 +106,13 @@ def disable_shared
106106
makefile_tasks.each do |task|
107107
task.enhance do
108108
makefile_content = File.read(task.name)
109-
makefile_content.sub!(/(LIBRUBYARG_SHARED = )(?:-l\$\(RUBY_SO_NAME\))(.*)/, '\1\2')
109+
makefile_content.match(/LIBRUBYARG_SHARED = (.*)/) do |match|
110+
shared_flags = match[1].split(" ")
111+
shared_flags.reject! { |flag| flag == "-l$(RUBY_SO_NAME)" }
112+
makefile_content.gsub!(/(LIBRUBYARG_SHARED = ).*/, "\\1#{shared_flags.join(' ')}")
110113

111-
File.write(task.name, makefile_content)
114+
File.write(task.name, makefile_content)
115+
end
112116
end
113117
end
114118
end

test/fixtures/expected_github_workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Cross compile the gem on different ruby versions"
1414
strategy:
1515
matrix:
16-
os: ["macos-latest", "ubuntu-latest"]
16+
os: ["macos-latest", "ubuntu-22.04"]
1717
runs-on: "${{ matrix.os }}"
1818
steps:
1919
- name: "Checkout code"
@@ -34,7 +34,7 @@ jobs:
3434
needs: compile
3535
strategy:
3636
matrix:
37-
os: ["macos-latest", "ubuntu-latest"]
37+
os: ["macos-latest", "ubuntu-22.04"]
3838
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
3939
type: ["cross", "native"]
4040
runs-on: "${{ matrix.os }}"
@@ -57,7 +57,7 @@ jobs:
5757
needs: test
5858
strategy:
5959
matrix:
60-
os: ["macos-latest", "ubuntu-latest"]
60+
os: ["macos-latest", "ubuntu-22.04"]
6161
runs-on: "${{ matrix.os }}"
6262
steps:
6363
- name: "Setup Ruby"

test/fixtures/expected_github_workflow_test_and_workdir.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Cross compile the gem on different ruby versions"
1414
strategy:
1515
matrix:
16-
os: ["macos-latest", "ubuntu-latest"]
16+
os: ["macos-latest", "ubuntu-22.04"]
1717
runs-on: "${{ matrix.os }}"
1818
steps:
1919
- name: "Checkout code"
@@ -36,7 +36,7 @@ jobs:
3636
needs: compile
3737
strategy:
3838
matrix:
39-
os: ["macos-latest", "ubuntu-latest"]
39+
os: ["macos-latest", "ubuntu-22.04"]
4040
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
4141
type: ["cross", "native"]
4242
runs-on: "${{ matrix.os }}"
@@ -62,7 +62,7 @@ jobs:
6262
needs: test
6363
strategy:
6464
matrix:
65-
os: ["macos-latest", "ubuntu-latest"]
65+
os: ["macos-latest", "ubuntu-22.04"]
6666
runs-on: "${{ matrix.os }}"
6767
steps:
6868
- name: "Setup Ruby"

test/fixtures/expected_github_workflow_test_command.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Cross compile the gem on different ruby versions"
1414
strategy:
1515
matrix:
16-
os: ["macos-latest", "ubuntu-latest"]
16+
os: ["macos-latest", "ubuntu-22.04"]
1717
runs-on: "${{ matrix.os }}"
1818
steps:
1919
- name: "Checkout code"
@@ -34,7 +34,7 @@ jobs:
3434
needs: compile
3535
strategy:
3636
matrix:
37-
os: ["macos-latest", "ubuntu-latest"]
37+
os: ["macos-latest", "ubuntu-22.04"]
3838
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
3939
type: ["cross", "native"]
4040
runs-on: "${{ matrix.os }}"
@@ -58,7 +58,7 @@ jobs:
5858
needs: test
5959
strategy:
6060
matrix:
61-
os: ["macos-latest", "ubuntu-latest"]
61+
os: ["macos-latest", "ubuntu-22.04"]
6262
runs-on: "${{ matrix.os }}"
6363
steps:
6464
- name: "Setup Ruby"

test/fixtures/expected_github_workflow_working_dir.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Cross compile the gem on different ruby versions"
1414
strategy:
1515
matrix:
16-
os: ["macos-latest", "ubuntu-latest"]
16+
os: ["macos-latest", "ubuntu-22.04"]
1717
runs-on: "${{ matrix.os }}"
1818
steps:
1919
- name: "Checkout code"
@@ -36,7 +36,7 @@ jobs:
3636
needs: compile
3737
strategy:
3838
matrix:
39-
os: ["macos-latest", "ubuntu-latest"]
39+
os: ["macos-latest", "ubuntu-22.04"]
4040
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
4141
type: ["cross", "native"]
4242
runs-on: "${{ matrix.os }}"
@@ -61,7 +61,7 @@ jobs:
6161
needs: test
6262
strategy:
6363
matrix:
64-
os: ["macos-latest", "ubuntu-latest"]
64+
os: ["macos-latest", "ubuntu-22.04"]
6565
runs-on: "${{ matrix.os }}"
6666
steps:
6767
- name: "Setup Ruby"

0 commit comments

Comments
 (0)