Skip to content

Commit

Permalink
Export PCRE::no_more_args and the functors.
Browse files Browse the repository at this point in the history
To produce a DLL, CMake can automatically export code symbols,
but not data symbols, so we have to annotate those manually...

Set up CI to exercise `-D BUILD_SHARED_LIBS=ON` on everything.

Fixes #429.

Change-Id: Ibc232913e5f7121b9804748ea03422862893e482
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61392
Reviewed-by: Paul Wankadia <[email protected]>
Reviewed-by: Perry Lorier <[email protected]>
  • Loading branch information
junyer committed Jun 1, 2023
1 parent 315514c commit 0f3bf78
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
56 changes: 54 additions & 2 deletions .github/workflows/ci-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ jobs:
shell: bash
- run: .github/cmake.sh
shell: bash
build-linux-shared:
runs-on: ubuntu-latest
container: gcc:13
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Install CMake
run: |
apt update -y
apt install -y cmake
shell: bash
- name: Install Abseil, GoogleTest and Benchmark
run: |
apt update -y
apt install -y libabsl-dev libgtest-dev libbenchmark-dev
shell: bash
- run: .github/cmake.sh -D BUILD_SHARED_LIBS=ON
shell: bash
build-macos:
runs-on: macos-latest
strategy:
Expand All @@ -36,7 +55,20 @@ jobs:
brew update
brew install abseil googletest google-benchmark
shell: bash
- run: .github/cmake.sh -D RE2_BUILD_FRAMEWORK=ON
- run: .github/cmake.sh
shell: bash
build-macos-shared:
runs-on: macos-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Install Abseil, GoogleTest and Benchmark
run: |
brew update
brew install abseil googletest google-benchmark
shell: bash
- run: .github/cmake.sh -D BUILD_SHARED_LIBS=ON
shell: bash
build-windows:
runs-on: windows-latest
Expand All @@ -52,5 +84,25 @@ jobs:
vcpkg update
vcpkg install abseil gtest benchmark
shell: bash
- run: .github/cmake.sh -D CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
- run: |
.github/cmake.sh \
-D CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
shell: bash
build-windows-shared:
runs-on: windows-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Install Abseil, GoogleTest and Benchmark
run: |
# TODO: Remove this in September 2023, which is when the default triplet for
# vcpkg libraries will change from x86-windows to the detected host triplet.
export VCPKG_DEFAULT_TRIPLET=x64-windows
vcpkg update
vcpkg install abseil gtest benchmark
shell: bash
- run: |
.github/cmake.sh -D BUILD_SHARED_LIBS=ON \
-D CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
shell: bash
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ if(RE2_BUILD_TESTING)
)

add_library(testing ${TESTING_SOURCES})
if(BUILD_SHARED_LIBS AND WIN32)
target_compile_definitions(testing -DRE2_BUILD_TESTING_DLL)
endif()
target_compile_features(testing PUBLIC cxx_std_14)
target_link_libraries(testing PUBLIC re2 GTest::gtest)

Expand Down Expand Up @@ -216,13 +219,19 @@ if(RE2_BUILD_TESTING)

foreach(target ${TEST_TARGETS})
add_executable(${target} re2/testing/${target}.cc)
if(BUILD_SHARED_LIBS AND WIN32)
target_compile_definitions(${target} -DRE2_CONSUME_TESTING_DLL)
endif()
target_compile_features(${target} PUBLIC cxx_std_14)
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)
if(BUILD_SHARED_LIBS AND WIN32)
target_compile_definitions(${target} -DRE2_CONSUME_TESTING_DLL)
endif()
target_compile_features(${target} PUBLIC cxx_std_14)
target_link_libraries(${target} PUBLIC testing benchmark::benchmark_main ${EXTRA_TARGET_LINK_LIBRARIES})
endforeach()
Expand Down
20 changes: 15 additions & 5 deletions util/pcre.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ const bool UsingPCRE = false;
} // namespace re2
#endif

// To produce a DLL, CMake can automatically export code symbols,
// but not data symbols, so we have to annotate those manually...
#if defined(RE2_BUILD_TESTING_DLL)
#define RE2_TESTING_DLL __declspec(dllexport)
#elif defined(RE2_CONSUME_TESTING_DLL)
#define RE2_TESTING_DLL __declspec(dllimport)
#else
#define RE2_TESTING_DLL
#endif

namespace re2 {

class PCRE_Options;
Expand All @@ -190,7 +200,7 @@ class PCRE {
// Marks end of arg list.
// ONLY USE IN OPTIONAL ARG DEFAULTS.
// DO NOT PASS EXPLICITLY.
static Arg no_more_args;
RE2_TESTING_DLL static Arg no_more_args;

// Options are same value as those in pcre. We provide them here
// to avoid users needing to include pcre.h and also to isolate
Expand Down Expand Up @@ -285,7 +295,7 @@ class PCRE {
const Arg& ptr16 = no_more_args) const;
};

static const FullMatchFunctor FullMatch;
RE2_TESTING_DLL static const FullMatchFunctor FullMatch;

// Exactly like FullMatch(), except that "pattern" is allowed to match
// a substring of "text".
Expand All @@ -309,7 +319,7 @@ class PCRE {
const Arg& ptr16 = no_more_args) const;
};

static const PartialMatchFunctor PartialMatch;
RE2_TESTING_DLL static const PartialMatchFunctor PartialMatch;

// Like FullMatch() and PartialMatch(), except that pattern has to
// match a prefix of "text", and "input" is advanced past the matched
Expand All @@ -334,7 +344,7 @@ class PCRE {
const Arg& ptr16 = no_more_args) const;
};

static const ConsumeFunctor Consume;
RE2_TESTING_DLL static const ConsumeFunctor Consume;

// Like Consume(..), but does not anchor the match at the beginning of the
// string. That is, "pattern" need not start its match at the beginning of
Expand All @@ -360,7 +370,7 @@ class PCRE {
const Arg& ptr16 = no_more_args) const;
};

static const FindAndConsumeFunctor FindAndConsume;
RE2_TESTING_DLL static const FindAndConsumeFunctor FindAndConsume;

// Replace the first match of "pattern" in "str" with "rewrite".
// Within "rewrite", backslash-escaped digits (\1 to \9) can be
Expand Down

0 comments on commit 0f3bf78

Please sign in to comment.