From 552c2b8f737f871b8bd00006e0f5d4036c5a5683 Mon Sep 17 00:00:00 2001 From: Paul Wankadia Date: Wed, 17 May 2023 19:45:48 +0000 Subject: [PATCH] Fix the GNU make and CMake configurations and CI workflows. Change-Id: I0ed384b0598d2bdaec1d41b51cd0de5d49e83481 Reviewed-on: https://code-review.googlesource.com/c/re2/+/61270 Reviewed-by: Paul Wankadia Reviewed-by: Alex Chernyakhovsky --- .github/workflows/ci-cmake.yml | 15 ++++++++++ .github/workflows/ci.yml | 12 ++++++++ CMakeLists.txt | 55 ++++++++++++++++++++++++++-------- Makefile | 50 ++++++++++++++++++------------- README | 5 ++++ re2Config.cmake.in | 2 ++ 6 files changed, 107 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci-cmake.yml b/.github/workflows/ci-cmake.yml index e8cd380d2..8d9e3c7c9 100644 --- a/.github/workflows/ci-cmake.yml +++ b/.github/workflows/ci-cmake.yml @@ -11,5 +11,20 @@ jobs: os: [macos-latest, ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 + - if: matrix.os == 'macos-latest' + name: Install dependencies (macOS) + run: | + brew install abseil googletest google-benchmark + shell: bash + - if: matrix.os == 'ubuntu-latest' + name: Install dependencies (Ubuntu) + run: | + sudo apt install libabsl-dev libgtest-dev libbenchmark-dev + shell: bash + - if: matrix.os == 'windows-latest' + name: Install dependencies (Windows) + run: | + vcpkg install abseil gtest benchmark + shell: bash - run: .github/cmake.sh shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index daa7c8711..0793373e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,10 @@ jobs: CXXFLAGS: -O3 -g -std=c++${{ matrix.ver }} steps: - uses: actions/checkout@v3 + - name: Install dependencies (macOS) + run: | + brew install abseil googletest google-benchmark + shell: bash - run: make && make test shell: bash build-clang: @@ -39,6 +43,10 @@ jobs: chmod +x ./llvm.sh sudo ./llvm.sh ${{ matrix.ver }} shell: bash + - name: Install dependencies (Ubuntu) + run: | + sudo apt install libabsl-dev libgtest-dev libbenchmark-dev + shell: bash - run: make && make test shell: bash build-gcc: @@ -53,5 +61,9 @@ jobs: CXX: g++ steps: - uses: actions/checkout@v3 + - name: Install dependencies (Ubuntu) + run: | + sudo apt install libabsl-dev libgtest-dev libbenchmark-dev + shell: bash - run: make && make test shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd122330..f8f62920e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,13 @@ set(REQUIRES) # ABI version # http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html -set(SONAME 10) +set(SONAME 11) set(EXTRA_TARGET_LINK_LIBRARIES) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - if(MSVC_VERSION LESS 1900) - message(FATAL_ERROR "you need Visual Studio 2015 or later") + if(MSVC_VERSION LESS 1920) + message(FATAL_ERROR "you need Visual Studio 2019 or later") endif() if(BUILD_SHARED_LIBS) # See http://www.kitware.com/blog/home/post/939 for details. @@ -61,6 +61,24 @@ if(UNIX) find_package(Threads REQUIRED) endif() +set(ABSL_DEPS + absl_base + absl_core_headers + absl_fixed_array + absl_flags + absl_flat_hash_map + absl_flat_hash_set + absl_inlined_vector + absl_optional + absl_span + absl_str_format + absl_strings + absl_synchronization + ) + +find_package(absl REQUIRED) +list(APPEND REQUIRES ${ABSL_DEPS}) + if(RE2_USE_ICU) find_package(ICU REQUIRED COMPONENTS uc) add_definitions(-DRE2_USE_ICU) @@ -72,6 +90,12 @@ if(USEPCRE) list(APPEND EXTRA_TARGET_LINK_LIBRARIES pcre) endif() +# TODO(junyer): Use string(JOIN " " ...) whenever CMake 3.12 (or newer) becomes +# the minimum required: that will make this hack slightly less filthy. For now, +# CMake does the same thing as string(CONCAT ...), basically, if we don't quote +# ${REQUIRES}, so quote it despite prevailing style. +string(REPLACE ";" " " REQUIRES "${REQUIRES}") + set(RE2_SOURCES re2/bitmap256.cc re2/bitstate.cc @@ -90,7 +114,6 @@ set(RE2_SOURCES re2/regexp.cc re2/set.cc re2/simplify.cc - re2/stringpiece.cc re2/tostring.cc re2/unicode_casefold.cc re2/unicode_groups.cc @@ -106,7 +129,7 @@ set(RE2_HEADERS ) add_library(re2 ${RE2_SOURCES}) -target_compile_features(re2 PUBLIC cxx_std_11) +target_compile_features(re2 PUBLIC cxx_std_14) target_include_directories(re2 PUBLIC $) # CMake gives "set_target_properties called with incorrect number of arguments." # errors if we don't quote ${RE2_HEADERS}, so quote it despite prevailing style. @@ -125,11 +148,19 @@ if(UNIX) target_link_libraries(re2 PUBLIC Threads::Threads) endif() +foreach(dep ${ABSL_DEPS}) + string(REGEX REPLACE "^absl_" "absl::" dep ${dep}) + target_link_libraries(re2 PUBLIC ${dep}) +endforeach() + if(RE2_USE_ICU) target_link_libraries(re2 PUBLIC ICU::uc) endif() if(RE2_BUILD_TESTING) + find_package(GTest REQUIRED) + find_package(benchmark REQUIRED) + set(TESTING_SOURCES re2/testing/backtrack.cc re2/testing/dump.cc @@ -142,7 +173,7 @@ if(RE2_BUILD_TESTING) ) add_library(testing STATIC ${TESTING_SOURCES}) - target_compile_features(testing PUBLIC cxx_std_11) + target_compile_features(testing PUBLIC cxx_std_14) target_link_libraries(testing PUBLIC re2) set(TEST_TARGETS @@ -174,16 +205,16 @@ if(RE2_BUILD_TESTING) ) foreach(target ${TEST_TARGETS}) - add_executable(${target} re2/testing/${target}.cc util/test.cc) - target_compile_features(${target} PUBLIC cxx_std_11) - target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES}) + add_executable(${target} re2/testing/${target}.cc) + target_compile_features(${target} PUBLIC cxx_std_14) + target_link_libraries(${target} testing GTest::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 util/benchmark.cc) - target_compile_features(${target} PUBLIC cxx_std_11) - target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES}) + add_executable(${target} re2/testing/${target}.cc) + target_compile_features(${target} PUBLIC cxx_std_14) + target_link_libraries(${target} testing GTest::GTest benchmark::benchmark_main ${EXTRA_TARGET_LINK_LIBRARIES}) endforeach() endif() diff --git a/Makefile b/Makefile index 34230ca66..15750ed4e 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,24 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +# Build against Abseil. +ABSL_DEPS=\ + absl_base\ + absl_core_headers\ + absl_fixed_array\ + absl_flags\ + absl_flat_hash_map\ + absl_flat_hash_set\ + absl_inlined_vector\ + absl_optional\ + absl_span\ + absl_str_format\ + absl_strings\ + absl_synchronization\ + +CCABSL=$(shell pkg-config $(ABSL_DEPS) --cflags) +LDABSL=$(shell pkg-config $(ABSL_DEPS) --libs) + # To build against ICU for full Unicode properties support, # uncomment the next two lines: # CCICU=$(shell pkg-config icu-uc --cflags) -DRE2_USE_ICU @@ -17,8 +35,8 @@ CXX?=g++ CXXFLAGS?=-O3 -g LDFLAGS?= # required -RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCICU) $(CCPCRE) -RE2_LDFLAGS?=-pthread $(LDICU) $(LDPCRE) +RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCABSL) $(CCICU) $(CCPCRE) +RE2_LDFLAGS?=-pthread $(LDABSL) $(LDICU) $(LDPCRE) AR?=ar ARFLAGS?=rsc NM?=nm @@ -43,14 +61,14 @@ SED_INPLACE=sed -i endif # The pkg-config Requires: field. -REQUIRES= +REQUIRES=$(ABSL_DEPS) ifdef LDICU REQUIRES+=icu-uc endif # ABI version # http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html -SONAME=10 +SONAME=11 # To rebuild the Tables generated by Perl and Python scripts (requires Internet # access for Unicode data), uncomment the following line: @@ -84,17 +102,11 @@ INSTALL_HFILES=\ re2/stringpiece.h\ HFILES=\ - util/benchmark.h\ - util/flags.h\ util/logging.h\ util/malloc_counter.h\ - util/mix.h\ - util/mutex.h\ util/pcre.h\ util/strutil.h\ - util/test.h\ util/utf.h\ - util/util.h\ re2/bitmap256.h\ re2/filtered_re2.h\ re2/pod_array.h\ @@ -135,7 +147,6 @@ OFILES=\ obj/re2/regexp.o\ obj/re2/set.o\ obj/re2/simplify.o\ - obj/re2/stringpiece.o\ obj/re2/tostring.o\ obj/re2/unicode_casefold.o\ obj/re2/unicode_groups.o\ @@ -216,25 +227,24 @@ obj/so/libre2.$(SOEXT): $(SOFILES) libre2.symbols libre2.symbols.darwin ln -sf libre2.$(SOEXTVER) $@ .PRECIOUS: obj/dbg/test/% -obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES) obj/dbg/util/test.o +obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES) @mkdir -p obj/dbg/test - $(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) obj/dbg/util/test.o obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) -lgtest -lgtest_main obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) .PRECIOUS: obj/test/% -obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o +obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) @mkdir -p obj/test - $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) # Test the shared lib, falling back to the static lib for private symbols .PRECIOUS: obj/so/test/% -obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o +obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) @mkdir -p obj/so/test - $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) -# Filter out dump.o because testing::TempDir() isn't available for it. -obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES) obj/util/benchmark.o +obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES) @mkdir -p obj/test - $(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(filter-out obj/re2/testing/dump.o, $(TESTOFILES)) obj/util/benchmark.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(TESTOFILES) -lgtest -lbenchmark -lbenchmark_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) # re2_fuzzer is a target for fuzzers like libFuzzer and AFL. This fake fuzzing # is simply a way to check that the target builds and then to run it against a diff --git a/README b/README index caee6afb6..469d6f397 100644 --- a/README +++ b/README @@ -10,6 +10,11 @@ make test make install make testinstall +Building RE2 requires Abseil (https://github.com/abseil/abseil-cpp) +to be installed on your system. Building the testing for RE2 requires +GoogleTest (https://github.com/google/googletest) and Benchmark +(https://github.com/google/benchmark) to be installed as well. + There is a fair amount of documentation (including code snippets) in the re2.h header file. diff --git a/re2Config.cmake.in b/re2Config.cmake.in index 1ea3ff0a2..6a177c615 100644 --- a/re2Config.cmake.in +++ b/re2Config.cmake.in @@ -13,6 +13,8 @@ if(UNIX) find_dependency(Threads REQUIRED) endif() +find_dependency(absl REQUIRED) + if(@RE2_USE_ICU@) find_dependency(ICU REQUIRED COMPONENTS uc) endif()