mudge / re2

Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python".
http://mudge.name/re2/
BSD 3-Clause "New" or "Revised" License
130 stars 13 forks source link

Ensure different Windows flavors build their own abseil library #81

Closed stanhu closed 1 year ago

stanhu commented 1 year ago

Previously if you ran:

bundle exec rake gem:x64-mingw-ucrt
bundle exec rake gem:x64-mingw32

The latter would fail with undefined symbols:

linking shared-object re2.so
/usr/bin/x86_64-w64-mingw32-ld: /tmp/re2/ports/x86_64-w64-mingw32/abseil/20230125.3/lib/libabsl_time_zone.a(time_zone_libc.cc.obj):time_zone_libc.cc:(.text+0x97): undefined reference to `__imp___timezone'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/re2/ports/x86_64-w64-mingw32/abseil/20230125.3/lib/libabsl_time_zone.a(time_zone_libc.cc.obj):time_zone_libc.cc:(.text+0xa8): undefined reference to `__imp___dstbias'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/re2/ports/x86_64-w64-mingw32/abseil/20230125.3/lib/libabsl_time_zone.a(time_zone_libc.cc.obj):time_zone_libc.cc:(.text+0xde): undefined reference to `__imp___tzname'
collect2: error: ld returned 1 exit status
make: *** [Makefile:262: re2.so] Error 1

The timezone, dstbias, and tzname symbols come from the Microsoft Runtime library.

This happened because the abseil C++ library would be installed for x64-mingw-ucrt and x64-mingw32 in the same directory based on the host value (x86_64-w64-mingw32). As a result, if x64-mingw-ucrt were built first, then the abseil libraries will link against the Universal C Runtime (UCRT). When rake gem:x64-mingw32 is attempted after rake gem:x64-mingw-ucrt, then it will fail to link those symbols because the abseil library in ports/x86_64-w64-mingw32 directory expects UCRT to be used.

To avoid this mess, append the RbConfig::CONFIG['arch'] to the mini_portile recipe to ensure x64-mingw-ucrt and x64-mingw32 builds use different library paths.

stanhu commented 1 year ago

@mudge Anything else I can do to get this merged? Would love to see 2.0 out the door: https://github.com/mudge/re2/issues/78#issuecomment-1655002674