Avoid PATH-resolved echo in generated Makefiles - #748
Closed
kanutocd wants to merge 1 commit into
Closed
Conversation
- Ruby's mkmf generates an ECHO command that invokes `echo` through PATH. When rb-sys is run under Bundler, a RubyGems executable with that name may precede the system command and hijack native-extension build output. - Replace the PATH-resolved command in rb-sys-generated POSIX Makefiles with /bin/echo and add a regression test.
kanutocd
marked this pull request as ready for review
July 19, 2026 11:52
This was referenced Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ruby's
mkmfgenerates anECHOcommand that invokesechothroughPATH:Under some Bundler environments, a RubyGems executable named
echomay appear earlier inPATHthan the operating system'secho, causing native extension builds to invoke the wrong executable.This change replaces the PATH-resolved command in rb-sys-generated POSIX Makefiles with an absolute path:
The replacement is applied only for POSIX Makefiles (
unless $nmake), so native Windows builds are unaffected.Background
I originally encountered this while building the
kinogem, where the generated Makefile invoked the RubyGemsechoexecutable instead of the operating system'secho, resulting in incorrect build output.The issue was originally addressed downstream in
kino:yaroslav/kino#4
Since
rb-sysis responsible for generating the Makefile, it seemed more appropriate to apply the workaround here so downstream gems do not each need to patch their generated Makefiles independently.Tests
Added a regression test verifying that generated POSIX Makefiles contain:
The regression test is skipped on Windows.
Verified with:
bundle exec rake testbundle exec rubocop gem/lib/rb_sys/mkmf.rb gem/test/test_mkmf_echo.rbNotes
This addresses the issue within
rb-sys-generated Makefiles. The underlyingECHOdefinition originates from Ruby'smkmfand is now being addressed upstream in ruby/ruby#17975If the upstream fix is merged and becomes part of the minimum Ruby version supported by
rb-sys, this workaround may eventually become unnecessary.