Nokogiri_precompiled_aarch64_dedshit 1.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +44 -0
  3. data/LICENSE-DEPENDENCIES.md +2224 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +287 -0
  6. data/bin/nokogiri +131 -0
  7. data/dependencies.yml +41 -0
  8. data/ext/java/nokogiri/Html4Document.java +157 -0
  9. data/ext/java/nokogiri/Html4ElementDescription.java +133 -0
  10. data/ext/java/nokogiri/Html4EntityLookup.java +63 -0
  11. data/ext/java/nokogiri/Html4SaxParserContext.java +289 -0
  12. data/ext/java/nokogiri/Html4SaxPushParser.java +213 -0
  13. data/ext/java/nokogiri/NokogiriService.java +613 -0
  14. data/ext/java/nokogiri/XmlAttr.java +154 -0
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +119 -0
  16. data/ext/java/nokogiri/XmlCdata.java +60 -0
  17. data/ext/java/nokogiri/XmlComment.java +77 -0
  18. data/ext/java/nokogiri/XmlDocument.java +705 -0
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +163 -0
  20. data/ext/java/nokogiri/XmlDtd.java +516 -0
  21. data/ext/java/nokogiri/XmlElement.java +44 -0
  22. data/ext/java/nokogiri/XmlElementContent.java +412 -0
  23. data/ext/java/nokogiri/XmlElementDecl.java +148 -0
  24. data/ext/java/nokogiri/XmlEntityDecl.java +151 -0
  25. data/ext/java/nokogiri/XmlEntityReference.java +79 -0
  26. data/ext/java/nokogiri/XmlNamespace.java +193 -0
  27. data/ext/java/nokogiri/XmlNode.java +1938 -0
  28. data/ext/java/nokogiri/XmlNodeSet.java +463 -0
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +79 -0
  30. data/ext/java/nokogiri/XmlReader.java +615 -0
  31. data/ext/java/nokogiri/XmlRelaxng.java +133 -0
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +329 -0
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +288 -0
  34. data/ext/java/nokogiri/XmlSchema.java +423 -0
  35. data/ext/java/nokogiri/XmlSyntaxError.java +137 -0
  36. data/ext/java/nokogiri/XmlText.java +90 -0
  37. data/ext/java/nokogiri/XmlXpathContext.java +305 -0
  38. data/ext/java/nokogiri/XsltStylesheet.java +368 -0
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +13 -0
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +27 -0
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +178 -0
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +99 -0
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +140 -0
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +65 -0
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +339 -0
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +817 -0
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +228 -0
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +110 -0
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +86 -0
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +107 -0
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +62 -0
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +165 -0
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +50 -0
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +37 -0
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +70 -0
  57. data/ext/java/nokogiri/internals/ParserContext.java +262 -0
  58. data/ext/java/nokogiri/internals/ReaderNode.java +564 -0
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +865 -0
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +50 -0
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +174 -0
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +11 -0
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +265 -0
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +40 -0
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +122 -0
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +178 -0
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +43 -0
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +106 -0
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +278 -0
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +664 -0
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +45 -0
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +45 -0
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +388 -0
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +308 -0
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +47 -0
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +51 -0
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +51 -0
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +50 -0
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +660 -0
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +194 -0
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +77 -0
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +45 -0
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +325 -0
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +106 -0
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +86 -0
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +181 -0
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +87 -0
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +452 -0
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +52 -0
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +190 -0
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +540 -0
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1712 -0
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +737 -0
  94. data/ext/nokogiri/depend +38 -0
  95. data/ext/nokogiri/extconf.rb +1086 -0
  96. data/ext/nokogiri/gumbo.c +594 -0
  97. data/ext/nokogiri/html4_document.c +167 -0
  98. data/ext/nokogiri/html4_element_description.c +294 -0
  99. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  100. data/ext/nokogiri/html4_sax_parser_context.c +116 -0
  101. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  102. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  103. data/ext/nokogiri/nokogiri.c +265 -0
  104. data/ext/nokogiri/nokogiri.h +235 -0
  105. data/ext/nokogiri/test_global_handlers.c +42 -0
  106. data/ext/nokogiri/xml_attr.c +103 -0
  107. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  108. data/ext/nokogiri/xml_cdata.c +57 -0
  109. data/ext/nokogiri/xml_comment.c +62 -0
  110. data/ext/nokogiri/xml_document.c +689 -0
  111. data/ext/nokogiri/xml_document_fragment.c +44 -0
  112. data/ext/nokogiri/xml_dtd.c +210 -0
  113. data/ext/nokogiri/xml_element_content.c +128 -0
  114. data/ext/nokogiri/xml_element_decl.c +69 -0
  115. data/ext/nokogiri/xml_encoding_handler.c +104 -0
  116. data/ext/nokogiri/xml_entity_decl.c +112 -0
  117. data/ext/nokogiri/xml_entity_reference.c +50 -0
  118. data/ext/nokogiri/xml_namespace.c +186 -0
  119. data/ext/nokogiri/xml_node.c +2426 -0
  120. data/ext/nokogiri/xml_node_set.c +496 -0
  121. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  122. data/ext/nokogiri/xml_reader.c +794 -0
  123. data/ext/nokogiri/xml_relax_ng.c +164 -0
  124. data/ext/nokogiri/xml_sax_parser.c +316 -0
  125. data/ext/nokogiri/xml_sax_parser_context.c +283 -0
  126. data/ext/nokogiri/xml_sax_push_parser.c +166 -0
  127. data/ext/nokogiri/xml_schema.c +260 -0
  128. data/ext/nokogiri/xml_syntax_error.c +85 -0
  129. data/ext/nokogiri/xml_text.c +48 -0
  130. data/ext/nokogiri/xml_xpath_context.c +415 -0
  131. data/ext/nokogiri/xslt_stylesheet.c +363 -0
  132. data/gumbo-parser/CHANGES.md +63 -0
  133. data/gumbo-parser/Makefile +111 -0
  134. data/gumbo-parser/THANKS +27 -0
  135. data/gumbo-parser/src/Makefile +34 -0
  136. data/gumbo-parser/src/README.md +41 -0
  137. data/gumbo-parser/src/ascii.c +75 -0
  138. data/gumbo-parser/src/ascii.h +115 -0
  139. data/gumbo-parser/src/attribute.c +42 -0
  140. data/gumbo-parser/src/attribute.h +17 -0
  141. data/gumbo-parser/src/char_ref.c +22225 -0
  142. data/gumbo-parser/src/char_ref.h +29 -0
  143. data/gumbo-parser/src/char_ref.rl +2154 -0
  144. data/gumbo-parser/src/error.c +626 -0
  145. data/gumbo-parser/src/error.h +148 -0
  146. data/gumbo-parser/src/foreign_attrs.c +104 -0
  147. data/gumbo-parser/src/foreign_attrs.gperf +27 -0
  148. data/gumbo-parser/src/insertion_mode.h +33 -0
  149. data/gumbo-parser/src/macros.h +91 -0
  150. data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
  151. data/gumbo-parser/src/parser.c +4878 -0
  152. data/gumbo-parser/src/parser.h +41 -0
  153. data/gumbo-parser/src/replacement.h +33 -0
  154. data/gumbo-parser/src/string_buffer.c +103 -0
  155. data/gumbo-parser/src/string_buffer.h +68 -0
  156. data/gumbo-parser/src/string_piece.c +48 -0
  157. data/gumbo-parser/src/svg_attrs.c +174 -0
  158. data/gumbo-parser/src/svg_attrs.gperf +77 -0
  159. data/gumbo-parser/src/svg_tags.c +137 -0
  160. data/gumbo-parser/src/svg_tags.gperf +55 -0
  161. data/gumbo-parser/src/tag.c +223 -0
  162. data/gumbo-parser/src/tag_lookup.c +382 -0
  163. data/gumbo-parser/src/tag_lookup.gperf +170 -0
  164. data/gumbo-parser/src/tag_lookup.h +13 -0
  165. data/gumbo-parser/src/token_buffer.c +79 -0
  166. data/gumbo-parser/src/token_buffer.h +71 -0
  167. data/gumbo-parser/src/token_type.h +17 -0
  168. data/gumbo-parser/src/tokenizer.c +3463 -0
  169. data/gumbo-parser/src/tokenizer.h +112 -0
  170. data/gumbo-parser/src/tokenizer_states.h +339 -0
  171. data/gumbo-parser/src/utf8.c +245 -0
  172. data/gumbo-parser/src/utf8.h +164 -0
  173. data/gumbo-parser/src/util.c +66 -0
  174. data/gumbo-parser/src/util.h +34 -0
  175. data/gumbo-parser/src/vector.c +111 -0
  176. data/gumbo-parser/src/vector.h +45 -0
  177. data/lib/nokogiri/class_resolver.rb +67 -0
  178. data/lib/nokogiri/css/node.rb +54 -0
  179. data/lib/nokogiri/css/parser.rb +770 -0
  180. data/lib/nokogiri/css/parser.y +277 -0
  181. data/lib/nokogiri/css/parser_extras.rb +96 -0
  182. data/lib/nokogiri/css/syntax_error.rb +9 -0
  183. data/lib/nokogiri/css/tokenizer.rb +155 -0
  184. data/lib/nokogiri/css/tokenizer.rex +56 -0
  185. data/lib/nokogiri/css/xpath_visitor.rb +359 -0
  186. data/lib/nokogiri/css.rb +66 -0
  187. data/lib/nokogiri/decorators/slop.rb +44 -0
  188. data/lib/nokogiri/encoding_handler.rb +57 -0
  189. data/lib/nokogiri/extension.rb +32 -0
  190. data/lib/nokogiri/gumbo.rb +15 -0
  191. data/lib/nokogiri/html.rb +48 -0
  192. data/lib/nokogiri/html4/builder.rb +37 -0
  193. data/lib/nokogiri/html4/document.rb +214 -0
  194. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  195. data/lib/nokogiri/html4/element_description.rb +25 -0
  196. data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
  197. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  198. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  199. data/lib/nokogiri/html4/sax/parser.rb +63 -0
  200. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  201. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  202. data/lib/nokogiri/html4.rb +47 -0
  203. data/lib/nokogiri/html5/document.rb +168 -0
  204. data/lib/nokogiri/html5/document_fragment.rb +90 -0
  205. data/lib/nokogiri/html5/node.rb +98 -0
  206. data/lib/nokogiri/html5.rb +389 -0
  207. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  208. data/lib/nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar +0 -0
  209. data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
  210. data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
  211. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  212. data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
  213. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
  214. data/lib/nokogiri/jruby/xalan/serializer/2.7.3/serializer-2.7.3.jar +0 -0
  215. data/lib/nokogiri/jruby/xalan/xalan/2.7.3/xalan-2.7.3.jar +0 -0
  216. data/lib/nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar +0 -0
  217. data/lib/nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar +0 -0
  218. data/lib/nokogiri/syntax_error.rb +6 -0
  219. data/lib/nokogiri/version/constant.rb +6 -0
  220. data/lib/nokogiri/version/info.rb +223 -0
  221. data/lib/nokogiri/version.rb +4 -0
  222. data/lib/nokogiri/xml/attr.rb +66 -0
  223. data/lib/nokogiri/xml/attribute_decl.rb +20 -0
  224. data/lib/nokogiri/xml/builder.rb +487 -0
  225. data/lib/nokogiri/xml/cdata.rb +13 -0
  226. data/lib/nokogiri/xml/character_data.rb +9 -0
  227. data/lib/nokogiri/xml/document.rb +471 -0
  228. data/lib/nokogiri/xml/document_fragment.rb +205 -0
  229. data/lib/nokogiri/xml/dtd.rb +34 -0
  230. data/lib/nokogiri/xml/element_content.rb +38 -0
  231. data/lib/nokogiri/xml/element_decl.rb +15 -0
  232. data/lib/nokogiri/xml/entity_decl.rb +21 -0
  233. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  234. data/lib/nokogiri/xml/namespace.rb +58 -0
  235. data/lib/nokogiri/xml/node/save_options.rb +68 -0
  236. data/lib/nokogiri/xml/node.rb +1563 -0
  237. data/lib/nokogiri/xml/node_set.rb +447 -0
  238. data/lib/nokogiri/xml/notation.rb +19 -0
  239. data/lib/nokogiri/xml/parse_options.rb +213 -0
  240. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  241. data/lib/nokogiri/xml/pp/node.rb +57 -0
  242. data/lib/nokogiri/xml/pp.rb +4 -0
  243. data/lib/nokogiri/xml/processing_instruction.rb +11 -0
  244. data/lib/nokogiri/xml/reader.rb +105 -0
  245. data/lib/nokogiri/xml/relax_ng.rb +38 -0
  246. data/lib/nokogiri/xml/sax/document.rb +167 -0
  247. data/lib/nokogiri/xml/sax/parser.rb +125 -0
  248. data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
  249. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  250. data/lib/nokogiri/xml/sax.rb +6 -0
  251. data/lib/nokogiri/xml/schema.rb +73 -0
  252. data/lib/nokogiri/xml/searchable.rb +270 -0
  253. data/lib/nokogiri/xml/syntax_error.rb +72 -0
  254. data/lib/nokogiri/xml/text.rb +11 -0
  255. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  256. data/lib/nokogiri/xml/xpath.rb +21 -0
  257. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  258. data/lib/nokogiri/xml.rb +76 -0
  259. data/lib/nokogiri/xslt/stylesheet.rb +27 -0
  260. data/lib/nokogiri/xslt.rb +65 -0
  261. data/lib/nokogiri.rb +120 -0
  262. data/lib/xsd/xmlparser/nokogiri.rb +106 -0
  263. metadata +391 -0
@@ -0,0 +1,1086 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/GlobalVars
4
+
5
+ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM.include?("darwin")
6
+
7
+ require "mkmf"
8
+ require "rbconfig"
9
+ require "fileutils"
10
+ require "shellwords"
11
+ require "pathname"
12
+
13
+ # helpful constants
14
+ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
15
+ REQUIRED_LIBXML_VERSION = "2.6.21"
16
+ RECOMMENDED_LIBXML_VERSION = "2.9.3"
17
+
18
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.0" # keep this version in sync with the one in the gemspec
19
+ REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
20
+
21
+ # Keep track of what versions of what libraries we build against
22
+ OTHER_LIBRARY_VERSIONS = {}
23
+
24
+ NOKOGIRI_HELP_MESSAGE = <<~HELP
25
+ USAGE: ruby #{$PROGRAM_NAME} [options]
26
+
27
+ Flags that are always valid:
28
+
29
+ --use-system-libraries
30
+ --enable-system-libraries
31
+ Use system libraries instead of building and using the packaged libraries.
32
+
33
+ --disable-system-libraries
34
+ Use the packaged libraries, and ignore the system libraries. This is the default on most
35
+ platforms, and overrides `--use-system-libraries` and the environment variable
36
+ `NOKOGIRI_USE_SYSTEM_LIBRARIES`.
37
+
38
+ --disable-clean
39
+ Do not clean out intermediate files after successful build.
40
+
41
+ --prevent-strip
42
+ Take steps to prevent stripping the symbol table and debugging info from the shared
43
+ library, potentially overriding RbConfig's CFLAGS/LDFLAGS/DLDFLAGS.
44
+
45
+
46
+ Flags only used when using system libraries:
47
+
48
+ General:
49
+
50
+ --with-opt-dir=DIRECTORY
51
+ Look for headers and libraries in DIRECTORY.
52
+
53
+ --with-opt-lib=DIRECTORY
54
+ Look for libraries in DIRECTORY.
55
+
56
+ --with-opt-include=DIRECTORY
57
+ Look for headers in DIRECTORY.
58
+
59
+
60
+ Related to zlib:
61
+
62
+ --with-zlib-dir=DIRECTORY
63
+ Look for zlib headers and library in DIRECTORY.
64
+
65
+ --with-zlib-lib=DIRECTORY
66
+ Look for zlib library in DIRECTORY.
67
+
68
+ --with-zlib-include=DIRECTORY
69
+ Look for zlib headers in DIRECTORY.
70
+
71
+
72
+ Related to iconv:
73
+
74
+ --with-iconv-dir=DIRECTORY
75
+ Look for iconv headers and library in DIRECTORY.
76
+
77
+ --with-iconv-lib=DIRECTORY
78
+ Look for iconv library in DIRECTORY.
79
+
80
+ --with-iconv-include=DIRECTORY
81
+ Look for iconv headers in DIRECTORY.
82
+
83
+
84
+ Related to libxml2:
85
+
86
+ --with-xml2-dir=DIRECTORY
87
+ Look for xml2 headers and library in DIRECTORY.
88
+
89
+ --with-xml2-lib=DIRECTORY
90
+ Look for xml2 library in DIRECTORY.
91
+
92
+ --with-xml2-include=DIRECTORY
93
+ Look for xml2 headers in DIRECTORY.
94
+
95
+ --with-xml2-source-dir=DIRECTORY
96
+ (dev only) Build libxml2 from the source code in DIRECTORY
97
+
98
+
99
+ Related to libxslt:
100
+
101
+ --with-xslt-dir=DIRECTORY
102
+ Look for xslt headers and library in DIRECTORY.
103
+
104
+ --with-xslt-lib=DIRECTORY
105
+ Look for xslt library in DIRECTORY.
106
+
107
+ --with-xslt-include=DIRECTORY
108
+ Look for xslt headers in DIRECTORY.
109
+
110
+ --with-xslt-source-dir=DIRECTORY
111
+ (dev only) Build libxslt from the source code in DIRECTORY
112
+
113
+
114
+ Related to libexslt:
115
+
116
+ --with-exslt-dir=DIRECTORY
117
+ Look for exslt headers and library in DIRECTORY.
118
+
119
+ --with-exslt-lib=DIRECTORY
120
+ Look for exslt library in DIRECTORY.
121
+
122
+ --with-exslt-include=DIRECTORY
123
+ Look for exslt headers in DIRECTORY.
124
+
125
+
126
+ Flags only used when building and using the packaged libraries:
127
+
128
+ --disable-static
129
+ Do not statically link packaged libraries, instead use shared libraries.
130
+
131
+ --enable-cross-build
132
+ Enable cross-build mode. (You probably do not want to set this manually.)
133
+
134
+
135
+ Environment variables used:
136
+
137
+ NOKOGIRI_USE_SYSTEM_LIBRARIES
138
+ Equivalent to `--enable-system-libraries` when set, even if nil or blank.
139
+
140
+ CC
141
+ Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
142
+
143
+ CPPFLAGS
144
+ If this string is accepted by the C preprocessor, add it to the flags passed to the C preprocessor
145
+
146
+ CFLAGS
147
+ If this string is accepted by the compiler, add it to the flags passed to the compiler
148
+
149
+ LDFLAGS
150
+ If this string is accepted by the linker, add it to the flags passed to the linker
151
+
152
+ LIBS
153
+ Add this string to the flags passed to the linker
154
+ HELP
155
+
156
+ #
157
+ # utility functions
158
+ #
159
+ def config_clean?
160
+ enable_config("clean", true)
161
+ end
162
+
163
+ def config_static?
164
+ default_static = !truffle?
165
+ enable_config("static", default_static)
166
+ end
167
+
168
+ def config_cross_build?
169
+ enable_config("cross-build")
170
+ end
171
+
172
+ def config_system_libraries?
173
+ enable_config("system-libraries", ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES")) do |_, default|
174
+ arg_config("--use-system-libraries", default)
175
+ end
176
+ end
177
+
178
+ def windows?
179
+ RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
180
+ end
181
+
182
+ def solaris?
183
+ RbConfig::CONFIG["target_os"].include?("solaris")
184
+ end
185
+
186
+ def darwin?
187
+ RbConfig::CONFIG["target_os"].include?("darwin")
188
+ end
189
+
190
+ def openbsd?
191
+ RbConfig::CONFIG["target_os"].include?("openbsd")
192
+ end
193
+
194
+ def aix?
195
+ RbConfig::CONFIG["target_os"].include?("aix")
196
+ end
197
+
198
+ def nix?
199
+ !(windows? || solaris? || darwin?)
200
+ end
201
+
202
+ def truffle?
203
+ RUBY_ENGINE == "truffleruby"
204
+ end
205
+
206
+ def concat_flags(*args)
207
+ args.compact.join(" ")
208
+ end
209
+
210
+ def local_have_library(lib, func = nil, headers = nil)
211
+ have_library(lib, func, headers) || have_library("lib#{lib}", func, headers)
212
+ end
213
+
214
+ def zlib_source(version_string)
215
+ # As of 2022-12, I'm starting to see failed downloads often enough from zlib.net that I want to
216
+ # change the default to github.
217
+ if ENV["NOKOGIRI_USE_CANONICAL_ZLIB_SOURCE"]
218
+ "https://zlib.net/fossils/zlib-#{version_string}.tar.gz"
219
+ else
220
+ "https://github.com/madler/zlib/releases/download/v#{version_string}/zlib-#{version_string}.tar.gz"
221
+ end
222
+ end
223
+
224
+ def gnome_source
225
+ # As of 2022-02-20, some mirrors have expired SSL certificates. I'm able to retrieve from my home,
226
+ # but whatever host is resolved on the github actions workers see an expired cert.
227
+ #
228
+ # See https://github.com/sparklemotion/nokogiri/runs/5266206403?check_suite_focus=true
229
+ if ENV["NOKOGIRI_USE_CANONICAL_GNOME_SOURCE"]
230
+ "https://download.gnome.org"
231
+ else
232
+ "https://mirror.csclub.uwaterloo.ca/gnome" # old reliable
233
+ end
234
+ end
235
+
236
+ LOCAL_PACKAGE_RESPONSE = Object.new
237
+ def LOCAL_PACKAGE_RESPONSE.%(package)
238
+ package ? "yes: #{package}" : "no"
239
+ end
240
+
241
+ # wrapper around MakeMakefil#pkg_config and the PKGConfig gem
242
+ def try_package_configuration(pc)
243
+ unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG_GEM")
244
+ # try MakeMakefile#pkg_config, which uses the system utility `pkg-config`.
245
+ return if checking_for("#{pc} using `pkg_config`", LOCAL_PACKAGE_RESPONSE) do
246
+ pkg_config(pc)
247
+ end
248
+ end
249
+
250
+ # `pkg-config` probably isn't installed, which appears to be the case for lots of freebsd systems.
251
+ # let's fall back to the pkg-config gem, which knows how to parse .pc files, and wrap it with the
252
+ # same logic as MakeMakefile#pkg_config
253
+ begin
254
+ require "rubygems"
255
+ gem("pkg-config", REQUIRED_PKG_CONFIG_VERSION)
256
+ require "pkg-config"
257
+
258
+ checking_for("#{pc} using pkg-config gem version #{PKGConfig::VERSION}", LOCAL_PACKAGE_RESPONSE) do
259
+ if PKGConfig.have_package(pc)
260
+ cflags = PKGConfig.cflags(pc)
261
+ ldflags = PKGConfig.libs_only_L(pc)
262
+ libs = PKGConfig.libs_only_l(pc)
263
+
264
+ Logging.message("pkg-config gem found package configuration for %s\n", pc)
265
+ Logging.message("cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs)
266
+
267
+ [cflags, ldflags, libs]
268
+ end
269
+ end
270
+ rescue LoadError
271
+ message("Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n")
272
+ end
273
+ end
274
+
275
+ # set up mkmf to link against the library if we can find it
276
+ def have_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
277
+ if opt
278
+ dir_config(opt)
279
+ dir_config("opt")
280
+ end
281
+
282
+ # see if we have enough path info to do this without trying any harder
283
+ unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG")
284
+ return true if local_have_library(lib, func, headers)
285
+ end
286
+
287
+ try_package_configuration(pc) if pc
288
+
289
+ # verify that we can compile and link against the library
290
+ local_have_library(lib, func, headers)
291
+ end
292
+
293
+ def ensure_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
294
+ have_package_configuration(opt: opt, pc: pc, lib: lib, func: func, headers: headers) ||
295
+ abort_could_not_find_library(lib)
296
+ end
297
+
298
+ def ensure_func(func, headers = nil)
299
+ have_func(func, headers) || abort_could_not_find_library(func)
300
+ end
301
+
302
+ def preserving_globals
303
+ values = [$arg_config, $INCFLAGS, $CFLAGS, $CPPFLAGS, $LDFLAGS, $DLDFLAGS, $LIBPATH, $libs].map(&:dup)
304
+ yield
305
+ ensure
306
+ $arg_config, $INCFLAGS, $CFLAGS, $CPPFLAGS, $LDFLAGS, $DLDFLAGS, $LIBPATH, $libs = values
307
+ end
308
+
309
+ def abort_could_not_find_library(lib)
310
+ callers = caller(1..2).join("\n")
311
+ abort("-----\n#{callers}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----")
312
+ end
313
+
314
+ def chdir_for_build(&block)
315
+ # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
316
+ # folders don't support symlinks, but libiconv expects it for a build on
317
+ # Linux. We work around this limitation by using the temp dir for cooking.
318
+ build_dir = /mingw|mswin|cygwin/.match?(ENV["RCD_HOST_RUBY_PLATFORM"].to_s) ? "/tmp" : "."
319
+ Dir.chdir(build_dir, &block)
320
+ end
321
+
322
+ def sh_export_path(path)
323
+ # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
324
+ # as a $PATH separator, we need to convert windows paths from
325
+ #
326
+ # C:/path/to/foo
327
+ #
328
+ # to
329
+ #
330
+ # /C/path/to/foo
331
+ #
332
+ # which is sh-compatible, in order to find things properly during
333
+ # configuration
334
+ return path unless windows?
335
+
336
+ match = Regexp.new("^([A-Z]):(/.*)").match(path)
337
+ if match && match.length == 3
338
+ return File.join("/", match[1], match[2])
339
+ end
340
+
341
+ path
342
+ end
343
+
344
+ def libflag_to_filename(ldflag)
345
+ case ldflag
346
+ when /\A-l(.+)/
347
+ "lib#{Regexp.last_match(1)}.#{$LIBEXT}"
348
+ end
349
+ end
350
+
351
+ def have_libxml_headers?(version = nil)
352
+ source = if version.nil?
353
+ <<~SRC
354
+ #include <libxml/xmlversion.h>
355
+ SRC
356
+ else
357
+ version_int = format("%d%2.2d%2.2d", *version.split("."))
358
+ <<~SRC
359
+ #include <libxml/xmlversion.h>
360
+ #if LIBXML_VERSION < #{version_int}
361
+ # error libxml2 is older than #{version}
362
+ #endif
363
+ SRC
364
+ end
365
+
366
+ try_cpp(source)
367
+ end
368
+
369
+ def try_link_iconv(using = nil)
370
+ checking_for(using ? "iconv using #{using}" : "iconv") do
371
+ ["", "-liconv"].any? do |opt|
372
+ preserving_globals do
373
+ yield if block_given?
374
+
375
+ try_link(<<~'SRC', opt)
376
+ #include <stdlib.h>
377
+ #include <iconv.h>
378
+ int main(void)
379
+ {
380
+ iconv_t cd = iconv_open("", "");
381
+ iconv(cd, NULL, NULL, NULL, NULL);
382
+ return EXIT_SUCCESS;
383
+ }
384
+ SRC
385
+ end
386
+ end
387
+ end
388
+ end
389
+
390
+ def iconv_configure_flags
391
+ # give --with-iconv-dir and --with-opt-dir first priority
392
+ ["iconv", "opt"].each do |target|
393
+ config = preserving_globals { dir_config(target) }
394
+ next unless config.any? && try_link_iconv("--with-#{target}-* flags") { dir_config(target) }
395
+
396
+ idirs, ldirs = config.map do |dirs|
397
+ Array(dirs).flat_map do |dir|
398
+ dir.split(File::PATH_SEPARATOR)
399
+ end if dirs
400
+ end
401
+
402
+ return [
403
+ "--with-iconv=yes",
404
+ *("CPPFLAGS=#{idirs.map { |dir| "-I" + dir }.join(" ")}" if idirs),
405
+ *("LDFLAGS=#{ldirs.map { |dir| "-L" + dir }.join(" ")}" if ldirs),
406
+ ]
407
+ end
408
+
409
+ if try_link_iconv
410
+ return ["--with-iconv=yes"]
411
+ end
412
+
413
+ config = preserving_globals { pkg_config("libiconv") }
414
+ if config && try_link_iconv("pkg-config libiconv") { pkg_config("libiconv") }
415
+ cflags, ldflags, libs = config
416
+
417
+ return [
418
+ "--with-iconv=yes",
419
+ "CPPFLAGS=#{cflags}",
420
+ "LDFLAGS=#{ldflags}",
421
+ "LIBS=#{libs}",
422
+ ]
423
+ end
424
+
425
+ abort_could_not_find_library("libiconv")
426
+ end
427
+
428
+ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
429
+ require "rubygems"
430
+ gem("mini_portile2", REQUIRED_MINI_PORTILE_VERSION) # gemspec is not respected at install time
431
+ require "mini_portile2"
432
+ message("Using mini_portile version #{MiniPortile::VERSION}\n")
433
+
434
+ unless ["libxml2", "libxslt"].include?(name)
435
+ OTHER_LIBRARY_VERSIONS[name] = version
436
+ end
437
+
438
+ MiniPortile.new(name, version).tap do |recipe|
439
+ def recipe.port_path
440
+ "#{@target}/#{RUBY_PLATFORM}/#{@name}/#{@version}"
441
+ end
442
+
443
+ # We use 'host' to set compiler prefix for cross-compiling. Prefer host_alias over host. And
444
+ # prefer i686 (what external dev tools use) to i386 (what ruby's configure.ac emits).
445
+ recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
446
+ recipe.host = recipe.host.gsub(/i386/, "i686")
447
+
448
+ recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") if cacheable_p
449
+ recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
450
+
451
+ yield recipe
452
+
453
+ env = Hash.new do |hash, key|
454
+ hash[key] = (ENV[key]).to_s
455
+ end
456
+
457
+ recipe.configure_options.flatten!
458
+
459
+ recipe.configure_options.delete_if do |option|
460
+ case option
461
+ when /\A(\w+)=(.*)\z/
462
+ env[Regexp.last_match(1)] = if env.key?(Regexp.last_match(1))
463
+ concat_flags(env[Regexp.last_match(1)], Regexp.last_match(2))
464
+ else
465
+ Regexp.last_match(2)
466
+ end
467
+ true
468
+ else
469
+ false
470
+ end
471
+ end
472
+
473
+ if static_p
474
+ recipe.configure_options += [
475
+ "--disable-shared",
476
+ "--enable-static",
477
+ ]
478
+ env["CFLAGS"] = concat_flags(env["CFLAGS"], "-fPIC")
479
+ else
480
+ recipe.configure_options += [
481
+ "--enable-shared",
482
+ "--disable-static",
483
+ ]
484
+ end
485
+
486
+ if cross_p
487
+ recipe.configure_options += [
488
+ "--target=#{recipe.host}",
489
+ "--host=#{recipe.host}",
490
+ ]
491
+ end
492
+
493
+ if RbConfig::CONFIG["target_cpu"] == "universal"
494
+ ["CFLAGS", "LDFLAGS"].each do |key|
495
+ unless env[key].include?("-arch")
496
+ env[key] = concat_flags(env[key], RbConfig::CONFIG["ARCH_FLAG"])
497
+ end
498
+ end
499
+ end
500
+
501
+ recipe.configure_options += env.map do |key, value|
502
+ "#{key}=#{value.strip}"
503
+ end
504
+
505
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{RUBY_PLATFORM}.installed"
506
+ if File.exist?(checkpoint) && !recipe.source_directory
507
+ message("Building Nokogiri with a packaged version of #{name}-#{version}.\n")
508
+ else
509
+ message(<<~EOM)
510
+ ---------- IMPORTANT NOTICE ----------
511
+ Building Nokogiri with a packaged version of #{name}-#{version}.
512
+ Configuration options: #{recipe.configure_options.shelljoin}
513
+ EOM
514
+
515
+ unless recipe.patch_files.empty?
516
+ message("The following patches are being applied:\n")
517
+
518
+ recipe.patch_files.each do |patch|
519
+ message(format(" - %s\n", File.basename(patch)))
520
+ end
521
+ end
522
+
523
+ message(<<~EOM) if name != "libgumbo"
524
+
525
+ The Nokogiri maintainers intend to provide timely security updates, but if
526
+ this is a concern for you and want to use your OS/distro system library
527
+ instead, then abort this installation process and install nokogiri as
528
+ instructed at:
529
+
530
+ https://nokogiri.org/tutorials/installing_nokogiri.html#installing-using-standard-system-libraries
531
+
532
+ EOM
533
+
534
+ message(<<~EOM) if name == "libxml2"
535
+ Note, however, that nokogiri cannot guarantee compatibility with every
536
+ version of libxml2 that may be provided by OS/package vendors.
537
+
538
+ EOM
539
+
540
+ chdir_for_build { recipe.cook }
541
+ FileUtils.touch(checkpoint)
542
+ end
543
+ recipe.activate
544
+ end
545
+ end
546
+
547
+ def copy_packaged_libraries_headers(to_path:, from_recipes:)
548
+ FileUtils.rm_rf(to_path, secure: true)
549
+ FileUtils.mkdir(to_path)
550
+ from_recipes.each do |recipe|
551
+ FileUtils.cp_r(Dir[File.join(recipe.path, "include/*")], to_path)
552
+ end
553
+ end
554
+
555
+ def do_help
556
+ print(NOKOGIRI_HELP_MESSAGE)
557
+ exit!(0)
558
+ end
559
+
560
+ def do_clean
561
+ root = Pathname(PACKAGE_ROOT_DIR)
562
+ pwd = Pathname(Dir.pwd)
563
+
564
+ # Skip if this is a development work tree
565
+ unless (root + ".git").exist?
566
+ message("Cleaning files only used during build.\n")
567
+
568
+ # (root + 'tmp') cannot be removed at this stage because
569
+ # nokogiri.so is yet to be copied to lib.
570
+
571
+ # clean the ports build directory
572
+ Pathname.glob(pwd.join("tmp", "*", "ports")) do |dir|
573
+ FileUtils.rm_rf(dir, verbose: true)
574
+ end
575
+
576
+ if config_static?
577
+ # ports installation can be safely removed if statically linked.
578
+ FileUtils.rm_rf(root + "ports", verbose: true)
579
+ else
580
+ FileUtils.rm_rf(root + "ports" + "archives", verbose: true)
581
+ end
582
+ end
583
+
584
+ exit!(0)
585
+ end
586
+
587
+ # In ruby 3.2, symbol resolution changed on Darwin, to introduce the `-bundle_loader` flag to
588
+ # resolve symbols against the ruby binary.
589
+ #
590
+ # This makes it challenging to build a single extension that works with both a ruby with
591
+ # `--enable-shared` and one with `--disable-shared. To work around that, we choose to add
592
+ # `-flat_namespace` to the link line (later in this file).
593
+ #
594
+ # The `-flat_namespace` line introduces its own behavior change, which is that (similar to on
595
+ # Linux), any symbols in the extension that are exported may now be resolved by shared libraries
596
+ # loaded by the Ruby process. Specifically, that means that libxml2 and libxslt, which are
597
+ # statically linked into the nokogiri bundle, will resolve (at runtime) to a system libxml2 loaded
598
+ # by Ruby on Darwin. And it appears that often Ruby on Darwin does indeed load the system libxml2,
599
+ # and that messes with our assumptions about whether we're running with a patched libxml2 or a
600
+ # vanilla libxml2.
601
+ #
602
+ # We choose to use `-load_hidden` in this case to prevent exporting those symbols from libxml2 and
603
+ # libxslt, which ensures that they will be resolved to the static libraries in the bundle. In other
604
+ # words, when we use `load_hidden`, what happens in the extension stays in the extension.
605
+ #
606
+ # See https://github.com/rake-compiler/rake-compiler-dock/issues/87 for more info.
607
+ #
608
+ # Anyway, this method is the logical bit to tell us when to turn on these workarounds.
609
+ def needs_darwin_linker_hack
610
+ config_cross_build? &&
611
+ darwin? &&
612
+ Gem::Requirement.new("~> 3.2").satisfied_by?(Gem::Version.new(RbConfig::CONFIG["ruby_version"].split("+").first))
613
+ end
614
+
615
+ #
616
+ # main
617
+ #
618
+ do_help if arg_config("--help")
619
+ do_clean if arg_config("--clean")
620
+
621
+ if openbsd? && !config_system_libraries?
622
+ unless %x(#{ENV["CC"] || "/usr/bin/cc"} -v 2>&1).include?("clang")
623
+ (ENV["CC"] ||= find_executable("egcc")) ||
624
+ abort("Please install gcc 4.9+ from ports using `pkg_add -v gcc`")
625
+ end
626
+ append_cppflags "-I/usr/local/include"
627
+ end
628
+
629
+ if ENV["CC"]
630
+ RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
631
+ end
632
+
633
+ # use same c compiler for libxml and libxslt
634
+ ENV["CC"] = RbConfig::CONFIG["CC"]
635
+
636
+ if arg_config("--prevent-strip")
637
+ old_cflags = $CFLAGS.split.join(" ")
638
+ old_ldflags = $LDFLAGS.split.join(" ")
639
+ old_dldflags = $DLDFLAGS.split.join(" ")
640
+ $CFLAGS = $CFLAGS.split.reject { |flag| flag == "-s" }.join(" ")
641
+ $LDFLAGS = $LDFLAGS.split.reject { |flag| flag == "-s" }.join(" ")
642
+ $DLDFLAGS = $DLDFLAGS.split.reject { |flag| flag == "-s" }.join(" ")
643
+ puts "Prevent stripping by removing '-s' from $CFLAGS" if old_cflags != $CFLAGS
644
+ puts "Prevent stripping by removing '-s' from $LDFLAGS" if old_ldflags != $LDFLAGS
645
+ puts "Prevent stripping by removing '-s' from $DLDFLAGS" if old_dldflags != $DLDFLAGS
646
+ end
647
+
648
+ # adopt environment config
649
+ append_cflags(ENV["CFLAGS"].split) unless ENV["CFLAGS"].nil?
650
+ append_cppflags(ENV["CPPFLAGS"].split) unless ENV["CPPFLAGS"].nil?
651
+ append_ldflags(ENV["LDFLAGS"].split) unless ENV["LDFLAGS"].nil?
652
+ $LIBS = concat_flags($LIBS, ENV["LIBS"])
653
+
654
+ # nokogumbo code uses C90/C99 features, let's make sure older compilers won't give
655
+ # errors/warnings. see #2302
656
+ append_cflags(["-std=c89", "-Wno-declaration-after-statement", "-wimplicit-function-declaration"])
657
+
658
+ # gumbo html5 serialization is slower with O3, let's make sure we use O2
659
+ append_cflags("-O2")
660
+
661
+ append_cflags("-wimplicit-function-declaration")
662
+
663
+ # always include debugging information
664
+ append_cflags("-g")
665
+
666
+ # we use at least one inline function in the C extension
667
+ append_cflags("-Winline")
668
+
669
+ # good to have no matter what Ruby was compiled with
670
+ append_cflags("-Wmissing-noreturn")
671
+
672
+ # check integer loss of precision
673
+ if darwin?
674
+ append_cflags("-Wshorten-64-to-32")
675
+ else
676
+ append_cflags("-Wconversion -Wno-sign-conversion")
677
+ end
678
+
679
+ # handle clang variations, see #1101
680
+ if darwin?
681
+ append_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future")
682
+ append_cflags("-Wno-unknown-warning-option")
683
+ end
684
+
685
+ # these tend to be noisy, but on occasion useful during development
686
+ # append_cflags(["-Wcast-qual", "-Wwrite-strings"])
687
+
688
+ # Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
689
+ macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
690
+ if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
691
+ append_cppflags("-I#{macos_mojave_sdk_include_path}")
692
+ end
693
+
694
+ # Work around a character escaping bug in MSYS by passing an arbitrary double-quoted parameter to gcc.
695
+ # See https://sourceforge.net/p/mingw/bugs/2142
696
+ append_cppflags(' "-Idummypath"') if windows?
697
+
698
+ if config_system_libraries?
699
+ message "Building nokogiri using system libraries.\n"
700
+ ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
701
+ headers: "zlib.h", func: "gzdopen")
702
+ ensure_package_configuration(opt: "xml2", pc: "libxml-2.0", lib: "xml2",
703
+ headers: "libxml/parser.h", func: "xmlParseDoc")
704
+ ensure_package_configuration(opt: "xslt", pc: "libxslt", lib: "xslt",
705
+ headers: "libxslt/xslt.h", func: "xsltParseStylesheetDoc")
706
+ ensure_package_configuration(opt: "exslt", pc: "libexslt", lib: "exslt",
707
+ headers: "libexslt/exslt.h", func: "exsltFuncRegister")
708
+
709
+ have_libxml_headers?(REQUIRED_LIBXML_VERSION) ||
710
+ abort("ERROR: libxml2 version #{REQUIRED_LIBXML_VERSION} or later is required!")
711
+ have_libxml_headers?(RECOMMENDED_LIBXML_VERSION) ||
712
+ warn("WARNING: libxml2 version #{RECOMMENDED_LIBXML_VERSION} or later is highly recommended, but proceeding anyway.")
713
+
714
+ else
715
+ message "Building nokogiri using packaged libraries.\n"
716
+
717
+ static_p = config_static?
718
+ message "Static linking is #{static_p ? "enabled" : "disabled"}.\n"
719
+
720
+ cross_build_p = config_cross_build?
721
+ message "Cross build is #{cross_build_p ? "enabled" : "disabled"}.\n"
722
+
723
+ if needs_darwin_linker_hack
724
+ append_ldflags("-Wl,-flat_namespace")
725
+ end
726
+
727
+ require "yaml"
728
+ dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))
729
+
730
+ dir_config("zlib")
731
+
732
+ if cross_build_p || windows?
733
+ zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
734
+ recipe.files = [{
735
+ url: zlib_source(recipe.version),
736
+ sha256: dependencies["zlib"]["sha256"],
737
+ }]
738
+ if windows?
739
+ class << recipe
740
+ attr_accessor :cross_build_p
741
+
742
+ def configure
743
+ Dir.chdir(work_path) do
744
+ mk = File.read("win32/Makefile.gcc")
745
+ File.open("win32/Makefile.gcc", "wb") do |f|
746
+ f.puts "BINARY_PATH = #{path}/bin"
747
+ f.puts "LIBRARY_PATH = #{path}/lib"
748
+ f.puts "INCLUDE_PATH = #{path}/include"
749
+ mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
750
+ f.puts mk
751
+ end
752
+ end
753
+ end
754
+
755
+ def configured?
756
+ Dir.chdir(work_path) do
757
+ !!(File.read("win32/Makefile.gcc") =~ /^BINARY_PATH/)
758
+ end
759
+ end
760
+
761
+ def compile
762
+ execute("compile", "make -f win32/Makefile.gcc")
763
+ end
764
+
765
+ def install
766
+ execute("install", "make -f win32/Makefile.gcc install")
767
+ end
768
+ end
769
+ recipe.cross_build_p = cross_build_p
770
+ else
771
+ class << recipe
772
+ def configure
773
+ env = {}
774
+ env["CFLAGS"] = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
775
+ env["CHOST"] = host
776
+ execute("configure", ["./configure", "--static", configure_prefix], { env: env })
777
+ if darwin?
778
+ # needed as of zlib 1.2.13
779
+ Dir.chdir(work_path) do
780
+ makefile = File.read("Makefile").gsub(/^AR=.*$/, "AR=#{host}-libtool")
781
+ File.open("Makefile", "w") { |m| m.write(makefile) }
782
+ end
783
+ end
784
+ end
785
+ end
786
+ end
787
+ end
788
+
789
+ unless nix?
790
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p,
791
+ cross_build_p) do |recipe|
792
+ recipe.files = [{
793
+ url: "https://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
794
+ sha256: dependencies["libiconv"]["sha256"],
795
+ }]
796
+
797
+ # The libiconv configure script doesn't accept "arm64" host string but "aarch64"
798
+ recipe.host = recipe.host.gsub("arm64-apple-darwin", "aarch64-apple-darwin")
799
+
800
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
801
+
802
+ recipe.configure_options += [
803
+ "--disable-dependency-tracking",
804
+ "CPPFLAGS=-Wall",
805
+ "CFLAGS=#{cflags}",
806
+ "CXXFLAGS=#{cflags}",
807
+ "LDFLAGS=",
808
+ ]
809
+ end
810
+ end
811
+ elsif darwin? && !have_header("iconv.h")
812
+ abort(<<~EOM.chomp)
813
+ -----
814
+ The file "iconv.h" is missing in your build environment,
815
+ which means you haven't installed Xcode Command Line Tools properly.
816
+
817
+ To install Command Line Tools, try running `xcode-select --install` on
818
+ terminal and follow the instructions. If it fails, open Xcode.app,
819
+ select from the menu "Xcode" - "Open Developer Tool" - "More Developer
820
+ Tools" to open the developer site, download the installer for your OS
821
+ version and run it.
822
+ -----
823
+ EOM
824
+ end
825
+
826
+ if zlib_recipe
827
+ append_cppflags("-I#{zlib_recipe.path}/include")
828
+ $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH
829
+ ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
830
+ headers: "zlib.h", func: "gzdopen")
831
+ end
832
+
833
+ if libiconv_recipe
834
+ append_cppflags("-I#{libiconv_recipe.path}/include")
835
+ $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH
836
+ ensure_package_configuration(opt: "iconv", pc: "iconv", lib: "iconv",
837
+ headers: "iconv.h", func: "iconv_open")
838
+ end
839
+
840
+ libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
841
+ source_dir = arg_config("--with-xml2-source-dir")
842
+ if source_dir
843
+ recipe.source_directory = source_dir
844
+ else
845
+ minor_version = Gem::Version.new(recipe.version).segments.take(2).join(".")
846
+ recipe.files = [{
847
+ url: "#{gnome_source}/sources/libxml2/#{minor_version}/#{recipe.name}-#{recipe.version}.tar.xz",
848
+ sha256: dependencies["libxml2"]["sha256"],
849
+ }]
850
+ recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxml2", "*.patch")].sort
851
+ end
852
+
853
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
854
+
855
+ if zlib_recipe
856
+ recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
857
+ end
858
+
859
+ if libiconv_recipe
860
+ recipe.configure_options << "--with-iconv=#{libiconv_recipe.path}"
861
+ else
862
+ recipe.configure_options += iconv_configure_flags
863
+ end
864
+
865
+ if darwin? && !cross_build_p
866
+ recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
867
+ end
868
+
869
+ if windows?
870
+ cflags = concat_flags(cflags, "-ULIBXML_STATIC", "-DIN_LIBXML")
871
+ end
872
+
873
+ recipe.configure_options << if source_dir
874
+ "--config-cache"
875
+ else
876
+ "--disable-dependency-tracking"
877
+ end
878
+
879
+ recipe.configure_options += [
880
+ "--without-python",
881
+ "--without-readline",
882
+ "--with-c14n",
883
+ "--with-debug",
884
+ "--with-threads",
885
+ "CFLAGS=#{cflags}",
886
+ ]
887
+ end
888
+
889
+ libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
890
+ source_dir = arg_config("--with-xslt-source-dir")
891
+ if source_dir
892
+ recipe.source_directory = source_dir
893
+ else
894
+ minor_version = Gem::Version.new(recipe.version).segments.take(2).join(".")
895
+ recipe.files = [{
896
+ url: "#{gnome_source}/sources/libxslt/#{minor_version}/#{recipe.name}-#{recipe.version}.tar.xz",
897
+ sha256: dependencies["libxslt"]["sha256"],
898
+ }]
899
+ recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxslt", "*.patch")].sort
900
+ end
901
+
902
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
903
+
904
+ if darwin? && !cross_build_p
905
+ recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
906
+ end
907
+
908
+ if windows?
909
+ cflags = concat_flags(cflags, "-ULIBXSLT_STATIC", "-DIN_LIBXSLT")
910
+ cflags = concat_flags(cflags, "-ULIBEXSLT_STATIC", "-DIN_LIBEXSLT")
911
+ end
912
+
913
+ recipe.configure_options << if source_dir
914
+ "--config-cache"
915
+ else
916
+ "--disable-dependency-tracking"
917
+ end
918
+
919
+ recipe.configure_options += [
920
+ "--without-python",
921
+ "--without-crypto",
922
+ "--with-debug",
923
+ "--with-libxml-prefix=#{sh_export_path(libxml2_recipe.path)}",
924
+ "CFLAGS=#{cflags}",
925
+ ]
926
+ end
927
+
928
+ append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
929
+ append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
930
+
931
+ $libs = $libs.shellsplit.tap do |libs|
932
+ [libxml2_recipe, libxslt_recipe].each do |recipe|
933
+ libname = recipe.name[/\Alib(.+)\z/, 1]
934
+ config_basename = "#{libname}-config"
935
+ File.join(recipe.path, "bin", config_basename).tap do |config|
936
+ # call config scripts explicit with 'sh' for compat with Windows
937
+ cflags = %x(sh #{config} --cflags).strip
938
+ message("#{config_basename} cflags: #{cflags}\n")
939
+ $CPPFLAGS = concat_flags(cflags, $CPPFLAGS) # prepend
940
+
941
+ %x(sh #{config} --libs).strip.shellsplit.each do |arg|
942
+ case arg
943
+ when /\A-L(.+)\z/
944
+ # Prioritize ports' directories
945
+ $LIBPATH = if Regexp.last_match(1).start_with?(PACKAGE_ROOT_DIR + "/")
946
+ [Regexp.last_match(1)] | $LIBPATH
947
+ else
948
+ $LIBPATH | [Regexp.last_match(1)]
949
+ end
950
+ when /\A-l./
951
+ libs.unshift(arg)
952
+ else
953
+ $LDFLAGS << " " << arg.shellescape
954
+ end
955
+ end
956
+ end
957
+
958
+ patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(" ")
959
+ append_cppflags(%[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\"#{patches_string}\\""])
960
+
961
+ case libname
962
+ when "xml2"
963
+ # xslt-config --libs or pkg-config libxslt --libs does not include
964
+ # -llzma, so we need to add it manually when linking statically.
965
+ if static_p && preserving_globals { local_have_library("lzma") }
966
+ # Add it at the end; GH #988
967
+ libs << "-llzma"
968
+ end
969
+ when "xslt"
970
+ # xslt-config does not have a flag to emit options including
971
+ # -lexslt, so add it manually.
972
+ libs.unshift("-lexslt")
973
+ end
974
+ end
975
+ end.shelljoin
976
+
977
+ if static_p
978
+ static_archive_ld_flag = needs_darwin_linker_hack ? ["-load_hidden"] : []
979
+ $libs = $libs.shellsplit.map do |arg|
980
+ case arg
981
+ when "-lxml2"
982
+ static_archive_ld_flag + [File.join(libxml2_recipe.path, "lib", libflag_to_filename(arg))]
983
+ when "-lxslt", "-lexslt"
984
+ static_archive_ld_flag + [File.join(libxslt_recipe.path, "lib", libflag_to_filename(arg))]
985
+ else
986
+ arg
987
+ end
988
+ end.flatten.shelljoin
989
+ end
990
+
991
+ ensure_func("xmlParseDoc", "libxml/parser.h")
992
+ ensure_func("xsltParseStylesheetDoc", "libxslt/xslt.h")
993
+ ensure_func("exsltFuncRegister", "libexslt/exslt.h")
994
+ end
995
+
996
+ libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_build_p, false) do |recipe|
997
+ recipe.configure_options = []
998
+
999
+ class << recipe
1000
+ def downloaded?
1001
+ true
1002
+ end
1003
+
1004
+ def extract
1005
+ target = File.join(tmp_path, "gumbo-parser")
1006
+ output("Copying gumbo-parser files into #{target}...")
1007
+ FileUtils.mkdir_p(target)
1008
+ FileUtils.cp(Dir.glob(File.join(PACKAGE_ROOT_DIR, "gumbo-parser/src/*")), target)
1009
+ end
1010
+
1011
+ def configured?
1012
+ true
1013
+ end
1014
+
1015
+ def install
1016
+ lib_dir = File.join(port_path, "lib")
1017
+ inc_dir = File.join(port_path, "include")
1018
+ FileUtils.mkdir_p([lib_dir, inc_dir])
1019
+ FileUtils.cp(File.join(work_path, "libgumbo.a"), lib_dir)
1020
+ FileUtils.cp(Dir.glob(File.join(work_path, "*.h")), inc_dir)
1021
+ end
1022
+
1023
+ def compile
1024
+ cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-O2", "-g")
1025
+
1026
+ env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
1027
+ if config_cross_build?
1028
+ if /darwin/.match?(host)
1029
+ env["AR"] = "#{host}-libtool"
1030
+ env["ARFLAGS"] = "-o"
1031
+ else
1032
+ env["AR"] = "#{host}-ar"
1033
+ end
1034
+ env["RANLIB"] = "#{host}-ranlib"
1035
+ end
1036
+
1037
+ execute("compile", make_cmd, { env: env })
1038
+ end
1039
+ end
1040
+ end
1041
+ append_cppflags("-I#{File.join(libgumbo_recipe.path, "include")}")
1042
+ $libs = $libs + " " + File.join(libgumbo_recipe.path, "lib", "libgumbo.a")
1043
+ $LIBPATH = $LIBPATH | [File.join(libgumbo_recipe.path, "lib")]
1044
+ ensure_func("gumbo_parse_with_options", "nokogiri_gumbo.h")
1045
+
1046
+ have_func("xmlHasFeature") || abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
1047
+ have_func("xmlFirstElementChild") # introduced in libxml 2.7.3
1048
+ have_func("xmlRelaxNGSetParserStructuredErrors") # introduced in libxml 2.6.24
1049
+ have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
1050
+ have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
1051
+ have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
1052
+ have_func("rb_gc_location") # introduced in Ruby 2.7
1053
+ have_func("rb_category_warning") # introduced in Ruby 3.0
1054
+
1055
+ other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
1056
+ append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\"#{other_library_versions_string}\\""])
1057
+
1058
+ unless config_system_libraries?
1059
+ if cross_build_p
1060
+ # When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
1061
+ # These are packaged up by the cross-compiling callback in the ExtensionTask
1062
+ copy_packaged_libraries_headers(to_path: File.join(PACKAGE_ROOT_DIR, "ext/nokogiri/include"),
1063
+ from_recipes: [libxml2_recipe, libxslt_recipe])
1064
+ else
1065
+ # When compiling during installation, install packaged libraries' header files into ext/nokogiri/include
1066
+ copy_packaged_libraries_headers(to_path: "include",
1067
+ from_recipes: [libxml2_recipe, libxslt_recipe])
1068
+ $INSTALLFILES << ["include/**/*.h", "$(rubylibdir)"]
1069
+ end
1070
+ end
1071
+
1072
+ create_makefile("nokogiri/nokogiri")
1073
+
1074
+ if config_clean?
1075
+ # Do not clean if run in a development work tree.
1076
+ File.open("Makefile", "at") do |mk|
1077
+ mk.print(<<~EOF)
1078
+
1079
+ all: clean-ports
1080
+ clean-ports: $(DLLIB)
1081
+ \t-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? "enable" : "disable"}-static
1082
+ EOF
1083
+ end
1084
+ end
1085
+
1086
+ # rubocop:enable Style/GlobalVars