From 5187f69ceaa7c174e8158861f01bd596203a48fa Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 27 Mar 2026 15:23:00 +0100 Subject: [PATCH 1/4] Add CI job to build C sources with various compiler versions * See https://github.com/ruby/prism/issues/4048 --- .github/workflows/main.yml | 12 ++++++++++++ Rakefile | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6b3888f57d..24a76ff250 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -174,6 +174,18 @@ jobs: env: PRISM_BUILD_MINIMAL: "1" + build-with-various-compilers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + - name: Build with various compilers + run: bundle exec rake build_in_docker + build-java: runs-on: ubuntu-latest env: diff --git a/Rakefile b/Rakefile index eb96249985..22c0699cb6 100644 --- a/Rakefile +++ b/Rakefile @@ -76,3 +76,21 @@ namespace :build do desc "Build a development version of the gem" task dev: ["build:dev_version_set", "build", "build:dev_version_clear"] end + +task :build_in_docker => :templates do + # Versions from https://github.com/ruby/ruby/blob/master/.github/workflows/compilers.yml + compilers = (7..15).map { |v| "gcc-#{v}" } + compilers.each do |compiler| + dockerfile = <<~DOCKERFILE + FROM ghcr.io/ruby/ruby-ci-image:#{compiler} + USER root + ADD . /prism + WORKDIR /prism + RUN #{compiler} --version + RUN make CC=#{compiler} + DOCKERFILE + File.write 'Dockerfile', dockerfile + sh "docker build ." + rm 'Dockerfile' + end +end From 2908c1c6c586b187f5dda6a3f946420ad2002f7f Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 6 Apr 2026 14:47:12 +0200 Subject: [PATCH 2/4] Fix array-bounds error with GCC 9 * In file included from /usr/include/string.h:535, from include/prism/internal/arena.h:12, from src/prism.c:6: In function 'memset', inlined from 'lex_mode_push_regexp' at src/prism.c:290:5: .../string_fortified.h:59:10: error: '__builtin_memset' offset [26, 34] from the object at 'lex_mode' is out of the bounds of referenced subobject 'breakpoints' with type 'uint8_t[7]' {aka 'unsigned char[7]'} at offset 18 [-Werror=array-bounds] --- include/prism/internal/parser.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/prism/internal/parser.h b/include/prism/internal/parser.h index 3afe226757..4320cf4029 100644 --- a/include/prism/internal/parser.h +++ b/include/prism/internal/parser.h @@ -9,6 +9,7 @@ #include "prism/internal/list.h" #include "prism/internal/options.h" #include "prism/internal/static_literals.h" +#include "prism/internal/strpbrk.h" #include "prism/ast.h" #include "prism/line_offset_list.h" @@ -168,7 +169,7 @@ typedef struct pm_lex_mode { * This is the character set that should be used to delimit the * tokens within the list. */ - uint8_t breakpoints[11]; + uint8_t breakpoints[PM_STRPBRK_CACHE_SIZE]; } list; struct { @@ -190,7 +191,7 @@ typedef struct pm_lex_mode { * This is the character set that should be used to delimit the * tokens within the regular expression. */ - uint8_t breakpoints[7]; + uint8_t breakpoints[PM_STRPBRK_CACHE_SIZE]; } regexp; struct { @@ -223,7 +224,7 @@ typedef struct pm_lex_mode { * This is the character set that should be used to delimit the * tokens within the string. */ - uint8_t breakpoints[7]; + uint8_t breakpoints[PM_STRPBRK_CACHE_SIZE]; } string; struct { From de70cd3052270ce469b18444eee80402f01032a0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 6 Apr 2026 18:17:53 +0200 Subject: [PATCH 3/4] Use docker.io gcc images to speed up the CI job by using smaller images * These do not have ruby pre-installed, so we set SOEXT explicitly. --- Rakefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 22c0699cb6..c2db3cf3db 100644 --- a/Rakefile +++ b/Rakefile @@ -79,15 +79,14 @@ end task :build_in_docker => :templates do # Versions from https://github.com/ruby/ruby/blob/master/.github/workflows/compilers.yml - compilers = (7..15).map { |v| "gcc-#{v}" } - compilers.each do |compiler| + versions = (7..15).to_a + versions.each do |version| dockerfile = <<~DOCKERFILE - FROM ghcr.io/ruby/ruby-ci-image:#{compiler} - USER root + FROM docker.io/library/gcc:#{version} ADD . /prism WORKDIR /prism - RUN #{compiler} --version - RUN make CC=#{compiler} + RUN gcc --version + RUN make SOEXT=so DOCKERFILE File.write 'Dockerfile', dockerfile sh "docker build ." From 008ec467c726ada08e81ce4745043141c471f32b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 6 Apr 2026 18:57:50 +0200 Subject: [PATCH 4/4] Speedup build_in_docker by only copying the necessary files --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index c2db3cf3db..421a4df697 100644 --- a/Rakefile +++ b/Rakefile @@ -83,7 +83,9 @@ task :build_in_docker => :templates do versions.each do |version| dockerfile = <<~DOCKERFILE FROM docker.io/library/gcc:#{version} - ADD . /prism + COPY Makefile /prism/ + COPY src /prism/src + COPY include /prism/include WORKDIR /prism RUN gcc --version RUN make SOEXT=so