Skip to content
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

extconf not adding an appropriate -I for gumbo-parser on macOS #2689

Closed
stevecheckoway opened this issue Nov 9, 2022 · 5 comments
Closed
Labels
state/needs-triage Inbox for non-installation-related bug reports or help requests

Comments

@stevecheckoway
Copy link
Contributor

Please describe the bug

When compiling the C extension on macOS, compiling gumbo.c fails because it cannot find nokogiri_gumbo.h. The real problem is that the -Ipath/to/gumbo-parser/include is not getting passed to the compiler.

Here's the relevant line in the mkmf.log file

block in append_cppflags: checking for whether -I/Users/steve/programming/nokogiri/tmp/x86_64-darwin21/nokogiri/3.1.2/ports/x86_64-darwin21/libgumbo/1.0.0-nokogiri/include is accepted as CPPFLAGS... -------------------- no

The underlying problem seems to be that the configuration test is using -Werror along with the unsupported warning -Wmisleading-indentation.

Here's the relevant portion of the log. Note that checking for the flag fails but that the last line shows checking for gumbo_parse_with_options() succeeds.

block in append_cppflags: checking for whether -I/Users/steve/programming/nokogiri/tmp/x86_64-darwin21/nokogiri/3.1.2/ports/x86_64-darwin21/libgumbo/1.0.0-nokogiri/include is accepted as CPPFLAGS... -------------------- no

DYLD_FALLBACK_LIBRARY_PATH=.:/nix/store/dmg6nslgajiyw8gqm59yc545yvg8axqx-ruby-3.1.2/lib "clang -I/nix/store/dmg6nslgajiyw8gqm59yc545yvg8axqx-ruby-3.1.2/include/ruby-3.1.0/x86_64-darwin21 -I/nix/store/dmg6nslgajiyw8gqm59yc545yvg8axqx-ruby-3.1.2/include/ruby-3.1.0/ruby/backward -I/nix/store/dmg6nslgajiyw8gqm59yc545yvg8axqx-ruby-3.1.2/include/ruby-3.1.0 -I../../../../ext/nokogiri -I/Users/steve/programming/nokogiri/ports/x86_64-darwin21/libxml2/2.10.3/include/libxml2 -I/Users/steve/programming/nokogiri/ports/x86_64-darwin21/libxslt/1.1.37/include -I/Users/steve/programming/nokogiri/ports/x86_64-darwin21/libxml2/2.10.3/include/libxml2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -fno-common -pipe  -I/Users/steve/programming/nokogiri/tmp/x86_64-darwin21/nokogiri/3.1.2/ports/x86_64-darwin21/libgumbo/1.0.0-nokogiri/include -Werror -c conftest.c"
error: unknown warning option '-Wmisleading-indentation'; did you mean '-Wbinding-in-condition'? [-Werror,-Wunknown-warning-option]
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

--------------------

have_func: checking for gumbo_parse_with_options() in nokogiri_gumbo.h... -------------------- yes

One work-around is to add

append_cflags("-Wno-unknown-warning-option") if darwin?

to extconf.rb. But maybe a better option would be to figure out where -Wmisleading-indentation (or-Werror) is coming from and fix that.

@stevecheckoway stevecheckoway added the state/needs-triage Inbox for non-installation-related bug reports or help requests label Nov 9, 2022
@flavorjones
Copy link
Member

@stevecheckoway Likely that compiler flag is coming from Ruby itself. Can you take a look at the value of RbConfig::CONFIG["CFLAGS"] and see if it's there?

If so, one possible cause is that you've upgraded clang or xcode or whatever since that Ruby executable was built, and so your current compiler doesn't understand flags that were used to compile Ruby with your previous compiler.

@stevecheckoway
Copy link
Contributor Author

Good thinking! I suspect that what happened is my Ruby was compiled by a newer compiler (via Nix) than what I have installed on that machine. (That particular machine is stuck on the last version of macOS that supports 32-bit binaries.) I'll head into the office (where that machine is located currently) and check.

@flavorjones
Copy link
Member

Regardless, it would be good to add that clang flag on darwin. Can you kick the tires on #2690?

@stevecheckoway
Copy link
Contributor Author

#2690 fixes the problem. You were correct about the cause:

irb(main):002:0> RbConfig::CONFIG["CFLAGS"].split
=>
["-fdeclspec",
 "-O3",
 "-fno-fast-math",
 "-ggdb3",
 "-Wall",
 "-Wextra",
 "-Wdeprecated-declarations",
 "-Wdivision-by-zero",
 "-Wimplicit-function-declaration",
 "-Wimplicit-int",
 "-Wmisleading-indentation",        # <---
 "-Wpointer-arith",
 "-Wshorten-64-to-32",
 "-Wwrite-strings",
 "-Wold-style-definition",
 "-Wmissing-noreturn",
 "-Wno-constant-logical-operand",
 "-Wno-long-long",
 "-Wno-missing-field-initializers",
 "-Wno-overlength-strings",
 "-Wno-parentheses-equality",
 "-Wno-self-assign",
 "-Wno-tautological-compare",
 "-Wno-unused-parameter",
 "-Wno-unused-value",
 "-Wunused-variable",
 "-Wextra-tokens",
 "-Wundef",
 "-fno-common",
 "-pipe"]

@flavorjones
Copy link
Member

👍 when that PR goes green I'll merge it. In the meantime you should be able to work around this by setting your environment variable CFLAGS because we do this in the extconf:

append_cflags(ENV["CFLAGS"].split) unless ENV["CFLAGS"].nil?

flavorjones added a commit that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state/needs-triage Inbox for non-installation-related bug reports or help requests
Projects
None yet
Development

No branches or pull requests

2 participants