From a654b72c17d2342228295874a8b154a6a77d13df Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Tue, 24 Nov 2026 12:46:54 +0000 Subject: [PATCH] Add a nightly master image with modular GC enabled This commit adds a modular-gc variant alongside existing prod and debug builds. It uses `--with-modular-gc=/usr/local/lib/ruby/gc` and also builds the latest MMTk GC module from the ruby/ruby tree. Note: We've added `MMTK_LTO=0` to the MMtk build environment to stop clang building with `-march=native` when the clang and rustc llvm versions match. By default this Ruby will run as normal, but RUBY_GC_LIBRARY can be set to override the default GC. --- .github/workflows/build.yml | 40 ++++++++++++++++++++++++++----------- Dockerfile | 7 +++++++ README.md | 30 ++++++++++++++++++++++++++++ Rakefile | 4 ++-- install_ruby.sh | 8 ++++++++ 5 files changed, 75 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d302755..df240c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,6 +39,7 @@ jobs: outputs: ruby_sha: ${{ steps.ruby_sha.outputs.ruby_sha }} + variants: ${{ steps.variants.outputs.variants }} steps: - name: Resolve ruby_sha @@ -53,13 +54,22 @@ jobs: fi echo "ruby_sha=$ruby_sha" >> "$GITHUB_OUTPUT" + - name: Select image variants + id: variants + run: |- + if [ "$ruby_version" = master ]; then + echo 'variants=["", "-debug", "-modular-gc"]' >> "$GITHUB_OUTPUT" + else + echo 'variants=["", "-debug"]' >> "$GITHUB_OUTPUT" + fi + build: needs: prepare strategy: fail-fast: false matrix: - debug_suffix: ['', '-debug'] + variant_suffix: ${{ fromJSON(needs.prepare.outputs.variants) }} ubuntu_version: - resolute - noble @@ -71,7 +81,7 @@ jobs: env: ruby_sha: ${{ needs.prepare.outputs.ruby_sha }} ubuntu_version: "${{ matrix.ubuntu_version }}" - debug_suffix: ${{ matrix.debug_suffix }} + variant_suffix: ${{ matrix.variant_suffix }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -90,10 +100,15 @@ jobs: - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - run: | - if [ "${{ env.debug_suffix }}" = "-debug" ]; then - echo "cppflags=-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" >> $GITHUB_ENV - echo "optflags=-O3 -fno-inline" >> $GITHUB_ENV - fi + case "${{ env.variant_suffix }}" in + -debug) + echo "cppflags=-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" >> $GITHUB_ENV + echo "optflags=-O3 -fno-inline" >> $GITHUB_ENV + ;; + -modular-gc) + echo "modular_gc=mmtk" >> $GITHUB_ENV + ;; + esac - name: Build and push docker images run: |- @@ -105,6 +120,7 @@ jobs: arch=linux/${{ matrix.arch }} \ optflags="${{ env.optflags }}" \ cppflags="${{ env.cppflags }}" \ + modular_gc="${{ env.modular_gc }}" \ target=$target \ push_registries="rubylang ghcr.io/ruby" \ metadata_file="$RUNNER_TEMP/$target.json" && break @@ -116,7 +132,7 @@ jobs: - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: digests${{ matrix.debug_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }} + name: digests${{ matrix.variant_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }} path: ${{ runner.temp }}/digests/* if-no-files-found: error retention-days: 1 @@ -126,7 +142,7 @@ jobs: payload: | { "attachments": [{ - "text": "build ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.arch }} ${{ matrix.debug_suffix }} ", + "text": "build ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.arch }} ${{ matrix.variant_suffix }} ", "color": "danger" }] } @@ -138,7 +154,7 @@ jobs: strategy: fail-fast: false matrix: - debug_suffix: ['', '-debug'] + variant_suffix: ${{ fromJSON(needs.prepare.outputs.variants) }} ubuntu_version: - resolute - noble @@ -169,7 +185,7 @@ jobs: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: - pattern: digests${{ matrix.debug_suffix }}-${{ matrix.ubuntu_version }}-* + pattern: digests${{ matrix.variant_suffix }}-${{ matrix.ubuntu_version }}-* path: ${{ runner.temp }}/digests merge-multiple: true @@ -183,7 +199,7 @@ jobs: registry_name="$registry_name" \ ruby_version="${{ env.ruby_version }}" \ ubuntu_version="${{ matrix.ubuntu_version }}" \ - image_version_suffix=${{ matrix.debug_suffix }}$dev_suffix \ + image_version_suffix=${{ matrix.variant_suffix }}$dev_suffix \ digests="$digests" done done @@ -193,7 +209,7 @@ jobs: payload: | { "attachments": [{ - "text": "deploy_multiarch ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.debug_suffix }} ", + "text": "deploy_multiarch ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.variant_suffix }} ", "color": "danger" }] } diff --git a/Dockerfile b/Dockerfile index 597e071..26152ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,7 @@ COPY tmp/ruby /usr/src/ruby ARG optflags ARG debugflags ARG cppflags +ARG modular_gc RUN set -ex && \ # skip installing gem documentation @@ -159,6 +160,12 @@ COPY --from=build \ # Verify that the built/copied ruby can at least run (has necessary OS dependencies, etc). RUN /usr/local/bin/ruby -v +ARG modular_gc +RUN set -ex && \ + for gc in $modular_gc; do \ + RUBY_GC_LIBRARY=$gc /usr/local/bin/ruby -v -e 'GC.start'; \ + done + ### development ### FROM ruby AS development diff --git a/README.md b/README.md index 7074604..6431db0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256: - `rubylang/ruby:master-dev-resolute` - `rubylang/ruby:master-debug-resolute` - `rubylang/ruby:master-debug-dev-resolute` + - `rubylang/ruby:master-modular-gc-resolute` + - `rubylang/ruby:master-modular-gc-dev-resolute` - 4.0 - **`rubylang/ruby:latest`** - `rubylang/ruby:4.0-resolute` @@ -59,6 +61,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256: - `rubylang/ruby:master-dev-noble` - `rubylang/ruby:master-debug-noble` - `rubylang/ruby:master-debug-dev-noble` + - `rubylang/ruby:master-modular-gc-noble` + - `rubylang/ruby:master-modular-gc-dev-noble` - 4.0 - `rubylang/ruby:4.0-noble` - `rubylang/ruby:4.0.9-noble` @@ -76,6 +80,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256: - `rubylang/ruby:master-dev-jammy` - `rubylang/ruby:master-debug-jammy` - `rubylang/ruby:master-debug-dev-jammy` + - `rubylang/ruby:master-modular-gc-jammy` + - `rubylang/ruby:master-modular-gc-dev-jammy` - 4.0 - `rubylang/ruby:4.0-jammy` - `rubylang/ruby:4.0.9-jammy` @@ -95,6 +101,24 @@ Additional images are published for special purposes: - Nightly debug builds of master (e.g. `rubylang/ruby:master-debug-nightly-noble`) - EOL versions, for compatibility use only (e.g. `rubylang/ruby:3.2.11-noble`) +## Modular GC + +The `master-modular-gc` images contain Ruby master built with `--with-modular-gc=/usr/local/lib/ruby/gc` and the [MMTk](https://www.mmtk.io/) GC library. Ruby uses the built-in GC when `RUBY_GC_LIBRARY` is not set. Set `RUBY_GC_LIBRARY` to a library name to load that library: + +``` +docker run --rm -e RUBY_GC_LIBRARY=mmtk rubylang/ruby:master-modular-gc-resolute ruby -v +``` + +To use a custom GC, copy `librubygc..so` into `/usr/local/lib/ruby/gc/` and set `RUBY_GC_LIBRARY=`: + +``` +FROM rubylang/ruby:master-modular-gc-resolute +COPY librubygc.mygc.so /usr/local/lib/ruby/gc/ +ENV RUBY_GC_LIBRARY=mygc +``` + +The modular GC interface is internal to Ruby. Build the library from the same Ruby commit as the image. The `master-modular-gc--resolute` tag names that commit. Configure the Ruby source with `--with-modular-gc`, then run `make modular-gc MODULAR_GC=` in the build directory. This command writes `gc//librubygc..so` in the build directory. + ## Contributing The Dockerfile and build scripts live in the [ruby/docker-images](https://github.com/ruby/docker-images) repository. @@ -111,6 +135,12 @@ You can also specify a specific revision on the master branch: rake docker:build ruby_version=master:ce798d08de ``` +To build an image with modular GC enabled, list the GC libraries from Ruby's `gc/` directory in `modular_gc`: + +``` +rake docker:build ruby_version=master image_version_suffix=-modular-gc modular_gc=mmtk +``` + ### Triggering a build Builds can be triggered via GitHub Actions `workflow_dispatch`. Open the Actions tab, select the "Build Docker image with multi-arch" workflow, and run it with a `ruby_version` parameter (e.g. `4.0.9` or `master`). diff --git a/Rakefile b/Rakefile index 0af125c..c1bc928 100644 --- a/Rakefile +++ b/Rakefile @@ -276,7 +276,7 @@ namespace :docker do return ruby_version, tags end - desc "Build Docker image for Ruby (env: ruby_version, ubuntu_version, arch, image_version_suffix, tag_suffix, tag, cppflags, optflags, target, push_registries, metadata_file)" + desc "Build Docker image for Ruby (env: ruby_version, ubuntu_version, arch, image_version_suffix, tag_suffix, tag, cppflags, optflags, modular_gc, target, push_registries, metadata_file)" task :build do ruby_version = default_ruby_version unless ruby_version_exist?(ruby_version) @@ -317,7 +317,7 @@ namespace :docker do ruby_so_suffix = ruby_version.match(/\A(\d+\.\d+\.\d+)/)[1] build_args << "RUBY_SO_SUFFIX=#{ruby_so_suffix}" end - %w(cppflags optflags).each do |name| + %w(cppflags optflags modular_gc).each do |name| build_args << %Q(#{name}=#{ENV[name]}) if ENV.key?(name) end diff --git a/install_ruby.sh b/install_ruby.sh index c3c239b..ea3440d 100755 --- a/install_ruby.sh +++ b/install_ruby.sh @@ -99,6 +99,10 @@ fi --enable-zjit ) + if [ -n "$modular_gc" ]; then + configure_args+=(--with-modular-gc="$PREFIX/lib/ruby/gc") + fi + if [ -n "$cppflags" ]; then export cppflags=$cppflags else @@ -129,6 +133,10 @@ fi make -j "$(nproc)" make install + for gc in $modular_gc; do + MMTK_LTO=0 make install-modular-gc MODULAR_GC="$gc" MMTK_BUILD=release + done + popd rm -rf /tmp/ruby-build )