Skip to content

Commit

Permalink
Try building the testing for RE2 with CMake again.
Browse files Browse the repository at this point in the history
Benchmark on Ubuntu seems problematic with LTO, so... disable LTO.

GoogleTest on Windows makes MSVC's linker give "already defined in
testing.lib(exhaustive_tester.obj)" errors, so... frob the testing
library in the faint hope that the issue will finally be resolved.

Change-Id: Ib4237d44a12aa5bd2783d6b1285a5ccb14df4665
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61330
Reviewed-by: Perry Lorier <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed May 19, 2023
1 parent 07bd28d commit 6dbafa4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
10 changes: 4 additions & 6 deletions .github/cmake.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/bin/bash
set -eux

cmake . -D CMAKE_BUILD_TYPE=Debug "$@"
cmake . -D CMAKE_BUILD_TYPE=Debug -D RE2_BUILD_TESTING=ON "$@"
cmake --build . --config Debug --clean-first
# TODO: Build the testing for RE2.
# ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random'
ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random'

cmake . -D CMAKE_BUILD_TYPE=Release "$@"
cmake . -D CMAKE_BUILD_TYPE=Release -D RE2_BUILD_TESTING=ON "$@"
cmake --build . --config Release --clean-first
# TODO: Build the testing for RE2.
# ctest -C Release --output-on-failure -E 'dfa|exhaustive|random'
ctest -C Release --output-on-failure -E 'dfa|exhaustive|random'

exit 0
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ if(RE2_BUILD_TESTING)
util/pcre.cc
)

add_library(testing STATIC ${TESTING_SOURCES})
add_library(testing ${TESTING_SOURCES})
target_compile_features(testing PUBLIC cxx_std_14)
target_link_libraries(testing PUBLIC re2)
target_link_libraries(testing PUBLIC re2 GTest::gtest)

set(TEST_TARGETS
charclass_test
Expand Down Expand Up @@ -208,14 +208,20 @@ if(RE2_BUILD_TESTING)
foreach(target ${TEST_TARGETS})
add_executable(${target} re2/testing/${target}.cc)
target_compile_features(${target} PUBLIC cxx_std_14)
target_link_libraries(${target} PUBLIC testing GTest::gtest GTest::gtest_main ${EXTRA_TARGET_LINK_LIBRARIES})
target_link_libraries(${target} PUBLIC testing GTest::gtest_main ${EXTRA_TARGET_LINK_LIBRARIES})
add_test(NAME ${target} COMMAND ${target})
endforeach()

foreach(target ${BENCHMARK_TARGETS})
add_executable(${target} re2/testing/${target}.cc)
target_compile_features(${target} PUBLIC cxx_std_14)
target_link_libraries(${target} PUBLIC testing GTest::gtest benchmark::benchmark benchmark::benchmark_main ${EXTRA_TARGET_LINK_LIBRARIES})
target_link_libraries(${target} PUBLIC testing benchmark::benchmark_main ${EXTRA_TARGET_LINK_LIBRARIES})
# For GitHub Actions on Ubuntu 22.04 LTS, GCC gives "lto1: fatal error:
# bytecode stream in file ‘/usr/lib/x86_64-linux-gnu/libbenchmark_main.a’
# generated with LTO version 11.2 instead of the expected 11.3" errors,
# but it's unclear what the proper fix should be, so disable LTO for now.
set_target_properties(${target} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION FALSE)
endforeach()
endif()

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ABSL_DEPS=\
absl_synchronization\

CCABSL=$(shell pkg-config $(ABSL_DEPS) --cflags)
# GCC barfs on `-Wl` whereas Clang doesn't mind, but it's unclear
# what causes it to manifest on Ubuntu, so filter it out for now.
# GCC barfs on `-Wl` whereas Clang doesn't mind, but it's unclear what
# causes it to manifest on Ubuntu 22.04 LTS, so filter it out for now.
LDABSL=$(shell pkg-config $(ABSL_DEPS) --libs | sed -e 's/-Wl / /g')

# To build against ICU for full Unicode properties support,
Expand Down
4 changes: 2 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def build_extension(self, ext):
cmd = ['bazel', 'clean', '--expunge']
self.spawn(cmd)

cmd = ['bazel', 'build', '--compilation_mode=opt']
cmd = ['bazel', 'build']
cmd.append(f'--config={os.environ["RUNNER_OS"].lower()}')
if 'BAZEL_CPU' in os.environ:
cmd.append(f'--cpu={os.environ["BAZEL_CPU"].lower()}')
cmd += ['--', ':all']
cmd += ['--compilation_mode=opt', '--', ':all']
self.spawn(cmd)

# This ensures that f'_re2.{importlib.machinery.EXTENSION_SUFFIXES[0]}'
Expand Down
1 change: 0 additions & 1 deletion re2/testing/regexp_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "absl/strings/str_format.h"
#include "absl/synchronization/mutex.h"
#include "benchmark/benchmark.h"
#include "gtest/gtest.h"
#include "util/logging.h"
#include "util/malloc_counter.h"
#include "re2/prog.h"
Expand Down

0 comments on commit 6dbafa4

Please sign in to comment.