Skip to content

Use append_cflags instead of modifying CFLAGS directly#137

Merged
ioquatix merged 1 commit intosocketry:mainfrom
skatkov:compilation-error
May 22, 2025
Merged

Use append_cflags instead of modifying CFLAGS directly#137
ioquatix merged 1 commit intosocketry:mainfrom
skatkov:compilation-error

Conversation

@skatkov
Copy link
Contributor

@skatkov skatkov commented May 20, 2025

Linux system with latest GCC 15 can't compile this gem. See more #136

Types of Changes

Use append_cflags instead of modifying CFLAGS directly

According to this thread
https://inbox.vuxu.org/ruby-core/redmine.issue-21290.20250428190637.58020@ruby-lang.org/T/

ed25519 gem had a similar issue, and it was resolved by migrating to append_cflags.
RubyCrypto/ed25519@c1ee0e0

Let's move this gem to append_cflags as well. This approach is recommended over modifying CFLAGS since it ensures compatibility across different build environments by checking whether the flag is acceptable, and should not affect most systems.

In the meantime, it appears that Nobu has merged a wider fix to ruby itself. But this improvement will not hurt in the long term.

Testing

Building this branch with bake build works on my machine. At the same time, main branch is failing.

Contribution

@skatkov
Copy link
Contributor Author

skatkov commented May 21, 2025

@ioquatix would appreciate it if you can take a look here. I got blocked with one of my client projects due to this.

@ioquatix
Copy link
Member

I will sort it out today.

@ioquatix ioquatix force-pushed the compilation-error branch from 3d64dac to d085761 Compare May 22, 2025 04:36
@ioquatix ioquatix merged commit 7e10776 into socketry:main May 22, 2025
36 of 48 checks passed
@jakob-lilliemarck
Copy link

I am running in to this exact issue:

/home/jakob/.rvm/rubies/ruby-3.2.7/include/ruby-3.2.0/ruby/internal/scan_args.h:390:30: note: ‘bool’ is defined in header ‘<stdbool.h>’; this is probably fixable by adding ‘#include <stdbool.h>’
/home/jakob/.rvm/rubies/ruby-3.2.7/include/ruby-3.2.0/ruby/internal/scan_args.h:390:43: error: unknown type name ‘bool’

trying to bundle install a Ruby project using:

  • Fedora Linux 42 (KDE Plasma)
  • Ruby 3.2.3
  • GCC 15.1.1-2

The issue is with io-event:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/jakob/.rvm/gems/ruby-3.2.7/gems/io-event-1.1.7/ext
/home/jakob/.rvm/rubies/ruby-3.2.7/bin/ruby extconf.rb
checking for rb_ext_ractor_safe()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/jakob/.rvm/rubies/ruby-3.2.7/bin/$(RUBY_BASE_NAME)
/home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:490:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:583:in `try_link0'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:601:in `try_link'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:812:in `try_func'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:1116:in `block in have_func'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:989:in `block in checking_for'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:354:in `block (2 levels) in postpone'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:324:in `open'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:354:in `block in postpone'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:324:in `open'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:350:in `postpone'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:988:in `checking_for'
        from /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/mkmf.rb:1115:in `have_func'
        from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/jakob/.rvm/gems/ruby-3.2.7/extensions/x86_64-linux/3.2.0/io-event-1.1.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/jakob/.rvm/gems/ruby-3.2.7/gems/io-event-1.1.7 for inspection.
Results logged to /home/jakob/.rvm/gems/ruby-3.2.7/extensions/x86_64-linux/3.2.0/io-event-1.1.7/gem_make.out

  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/builder.rb:119:in `run'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/builder.rb:187:in `build_extension'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/builder.rb:221:in `block in build_extensions'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in `each'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in `build_extensions'
  /home/jakob/.rvm/rubies/ruby-3.2.7/lib/ruby/3.2.0/rubygems/installer.rb:846:in `build_extensions'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/source/rubygems.rb:200:in `install'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/installer/gem_installer.rb:54:in `install'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/installer/parallel_installer.rb:167:in `do_install'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/installer/parallel_installer.rb:158:in `block in worker_pool'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/worker.rb:62:in `apply_func'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/worker.rb:57:in `block in process_queue'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/worker.rb:54:in `loop'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/worker.rb:54:in `process_queue'
  /home/jakob/.rvm/gems/ruby-3.2.7/gems/bundler-2.4.7/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing io-event (1.1.7), and Bundler cannot continue.

In Gemfile:
  async-websocket was resolved to 0.8.0, which depends on
    async-io was resolved to 1.34.3, which depends on
      async was resolved to 2.5.0, which depends on
        io-event

Feels like I have installed every conceivable development tools package there is 🤷

@skatkov
Copy link
Contributor Author

skatkov commented Jun 12, 2025

Try updating a gem, fix already landed with a release.

@ioquatix ioquatix added this to the v1.10.1 milestone Jun 16, 2025
stanhu added a commit to stanhu/cbor-ruby that referenced this pull request Jul 23, 2025
This fixes a compilation issue in GCC 15 due `stdbool.h`
not being included when `-std=c99` is in use. This occurs because
the standard `configure` script shipped with Ruby does not properly
test for `stdbool.h` on C23 compilers. It needs to pick up this change:

https://cgit.git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6dcecb780a69bd208088d666b299e92aa7ae7e80

The `append_cflags` approach is recommended over modifying CFLAGS since
it ensures compatibility across different build environments by checking
whether the flag is acceptable.

Similar changes:

* socketry/io-event#137
* mongodb/bson-ruby#355

Closes cabo#27
stanhu added a commit to stanhu/ruby-magic that referenced this pull request Jul 27, 2025
This fixes a compilation issue in GCC 15 due `stdbool.h` not being
included when `-std=c99` is in use. This occurs because the standard
`configure` script shipped with older Ruby versions (prior to 3.4.5 and
3.3.9) do not properly test for `stdbool.h` on C23 compilers
(https://bugs.ruby-lang.org/issues/21340).

The `append_cflags` approach is recommended over modifying CFLAGS since
it ensures compatibility across different build environments by checking
whether the flag is acceptable.

Similar changes:

* socketry/io-event#137
* mongodb/bson-ruby#355

Closes kwilczynski#27
stanhu added a commit to stanhu/ruby-magic that referenced this pull request Jul 27, 2025
This fixes a compilation issue in GCC 15 due `stdbool.h` not being
included when `-std=c99` is in use. This occurs because the standard
`configure` script shipped with older Ruby versions (prior to 3.4.5 and
3.3.9) do not properly test for `stdbool.h` on C23 compilers
(https://bugs.ruby-lang.org/issues/21340).

The `append_cflags` approach is recommended over modifying CFLAGS since
it ensures compatibility across different build environments by checking
whether the flag is acceptable.

Similar changes:

* socketry/io-event#137
* mongodb/bson-ruby#355
stanhu added a commit to stanhu/cbor-ruby that referenced this pull request Jul 28, 2025
This fixes a compilation issue in GCC 15 due `stdbool.h`
not being included when `-std=c99` is in use. This occurs because
the standard `configure` script shipped with Ruby does not properly
test for `stdbool.h` on C23 compilers. It needs to pick up this change:

https://cgit.git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6dcecb780a69bd208088d666b299e92aa7ae7e80

The `append_cflags` approach is recommended over modifying CFLAGS since
it ensures compatibility across different build environments by checking
whether the flag is acceptable.

Similar changes:

* socketry/io-event#137
* mongodb/bson-ruby#355

Closes cabo#27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants