Skip to content

Commit 0d85b96

Browse files
authored
Merge pull request #151 from rake-compiler/flavorjones-choose-ruby-version-sh
feat: allow easier selection of the ruby run in the container
2 parents cc84689 + 466effd commit 0d85b96

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,42 @@ Other environment variables can be set or passed through to the container like t
358358
RakeCompilerDock.sh "rake cross native gem OPENSSL_VERSION=#{ENV['OPENSSL_VERSION']}"
359359
```
360360

361+
### Choosing the version of ruby to run in the build container
362+
363+
There are [multiple versions of Ruby installed in the build container](https://github.com/rake-compiler/rake-compiler-dock/blob/d3e6b44916d9d63d4c431b8c749a2c58bf1fe8e8/Dockerfile.mri.erb#L77). The latest version will be the default, but you may need to choose a different version to run during your build process.
364+
365+
You can do this by passing a `ruby:` keyword argument to `RakeCompilerDock.sh`:
366+
367+
```ruby
368+
RakeCompilerDock.sh "ruby -v"
369+
# => ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
370+
371+
RakeCompilerDock.sh "ruby -v", ruby: "3.1.6"
372+
# => ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]48d4efcb85) +PRISM [x86_64-linux]
373+
```
374+
375+
Or by setting the environment variable `RCD_RUBY_VERSION`:
376+
377+
``` sh
378+
$ rake-compiler-dock bash -c "ruby -v"
379+
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
380+
381+
$ RCD_RUBY_VERSION=3.1.6 rake-compiler-dock bash -c "ruby -v"
382+
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
383+
```
384+
385+
Or by running `rbenv shell` in the command:
386+
387+
``` ruby
388+
RakeCompilerDock.sh "rbenv shell 3.1.6 && ruby -v", platform: "x86_64-linux-gnu"
389+
# => ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
390+
```
391+
392+
``` sh
393+
$ rake-compiler-dock bash -c "rbenv shell 3.1.6 && ruby -v"
394+
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
395+
```
396+
361397
### Choosing specific Ruby versions to support
362398

363399
If you only want to precompile for certain Ruby versions, you can specify those versions by overwriting the `RUBY_CC_VERSION` environment variable.

build/mk_musl_cross.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ GCC_CONFIG += --disable-libquadmath --disable-decimal-float
2929
GCC_CONFIG += --disable-multilib
3030
EOF
3131

32-
make -j$(nproc) install
32+
make -j$(nproc) install LINUX_HEADERS_SITE=http://mirrors.2f30.org/sabotage/tarballs/
3333

3434
popd
3535

build/sudoers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Defaults env_keep += "http_proxy https_proxy ftp_proxy GEM_PRIVATE_KEY_PASSPHRASE RCD_HOST_RUBY_PLATFORM RCD_HOST_RUBY_VERSION RCD_IMAGE RUBY_CC_VERSION LD_LIBRARY_PATH DEVTOOLSET_ROOTPATH SOURCE_DATE_EPOCH"
1+
Defaults env_keep += "http_proxy https_proxy ftp_proxy GEM_PRIVATE_KEY_PASSPHRASE RCD_HOST_RUBY_PLATFORM RCD_HOST_RUBY_VERSION RCD_IMAGE RUBY_CC_VERSION LD_LIBRARY_PATH DEVTOOLSET_ROOTPATH SOURCE_DATE_EPOCH RBENV_VERSION"

lib/rake_compiler_dock/starter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def exec(*args)
4141
user = options.fetch(:username){ current_user }
4242
group = options.fetch(:groupname){ current_group }
4343

44+
ruby_version = options[:ruby] || ENV['RCD_RUBY_VERSION']
45+
rbenv_opts = if ruby_version
46+
["-e", "RBENV_VERSION=#{ruby_version}"]
47+
end
48+
4449
platforms(options).split(" ").each do |platform|
4550
image_name = container_image_name(options.merge(platform: platform))
4651

@@ -73,6 +78,7 @@ def exec(*args)
7378
"-e", "RCD_HOST_RUBY_PLATFORM=#{RUBY_PLATFORM}",
7479
"-e", "RCD_HOST_RUBY_VERSION=#{RUBY_VERSION}",
7580
"-e", "RCD_IMAGE=#{image_name}",
81+
*rbenv_opts,
7682
"-w", make_valid_path(workdir),
7783
*docker_opts,
7884
image_name,

test/test_environment_variables.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ def test_SOURCE_DATE_EPOCH
8585
end
8686
end
8787

88+
class UsingWrapperSpecifyingRuby < UsingWrapper
89+
include Common
90+
91+
def invocation(command)
92+
idir = File.join(File.dirname(__FILE__), '../lib')
93+
"RCD_RUBY_VERSION=3.1.6 RCD_PLATFORM=#{TEST_PLATFORM} RCD_RUBYVM=#{IS_JRUBY ? 'jruby' : 'mri'} #{RbConfig::CONFIG['RUBY_INSTALL_NAME']} -I#{idir.inspect} bin/rake-compiler-dock bash -c '#{command}'"
94+
end
95+
96+
def test_RUBY_VERSION
97+
assert_equal "3.1.6", rcd_env['RBENV_VERSION']
98+
end
99+
end
100+
88101
class AsIfContinuousIntegration < Test::Unit::TestCase
89102
include Common
90103

0 commit comments

Comments
 (0)