re2 2.0.0.beta1-x64-mingw32

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.
@@ -0,0 +1,384 @@
1
+ # re2 (http://github.com/mudge/re2)
2
+ # Ruby bindings to re2, an "efficient, principled regular expression library"
3
+ #
4
+ # Copyright (c) 2010-2012, Paul Mucur (http://mudge.name)
5
+ # Released under the BSD Licence, please see LICENSE.txt
6
+
7
+ require 'mkmf'
8
+ require_relative 'recipes'
9
+
10
+ RE2_HELP_MESSAGE = <<~HELP
11
+ USAGE: ruby #{$0} [options]
12
+
13
+ Flags that are always valid:
14
+
15
+ --enable-system-libraries
16
+ Use system libraries instead of building and using the packaged libraries.
17
+
18
+ --disable-system-libraries
19
+ Use the packaged libraries, and ignore the system libraries. This is the default.
20
+
21
+
22
+ Flags only used when using system libraries:
23
+
24
+ Related to re2 library:
25
+
26
+ --with-re2-dir=DIRECTORY
27
+ Look for re2 headers and library in DIRECTORY.
28
+
29
+
30
+ Flags only used when building and using the packaged libraries:
31
+
32
+ --enable-cross-build
33
+ Enable cross-build mode. (You probably do not want to set this manually.)
34
+
35
+
36
+ Environment variables used:
37
+
38
+ CC
39
+ Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
40
+
41
+ CPPFLAGS
42
+ If this string is accepted by the C preprocessor, add it to the flags passed to the C preprocessor
43
+
44
+ CFLAGS
45
+ If this string is accepted by the compiler, add it to the flags passed to the compiler
46
+
47
+ LDFLAGS
48
+ If this string is accepted by the linker, add it to the flags passed to the linker
49
+
50
+ LIBS
51
+ Add this string to the flags passed to the linker
52
+ HELP
53
+
54
+ #
55
+ # utility functions
56
+ #
57
+ def config_system_libraries?
58
+ enable_config("system-libraries", ENV.key?('RE2_USE_SYSTEM_LIBRARIES'))
59
+ end
60
+
61
+ def config_cross_build?
62
+ enable_config("cross-build")
63
+ end
64
+
65
+ def concat_flags(*args)
66
+ args.compact.join(" ")
67
+ end
68
+
69
+ def do_help
70
+ print(RE2_HELP_MESSAGE)
71
+ exit!(0)
72
+ end
73
+
74
+ def darwin?
75
+ RbConfig::CONFIG["target_os"].include?("darwin")
76
+ end
77
+
78
+ def windows?
79
+ RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
80
+ end
81
+
82
+ def freebsd?
83
+ RbConfig::CONFIG["target_os"].include?("freebsd")
84
+ end
85
+
86
+ def target_host
87
+ # We use 'host' to set compiler prefix for cross-compiling. Prefer host_alias over host. And
88
+ # prefer i686 (what external dev tools use) to i386 (what ruby's configure.ac emits).
89
+ host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
90
+ host.gsub(/i386/, "i686")
91
+ end
92
+
93
+ def target_arch
94
+ RbConfig::CONFIG['arch']
95
+ end
96
+
97
+ def with_temp_dir
98
+ Dir.mktmpdir do |temp_dir|
99
+ Dir.chdir(temp_dir) do
100
+ yield
101
+ end
102
+ end
103
+ end
104
+
105
+ #
106
+ # main
107
+ #
108
+ do_help if arg_config('--help')
109
+
110
+ if ENV["CC"]
111
+ RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
112
+ RbConfig::CONFIG["CC"] = ENV["CC"]
113
+ end
114
+
115
+ if ENV["CXX"]
116
+ RbConfig::MAKEFILE_CONFIG["CXX"] = ENV["CXX"]
117
+ RbConfig::CONFIG["CXX"] = ENV["CXX"]
118
+ end
119
+
120
+ def build_extension
121
+ $CFLAGS << " -Wall -Wextra -funroll-loops"
122
+
123
+ # Pass -x c++ to force gcc to compile the test program
124
+ # as C++ (as it will end in .c by default).
125
+ compile_options = "-x c++"
126
+
127
+ have_library("stdc++")
128
+ have_header("stdint.h")
129
+ have_func("rb_str_sublen")
130
+
131
+ unless have_library("re2")
132
+ abort "You must have re2 installed and specified with --with-re2-dir, please see https://github.com/google/re2/wiki/Install"
133
+ end
134
+
135
+ minimal_program = <<SRC
136
+ #include <re2/re2.h>
137
+ int main() { return 0; }
138
+ SRC
139
+
140
+ re2_requires_version_flag = checking_for("re2 that requires explicit C++ version flag") do
141
+ !try_compile(minimal_program, compile_options)
142
+ end
143
+
144
+ if re2_requires_version_flag
145
+ # Recent versions of re2 depend directly on abseil, which requires a
146
+ # compiler with C++14 support (see
147
+ # https://github.com/abseil/abseil-cpp/issues/1127 and
148
+ # https://github.com/abseil/abseil-cpp/issues/1431). However, the
149
+ # `std=c++14` flag doesn't appear to suffice; we need at least
150
+ # `std=c++17`.
151
+ abort "Cannot compile re2 with your compiler: recent versions require C++14 support." unless %w[c++20 c++17 c++11 c++0x].any? do |std|
152
+ checking_for("re2 that compiles with #{std} standard") do
153
+ if try_compile(minimal_program, compile_options + " -std=#{std}")
154
+ compile_options << " -std=#{std}"
155
+ $CPPFLAGS << " -std=#{std}"
156
+
157
+ true
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ # Determine which version of re2 the user has installed.
164
+ # Revision d9f8806c004d added an `endpos` argument to the
165
+ # generic Match() function.
166
+ #
167
+ # To test for this, try to compile a simple program that uses
168
+ # the newer form of Match() and set a flag if it is successful.
169
+ checking_for("RE2::Match() with endpos argument") do
170
+ test_re2_match_signature = <<SRC
171
+ #include <re2/re2.h>
172
+
173
+ int main() {
174
+ RE2 pattern("test");
175
+ re2::StringPiece *match;
176
+ pattern.Match("test", 0, 0, RE2::UNANCHORED, match, 0);
177
+
178
+ return 0;
179
+ }
180
+ SRC
181
+
182
+ if try_compile(test_re2_match_signature, compile_options)
183
+ $defs.push("-DHAVE_ENDPOS_ARGUMENT")
184
+ end
185
+ end
186
+
187
+ checking_for("RE2::Set::Match() with error information") do
188
+ test_re2_set_match_signature = <<SRC
189
+ #include <vector>
190
+ #include <re2/re2.h>
191
+ #include <re2/set.h>
192
+
193
+ int main() {
194
+ RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
195
+ s.Add("foo", NULL);
196
+ s.Compile();
197
+
198
+ std::vector<int> v;
199
+ RE2::Set::ErrorInfo ei;
200
+ s.Match("foo", &v, &ei);
201
+
202
+ return 0;
203
+ }
204
+ SRC
205
+
206
+ if try_compile(test_re2_set_match_signature, compile_options)
207
+ $defs.push("-DHAVE_ERROR_INFO_ARGUMENT")
208
+ end
209
+ end
210
+ end
211
+
212
+ def process_recipe(recipe)
213
+ cross_build_p = config_cross_build?
214
+ message "Cross build is #{cross_build_p ? "enabled" : "disabled"}.\n"
215
+
216
+ recipe.host = target_host
217
+ # Ensure x64-mingw-ucrt and x64-mingw32 use different library paths since the host
218
+ # is the same (x86_64-w64-mingw32).
219
+ recipe.target = File.join(recipe.target, target_arch) if cross_build_p
220
+
221
+ yield recipe
222
+
223
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
224
+ name = recipe.name
225
+ version = recipe.version
226
+
227
+ if File.exist?(checkpoint)
228
+ message("Building re2 with a packaged version of #{name}-#{version}.\n")
229
+ else
230
+ message(<<~EOM)
231
+ ---------- IMPORTANT NOTICE ----------
232
+ Building re2 with a packaged version of #{name}-#{version}.
233
+ Configuration options: #{recipe.configure_options.shelljoin}
234
+ EOM
235
+
236
+ unless recipe.patch_files.empty?
237
+ message("The following patches are being applied:\n")
238
+
239
+ recipe.patch_files.each do |patch|
240
+ message(" - %s\n" % File.basename(patch))
241
+ end
242
+ end
243
+
244
+ # Use a temporary base directory to reduce filename lengths since
245
+ # Windows can hit a limit of 250 characters (CMAKE_OBJECT_PATH_MAX).
246
+ with_temp_dir { recipe.cook }
247
+
248
+ FileUtils.touch(checkpoint)
249
+ end
250
+
251
+ recipe.activate
252
+ end
253
+
254
+ def build_with_system_libraries
255
+ header_dirs = [
256
+ "/usr/local/include",
257
+ "/opt/homebrew/include",
258
+ "/usr/include"
259
+ ]
260
+
261
+ lib_dirs = [
262
+ "/usr/local/lib",
263
+ "/opt/homebrew/lib",
264
+ "/usr/lib"
265
+ ]
266
+
267
+ dir_config("re2", header_dirs, lib_dirs)
268
+
269
+ build_extension
270
+ end
271
+
272
+ # pkgconf v1.9.3 on Windows incorrectly sorts the output of `pkg-config
273
+ # --libs --static`, resulting in build failures: https://github.com/pkgconf/pkgconf/issues/268.
274
+ # To work around the issue, store the correct order of abseil flags here and add them manually
275
+ # for Windows.
276
+ #
277
+ # Note that `-ldbghelp` is incorrectly added before `-labsl_symbolize` in abseil:
278
+ # https://github.com/abseil/abseil-cpp/issues/1497
279
+ ABSL_LDFLAGS = %w[
280
+ -labsl_flags
281
+ -labsl_flags_internal
282
+ -labsl_flags_marshalling
283
+ -labsl_flags_reflection
284
+ -labsl_flags_private_handle_accessor
285
+ -labsl_flags_commandlineflag
286
+ -labsl_flags_commandlineflag_internal
287
+ -labsl_flags_config
288
+ -labsl_flags_program_name
289
+ -labsl_cord
290
+ -labsl_cordz_info
291
+ -labsl_cord_internal
292
+ -labsl_cordz_functions
293
+ -labsl_cordz_handle
294
+ -labsl_crc_cord_state
295
+ -labsl_crc32c
296
+ -labsl_crc_internal
297
+ -labsl_crc_cpu_detect
298
+ -labsl_hash
299
+ -labsl_city
300
+ -labsl_bad_variant_access
301
+ -labsl_low_level_hash
302
+ -labsl_raw_hash_set
303
+ -labsl_hashtablez_sampler
304
+ -labsl_exponential_biased
305
+ -labsl_bad_optional_access
306
+ -labsl_str_format_internal
307
+ -labsl_synchronization
308
+ -labsl_graphcycles_internal
309
+ -labsl_stacktrace
310
+ -labsl_symbolize
311
+ -ldbghelp
312
+ -labsl_debugging_internal
313
+ -labsl_demangle_internal
314
+ -labsl_malloc_internal
315
+ -labsl_time
316
+ -labsl_civil_time
317
+ -labsl_strings
318
+ -labsl_strings_internal
319
+ -ladvapi32
320
+ -labsl_base
321
+ -labsl_spinlock_wait
322
+ -labsl_int128
323
+ -labsl_throw_delegate
324
+ -labsl_raw_logging_internal
325
+ -labsl_log_severity
326
+ -labsl_time_zone
327
+ ].freeze
328
+
329
+ def add_static_ldflags(flags)
330
+ static_flags = flags.split
331
+
332
+ if MiniPortile.windows?
333
+ static_flags.each { |flag| append_ldflags(flag) unless ABSL_LDFLAGS.include?(flag) }
334
+ ABSL_LDFLAGS.each { |flag| append_ldflags(flag) }
335
+ else
336
+ static_flags.each { |flag| append_ldflags(flag) }
337
+ end
338
+ end
339
+
340
+ def build_with_vendored_libraries
341
+ message "Building re2 using packaged libraries.\n"
342
+
343
+ abseil_recipe, re2_recipe = load_recipes
344
+
345
+ process_recipe(abseil_recipe) do |recipe|
346
+ recipe.configure_options += ['-DABSL_PROPAGATE_CXX_STD=ON', '-DCMAKE_CXX_VISIBILITY_PRESET=hidden']
347
+ end
348
+
349
+ process_recipe(re2_recipe) do |recipe|
350
+ recipe.configure_options += ["-DCMAKE_PREFIX_PATH=#{abseil_recipe.path}", '-DCMAKE_CXX_FLAGS=-DNDEBUG',
351
+ '-DCMAKE_CXX_VISIBILITY_PRESET=hidden']
352
+ end
353
+
354
+ dir_config("re2", File.join(re2_recipe.path, 'include'), File.join(re2_recipe.path, 'lib'))
355
+ dir_config("abseil", File.join(abseil_recipe.path, 'include'), File.join(abseil_recipe.path, 'lib'))
356
+
357
+ pkg_config_paths = [
358
+ "#{abseil_recipe.path}/lib/pkgconfig",
359
+ "#{re2_recipe.path}/lib/pkgconfig"
360
+ ].join(File::PATH_SEPARATOR)
361
+
362
+ pkg_config_paths = "#{ENV['PKG_CONFIG_PATH']}#{File::PATH_SEPARATOR}#{pkg_config_paths}" if ENV['PKG_CONFIG_PATH']
363
+
364
+ ENV['PKG_CONFIG_PATH'] = pkg_config_paths
365
+ pc_file = File.join(re2_recipe.path, 'lib', 'pkgconfig', 're2.pc')
366
+
367
+ raise 'Please install the `pkg-config` utility!' unless find_executable('pkg-config')
368
+
369
+ # See https://bugs.ruby-lang.org/issues/18490, broken in Ruby 3.1 but fixed in Ruby 3.2.
370
+ flags = xpopen(['pkg-config', '--libs', '--static', pc_file], err: %i[child out], &:read)
371
+
372
+ raise 'Unable to run pkg-config --libs --static' unless $?.success?
373
+
374
+ add_static_ldflags(flags)
375
+ build_extension
376
+ end
377
+
378
+ if config_system_libraries?
379
+ build_with_system_libraries
380
+ else
381
+ build_with_vendored_libraries
382
+ end
383
+
384
+ create_makefile("re2")