postmodern / ruby-install

Installs Ruby, JRuby, TruffleRuby, or mruby
MIT License
1.89k stars 250 forks source link

CFLAGS unrecognized using 0.9.0 – working with 0.8.5 #451

Closed svoop closed 1 year ago

svoop commented 1 year ago

On a Gentoo Linux box, I try to install the system Ruby 3.1 using:

ruby-install --system $new_ruby -- --with-jemalloc CFLAGS="-march=core2 -msse4 -mcx16 -msahf -pipe -O2"

This worked fine up until rub-install-0.8.5, however, with 0.9.0 all the latter CFLAGS cause an error message similar to:

>>> Verifying ruby-3.1.4.tar.xz ... >>> Extracting ruby-3.1.4.tar.xz to /usr/local/src/ruby-3.1.4 ... >>> Configuring ruby 3.1.4 ... configure: error: unrecognized option: `-msse4'

It does work if I reduce CFLAGS to only -march=core2, but then I get a lot of warnings due to the missing optimization flag.

There's nothing in the CHANGELOG which might give a hint towards a regression, but maybe you have an idea whether a particular commit could be related.

Meanwhile, I'm not really sure what to provide in order to help debugging. However, I have a standby box to try things, just tell me what I can provide. Big thanks!!

svoop commented 1 year ago

Same with other Rubies such as 3.2.2

postmodern commented 1 year ago

Could you try reproducing this without ruby-install, but just run the ./configure --with-jemalloc CFLAGS="-march=core2 -msse4 -mcx16 -msahf -pipe -O2" command in the ruby src directory?

ruby-install uses "$@" and "${configure_opts[@]}" which should preserve the argument as a single argument. So I'm wondering if ./configure isn't recognizing CFLAGS as an env variable? https://github.com/postmodern/ruby-install/blob/master/bin/ruby-install#L5 https://github.com/postmodern/ruby-install/blob/master/share/ruby-install/ruby-install.sh#L217 https://github.com/postmodern/ruby-install/blob/master/share/ruby-install/ruby/functions.sh#L40

Also, as a workaround, you could try passing the env variable in at the front of the command like you normally would:

CFLAGS="..." ruby-install ruby -- ...
postmodern commented 1 year ago

Wait, I see the diff now between 0.8.5 and 0.9.0. I added the run method which logs the command and then executes it. Appears that by calling $@ (without quotes) to run the given arguments as a command, it causes implicit arg splitting. According to the Wooledge Wiki, a lone "$@" will preserve the arguments but also execute them as a command. https://mywiki.wooledge.org/Quotes

svoop commented 1 year ago

Just tried it on the Linux box with current main – works like a charm, thanks a bunch!! 🎉

Our design guy has the same problem on his Mac (he needs to set CPPFLAGS for some exotic stuff). I'd rather wait for your release of 0.9.1 and then nudge Homebrew than going from source there – any chance to see 0.9.1 soonish?

postmodern commented 1 year ago

Now to come up with a good test to verify that run doesn't implicitly word split it's arguments.