From 5060d0f73cd3c9b8e6c11199359eb8d09c8130e0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 31 Aug 2026 16:29:08 +0200 Subject: [PATCH 1/4] Use the cflags configure variable for the -std=gnu17 workaround Exporting CFLAGS overrides Ruby's default optflags/debugflags/warnflags, notably losing -O3 and silently producing a much slower (-O0) Ruby. The cflags configure variable is appended to those defaults instead. Keep prepending to CFLAGS when the user already overrides CFLAGS, since configure ignores cflags when CFLAGS is given. Co-Authored-By: Claude Fable 5 --- bin/ruby-build | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/ruby-build b/bin/ruby-build index 52fc7e0bc8..546e81a5a3 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -748,7 +748,17 @@ build_package_standard() { # # TODO: Consider changing this to check for GCC v15 specifically # rather than inspecting the OS itself. - export CFLAGS="-std=gnu17 $CFLAGS" + if [ "${CFLAGS+defined}" ]; then + # If the user overrides CFLAGS they are responsible for it. + # The usual trap is specifying no `-O` flag and getting a `-O0` slow build. + export CFLAGS="-std=gnu17 $CFLAGS" + else + # Use the `cflags` configure variable, which Ruby's configure appends to + # its default optflags/debugflags/warnflags, unlike CFLAGS which would + # override them and notably lose the -O3, producing a much slower Ruby. + # configure ignores `cflags` when CFLAGS is given, hence the branch above. + export cflags="-std=gnu17 $cflags" + fi fi # ./configure --prefix=/path/to/ruby # shellcheck disable=SC2086,SC2153 From 692136ba520ece84ae88229fde339ec0f161531e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 31 Aug 2026 16:39:48 +0200 Subject: [PATCH 2/4] Let CFLAGS override everything, it's the purpose of CFLAGS --- bin/ruby-build | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/bin/ruby-build b/bin/ruby-build index 546e81a5a3..d7f39aa0ca 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -748,17 +748,11 @@ build_package_standard() { # # TODO: Consider changing this to check for GCC v15 specifically # rather than inspecting the OS itself. - if [ "${CFLAGS+defined}" ]; then - # If the user overrides CFLAGS they are responsible for it. - # The usual trap is specifying no `-O` flag and getting a `-O0` slow build. - export CFLAGS="-std=gnu17 $CFLAGS" - else - # Use the `cflags` configure variable, which Ruby's configure appends to - # its default optflags/debugflags/warnflags, unlike CFLAGS which would - # override them and notably lose the -O3, producing a much slower Ruby. - # configure ignores `cflags` when CFLAGS is given, hence the branch above. - export cflags="-std=gnu17 $cflags" - fi + + # Use the cflags configure variable, which Ruby's configure appends to + # its default optflags/debugflags/warnflags, unlike CFLAGS which would + # override them and notably lose the -O3, producing a -O0 Ruby. + export cflags="-std=gnu17 $cflags" fi # ./configure --prefix=/path/to/ruby # shellcheck disable=SC2086,SC2153 From 7177e5c1b310e485285f2ce14b785f15ea008d5b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 31 Aug 2026 16:29:31 +0200 Subject: [PATCH 3/4] Clarify that RUBY_CFLAGS overrides Ruby's default CFLAGS "Additional" was misleading: passing CFLAGS to Ruby's configure replaces the default optflags/debugflags/warnflags, so e.g. RUBY_CFLAGS=-march=native silently builds an unoptimized (-O0) Ruby. Document the overriding semantics and point to RUBY_CONFIGURE_OPTS=cflags=... for adding flags. Co-Authored-By: Claude Fable 5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7581776e5c..20e1495bc0 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ The build process may be configured through the following environment variables: | `RUBY_BUILD_ROOT` | The path prefix to search for build definitions files. *Deprecated:* use `RUBY_BUILD_DEFINITIONS`| | `RUBY_BUILD_VENDOR_OPENSSL` | Build and vendor openssl even if the system openssl is compatible | | `CC` | Path to the C compiler. | -| `RUBY_CFLAGS` | Additional `CFLAGS` options (_e.g.,_ to override `-O3`). | +| `RUBY_CFLAGS` | Overrides Ruby's default `CFLAGS`, including `-O3` (beware: without a `-O` flag Ruby is built unoptimized). To add flags, use `RUBY_CONFIGURE_OPTS=cflags=...` instead | | `CONFIGURE_OPTS` | Additional `./configure` options. | | `MAKE` | Custom `make` command (_e.g.,_ `gmake`). | | `MAKE_OPTS` / `MAKEOPTS` | Additional `make` options. | From 5b39cda85121ff9123a9fd98ada0b0b33158873c Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 31 Aug 2026 16:32:26 +0200 Subject: [PATCH 4/4] Treat the dev version as newer than any release in normalize_semver normalize_semver("dev") returned 0, so ruby-dev was treated as older than any released version and version-gated workarounds misfired. Notably the Fedora 42+ -std=gnu17 workaround for Ruby < 3.2 was applied to ruby-dev builds, which do not need it. Co-Authored-By: Claude Fable 5 --- bin/ruby-build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/ruby-build b/bin/ruby-build index d7f39aa0ca..1cecfbb820 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -1173,7 +1173,11 @@ homebrew_openssl_versions() { # Example: 3.1.23 -> 30123 # See also osx_version, require_java normalize_semver() { - awk -F. '{print $1 * 10000 + $2 * 100 + $3}' <<<"$1" + if [ "$1" = "dev" ]; then + echo 99999999 + else + awk -F. '{print $1 * 10000 + $2 * 100 + $3}' <<<"$1" + fi } # Checks if system OpenSSL does NOT satisfy the version requirement