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

Fix compiling with libxml 2.12.x #209

Closed
wants to merge 1 commit into from

Conversation

skipkayhil
Copy link

Before:

❯ gem install libxml-ruby
Building native extensions. This could take a while...
ERROR:  Error installing libxml-ruby:
        ERROR: Failed to build gem native extension.

    current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
/home/hartley/.cache/asdf/installs/ruby/3.3.0/bin/ruby extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/opt/homebrew/opt/libxml2/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2,/usr/local/include,/usr/local/opt/libxml2/include/libxml2... yes
checking for xmlParseDoc() in -lxml2... yes
creating extconf.h
creating Makefile

current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
make DESTDIR\= sitearchdir\=./.gem.20231230-282081-ekb713 sitelibdir\=./.gem.20231230-282081-ekb713 clean

current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
make DESTDIR\= sitearchdir\=./.gem.20231230-282081-ekb713 sitelibdir\=./.gem.20231230-282081-ekb713
compiling libxml.c
In file included from ruby_libxml.h:13,
                 from libxml.c:1:
ruby_xml_encoding.h:12:27: error: unknown type name ‘xmlChar’
   12 | VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
      |                           ^~~~~~~
ruby_xml_encoding.h:12:48: error: unknown type name ‘xmlChar’
   12 | VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
      |                                                ^~~~~~~
ruby_xml_encoding.h:13:31: error: unknown type name ‘xmlChar’
   13 | VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
      |                               ^~~~~~~
ruby_xml_encoding.h:13:71: error: unknown type name ‘xmlChar’
   13 | VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
      |                                                                       ^~~~~~~
ruby_xml_encoding.h:15:60: error: unknown type name ‘xmlCharEncoding’
   15 | rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding);
      |                                                            ^~~~~~~~~~~~~~~
ruby_xml_encoding.h:16:41: error: unknown type name ‘xmlChar’
   16 | rb_encoding* rxml_figure_encoding(const xmlChar* xencoding);
      |                                         ^~~~~~~
In file included from ruby_libxml.h:14:
ruby_xml_attributes.h:9:27: error: unknown type name ‘xmlNodePtr’
    9 | VALUE rxml_attributes_new(xmlNodePtr xnode);
      |                           ^~~~~~~~~~
In file included from ruby_libxml.h:15:
ruby_xml_attr.h:9:22: error: unknown type name ‘xmlAttrPtr’
    9 | VALUE rxml_attr_wrap(xmlAttrPtr xattr);
      |                      ^~~~~~~~~~
In file included from ruby_libxml.h:16:
ruby_xml_attr_decl.h:9:27: error: unknown type name ‘xmlAttributePtr’
    9 | VALUE rxml_attr_decl_wrap(xmlAttributePtr xattribute);
      |                           ^~~~~~~~~~~~~~~
In file included from ruby_libxml.h:17:
ruby_xml_document.h:8:26: error: unknown type name ‘xmlDocPtr’; did you mean ‘xmlErrorPtr’?
    8 | VALUE rxml_document_wrap(xmlDocPtr xnode);
      |                          ^~~~~~~~~
      |                          xmlErrorPtr
ruby_xml_document.h:10:9: error: unknown type name ‘xmlChar’
   10 | typedef xmlChar * xmlCharPtr;
      |         ^~~~~~~
In file included from ruby_libxml.h:18:
ruby_xml_node.h:9:21: error: unknown type name ‘xmlNodePtr’
    9 | void rxml_node_mark(xmlNodePtr xnode);
      |                     ^~~~~~~~~~
ruby_xml_node.h:10:22: error: unknown type name ‘xmlNodePtr’
   10 | VALUE rxml_node_wrap(xmlNodePtr xnode);
      |                      ^~~~~~~~~~
ruby_xml_node.h:11:23: error: unknown type name ‘xmlNodePtr’
   11 | void rxml_node_manage(xmlNodePtr xnode, VALUE node);
      |                       ^~~~~~~~~~
ruby_xml_node.h:12:25: error: unknown type name ‘xmlNodePtr’
   12 | void rxml_node_unmanage(xmlNodePtr xnode, VALUE node);
      |                         ^~~~~~~~~~
In file included from ruby_libxml.h:19:
ruby_xml_namespace.h:9:27: error: unknown type name ‘xmlNsPtr’; did you mean ‘xmlCharPtr’?
    9 | VALUE rxml_namespace_wrap(xmlNsPtr xns);
      |                           ^~~~~~~~
      |                           xmlCharPtr
In file included from ruby_libxml.h:29:
ruby_xml_sax2_handler.h:6:8: error: unknown type name ‘xmlSAXHandler’
    6 | extern xmlSAXHandler rxml_sax_handler;
      |        ^~~~~~~~~~~~~
cc1: note: unrecognized command-line option ‘-Wno-self-assign’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-parentheses-equality’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-constant-logical-operand’ may have been intended to silence earlier diagnostics
make: *** [Makefile:248: libxml.o] Error 1

make failed, exit code 2

The errors were fixed locally by adding

  • an include for libxml/tree.h to ruby_xml_attributes.h
  • includes for libxml/xmlstring.h and libxml/encoding.h to ruby_xml_encoding.h

However, this approach generally seems brittle compared to including libxml2/parser.h in the entrypoint which includes all of these headers.


I really have no idea what I'm doing, I have basically no experience with C extensions 😅 any feedback is appreciated

Before:

```
❯ gem install libxml-ruby
Building native extensions. This could take a while...
ERROR:  Error installing libxml-ruby:
        ERROR: Failed to build gem native extension.

    current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
/home/hartley/.cache/asdf/installs/ruby/3.3.0/bin/ruby extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/opt/homebrew/opt/libxml2/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2,/usr/local/include,/usr/local/opt/libxml2/include/libxml2... yes
checking for xmlParseDoc() in -lxml2... yes
creating extconf.h
creating Makefile

current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
make DESTDIR\= sitearchdir\=./.gem.20231230-282081-ekb713 sitelibdir\=./.gem.20231230-282081-ekb713 clean

current directory: /home/hartley/.cache/asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/libxml-ruby-4.1.2/ext/libxml
make DESTDIR\= sitearchdir\=./.gem.20231230-282081-ekb713 sitelibdir\=./.gem.20231230-282081-ekb713
compiling libxml.c
In file included from ruby_libxml.h:13,
                 from libxml.c:1:
ruby_xml_encoding.h:12:27: error: unknown type name ‘xmlChar’
   12 | VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
      |                           ^~~~~~~
ruby_xml_encoding.h:12:48: error: unknown type name ‘xmlChar’
   12 | VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
      |                                                ^~~~~~~
ruby_xml_encoding.h:13:31: error: unknown type name ‘xmlChar’
   13 | VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
      |                               ^~~~~~~
ruby_xml_encoding.h:13:71: error: unknown type name ‘xmlChar’
   13 | VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
      |                                                                       ^~~~~~~
ruby_xml_encoding.h:15:60: error: unknown type name ‘xmlCharEncoding’
   15 | rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding);
      |                                                            ^~~~~~~~~~~~~~~
ruby_xml_encoding.h:16:41: error: unknown type name ‘xmlChar’
   16 | rb_encoding* rxml_figure_encoding(const xmlChar* xencoding);
      |                                         ^~~~~~~
In file included from ruby_libxml.h:14:
ruby_xml_attributes.h:9:27: error: unknown type name ‘xmlNodePtr’
    9 | VALUE rxml_attributes_new(xmlNodePtr xnode);
      |                           ^~~~~~~~~~
In file included from ruby_libxml.h:15:
ruby_xml_attr.h:9:22: error: unknown type name ‘xmlAttrPtr’
    9 | VALUE rxml_attr_wrap(xmlAttrPtr xattr);
      |                      ^~~~~~~~~~
In file included from ruby_libxml.h:16:
ruby_xml_attr_decl.h:9:27: error: unknown type name ‘xmlAttributePtr’
    9 | VALUE rxml_attr_decl_wrap(xmlAttributePtr xattribute);
      |                           ^~~~~~~~~~~~~~~
In file included from ruby_libxml.h:17:
ruby_xml_document.h:8:26: error: unknown type name ‘xmlDocPtr’; did you mean ‘xmlErrorPtr’?
    8 | VALUE rxml_document_wrap(xmlDocPtr xnode);
      |                          ^~~~~~~~~
      |                          xmlErrorPtr
ruby_xml_document.h:10:9: error: unknown type name ‘xmlChar’
   10 | typedef xmlChar * xmlCharPtr;
      |         ^~~~~~~
In file included from ruby_libxml.h:18:
ruby_xml_node.h:9:21: error: unknown type name ‘xmlNodePtr’
    9 | void rxml_node_mark(xmlNodePtr xnode);
      |                     ^~~~~~~~~~
ruby_xml_node.h:10:22: error: unknown type name ‘xmlNodePtr’
   10 | VALUE rxml_node_wrap(xmlNodePtr xnode);
      |                      ^~~~~~~~~~
ruby_xml_node.h:11:23: error: unknown type name ‘xmlNodePtr’
   11 | void rxml_node_manage(xmlNodePtr xnode, VALUE node);
      |                       ^~~~~~~~~~
ruby_xml_node.h:12:25: error: unknown type name ‘xmlNodePtr’
   12 | void rxml_node_unmanage(xmlNodePtr xnode, VALUE node);
      |                         ^~~~~~~~~~
In file included from ruby_libxml.h:19:
ruby_xml_namespace.h:9:27: error: unknown type name ‘xmlNsPtr’; did you mean ‘xmlCharPtr’?
    9 | VALUE rxml_namespace_wrap(xmlNsPtr xns);
      |                           ^~~~~~~~
      |                           xmlCharPtr
In file included from ruby_libxml.h:29:
ruby_xml_sax2_handler.h:6:8: error: unknown type name ‘xmlSAXHandler’
    6 | extern xmlSAXHandler rxml_sax_handler;
      |        ^~~~~~~~~~~~~
cc1: note: unrecognized command-line option ‘-Wno-self-assign’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-parentheses-equality’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-constant-logical-operand’ may have been intended to silence earlier diagnostics
make: *** [Makefile:248: libxml.o] Error 1

make failed, exit code 2
```

The errors were fixed locally by adding
- an include for libxml/tree.h to ruby_xml_attributes.h
- includes for libxml/xmlstring.h and libxml/encoding.h to
  ruby_xml_encoding.h

However, this approach generally seems brittle compared to including
libxml2/parser.h in the entrypoint which includes all of these headers.
@cfis
Copy link
Member

cfis commented Jan 6, 2024

Thanks for the report - your change seems reasonable but I would like to see why it is now required. Will take a look.

@cfis
Copy link
Member

cfis commented Jan 7, 2024

Hmm, so using Brew on MacOS with libxml2 2.12.3 I cannot duplicate this issue. I assume you are using the latest libxml-ruby version?

@jtojnar
Copy link

jtojnar commented Jan 7, 2024

I get the same errors as OP with 4.1.2 (same as OP) and libxml2 2.12.3 on NixOS.

See https://gitlab.gnome.org/GNOME/libxml2/-/issues/642 for discussion of issues in other projects.

cfis added a commit that referenced this pull request Jan 8, 2024
@cfis
Copy link
Member

cfis commented Jan 8, 2024

Ok, was able to reproduce on windows with mingw64. Used a slightly different approach that in this MR.

Thanks for the report!

@cfis cfis closed this Jan 8, 2024
@skipkayhil skipkayhil deleted the hm-fix-compiling-2-12 branch January 8, 2024 01:42
@skipkayhil
Copy link
Author

skipkayhil commented Jan 8, 2024

That works for me! I confirmed I am able to run rake compile on the master branch now.

Thanks for taking a look and apologies that my fix wasn't quite right 😄

@cfis
Copy link
Member

cfis commented Jan 8, 2024

No worries, will cut a release with the fix (after a few more fixes).

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