-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Append flags from environment variables. #629
Merged
Merged
Conversation
This file contains 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
According to the `mkmf.rb#init_mkmf`, there are command line options below. * `--with-cflags` to set the `cflags` * `--with-ldflags` to set the `ldflags` For example the following command compiles with the specified flags. Note that `MAKEFLAGS` is to print the compiler command lines. ``` $ MAKEFLAGS="V=1" \ bundle exec rake compile -- \ --with-cflags="-Wundef -Werror" \ --with-ldflags="-fstack-protector" ``` However, I couldn't find command line options to append the flags. And this commit is to append the `cflags` and `ldflags` by the environment variables. ``` $ MAKEFLAGS="V=1" \ RUBY_OPENSSL_EXTCFLAGS="-Wundef -Werror" \ RUBY_OPENSSL_EXTLDFLAGS="-fstack-protector" \ bundle exec rake compile ```
faa9fce
to
b551eb8
Compare
Here is my test log on Fedora 37. The appended cflags and ldflags are used in the gcc commands below.
|
Nice work! |
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.
According to the
mkmf.rb#init_mkmf
, there are command line options below.--with-cflags
to set thecflags
--with-ldflags
to set theldflags
For example the following command compiles with the specified flags. Note that
MAKEFLAGS
is to print the compiler command lines.However, I couldn't find command line options to append the flags. And this
commit is to append the
cflags
andldflags
by the environment variables.Details
The implementation was inspired by Nokogiri project.
https://github.com/sparklemotion/nokogiri/blob/30e965809c4c55b191c5c9f3a2cc5a289fce4681/ext/nokogiri/extconf.rb#L648-L651
However, I wanted to avoid the
CFLAGS
was loaded unintentionally. Because I seeCFLAGS
andLDFLAGS
are already set in the build environment in Fedora project. Those are used to set the flags, not to append. So, I used the prefixRUBY_OPENSSL_
. I also wanted to clarify that the value is used not to set but to append to the existing cflags coming from therbconfig.rb
. It seems theEXTLDFLAGS
exists in the purpose of appendng the flags in thetemplate/Makefile.in
in ruby/ruby. So, I chose theRUBY_OPENSSL_EXTCFLAGS
andRUBY_OPENSSL_EXTLDFLAGS
.You can also add your preferred debug flags like this.