mini-pro-gem 0.0.1

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