From 0910de6319723df6bf71e3045d8443f68759b544 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Mon, 19 May 2025 13:36:22 -0400 Subject: [PATCH 1/4] add regression test --- .../projects/bsoncxx/pkg-config/static/build.sh | 8 ++++++++ .../projects/mongocxx/pkg-config/static/build.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/examples/projects/bsoncxx/pkg-config/static/build.sh b/examples/projects/bsoncxx/pkg-config/static/build.sh index b935e4fb38..7b285836de 100755 --- a/examples/projects/bsoncxx/pkg-config/static/build.sh +++ b/examples/projects/bsoncxx/pkg-config/static/build.sh @@ -11,6 +11,14 @@ set -o pipefail exit 1 ) +# Sanity-check that static libbson is required. Regression test for CXX-3290. +(pkg-config --print-requires libbsoncxx-static | grep -- bson2-static || ( + ( + echo "Expected bson2-static to be required" >&2 + exit 1 + ) +)) + rm -rf build/* cd build "${CXX:?}" $CXXFLAGS -Wall -Wextra -Werror -std="c++${CXX_STANDARD:?}" -c -o hello_bsoncxx.o ../../../hello_bsoncxx.cpp $(pkg-config --cflags libbsoncxx-static) diff --git a/examples/projects/mongocxx/pkg-config/static/build.sh b/examples/projects/mongocxx/pkg-config/static/build.sh index c48b100064..21da4af559 100755 --- a/examples/projects/mongocxx/pkg-config/static/build.sh +++ b/examples/projects/mongocxx/pkg-config/static/build.sh @@ -16,6 +16,21 @@ set -o pipefail exit 1 ) +# Sanity-check that static libbson/libmongoc is required. Regression test for CXX-3290. +(pkg-config --print-requires libmongocxx-static | grep -- mongoc2-static || ( + ( + echo "Expected mongoc2-static to be required" >&2 + exit 1 + ) +)) + +(pkg-config --print-requires libmongocxx-static | grep -- bson2-static || ( + ( + echo "Expected bson2-static to be required" >&2 + exit 1 + ) +)) + rm -rf build/* cd build "${CXX:?}" $CXXFLAGS -Wall -Wextra -Werror -std="c++${CXX_STANDARD:?}" -c -o hello_mongocxx.o ../../../hello_mongocxx.cpp $(pkg-config --cflags libmongocxx-static) From 9b95e0d784e6809a2a1db0e2a738b1f3096fb791 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Mon, 19 May 2025 13:38:26 -0400 Subject: [PATCH 2/4] CXX-3290 fix static pkg-config C driver dependencies Restore behavior prior to 4.1.0: Have static libbsoncxx depend on static (not shared) libbson. Have static libmongocxx depend on static (not shared) libmongoc. --- src/bsoncxx/cmake/generate-pc.cmake | 2 +- src/mongocxx/cmake/generate-pc.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bsoncxx/cmake/generate-pc.cmake b/src/bsoncxx/cmake/generate-pc.cmake index 0630f1a955..14f151a383 100644 --- a/src/bsoncxx/cmake/generate-pc.cmake +++ b/src/bsoncxx/cmake/generate-pc.cmake @@ -26,7 +26,7 @@ if(1) set(requires "") if(is_static) - list(APPEND requires "bson2 >= ${bson_req_ver}") + list(APPEND requires "bson2-static >= ${bson_req_ver}") endif() list(JOIN requires ", " requires) diff --git a/src/mongocxx/cmake/generate-pc.cmake b/src/mongocxx/cmake/generate-pc.cmake index 9d19df453a..9ae35525d1 100644 --- a/src/mongocxx/cmake/generate-pc.cmake +++ b/src/mongocxx/cmake/generate-pc.cmake @@ -28,7 +28,7 @@ if(1) if(is_static) list(APPEND requires "lib${bsoncxx_name} >= ${version}") - list(APPEND requires "mongoc2 >= ${mongoc_req_ver}") + list(APPEND requires "mongoc2-static >= ${mongoc_req_ver}") else() list(APPEND requires "lib${bsoncxx_name} >= ${version}") endif() From 40c96075eebe2cff6fd2d8259363e8df26c77e9c Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Mon, 19 May 2025 14:31:56 -0400 Subject: [PATCH 3/4] do not expect libbson transitive dependency in output --- examples/projects/mongocxx/pkg-config/static/build.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/projects/mongocxx/pkg-config/static/build.sh b/examples/projects/mongocxx/pkg-config/static/build.sh index 21da4af559..7ddcce8a67 100755 --- a/examples/projects/mongocxx/pkg-config/static/build.sh +++ b/examples/projects/mongocxx/pkg-config/static/build.sh @@ -16,7 +16,7 @@ set -o pipefail exit 1 ) -# Sanity-check that static libbson/libmongoc is required. Regression test for CXX-3290. +# Sanity-check that static libmongoc is required. Regression test for CXX-3290. (pkg-config --print-requires libmongocxx-static | grep -- mongoc2-static || ( ( echo "Expected mongoc2-static to be required" >&2 @@ -24,13 +24,6 @@ set -o pipefail ) )) -(pkg-config --print-requires libmongocxx-static | grep -- bson2-static || ( - ( - echo "Expected bson2-static to be required" >&2 - exit 1 - ) -)) - rm -rf build/* cd build "${CXX:?}" $CXXFLAGS -Wall -Wextra -Werror -std="c++${CXX_STANDARD:?}" -c -o hello_mongocxx.o ../../../hello_mongocxx.cpp $(pkg-config --cflags libmongocxx-static) From e31be8fe16af031c7f0c42e0f9e7aa0855488e2d Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Mon, 19 May 2025 15:59:41 -0400 Subject: [PATCH 4/4] remove subshells, use `-q` --- .../bsoncxx/pkg-config/shared/build.sh | 9 +++--- .../bsoncxx/pkg-config/static/build.sh | 19 +++++------- .../mongocxx/pkg-config/shared/build.sh | 19 ++++++------ .../mongocxx/pkg-config/static/build.sh | 29 +++++++++---------- 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/examples/projects/bsoncxx/pkg-config/shared/build.sh b/examples/projects/bsoncxx/pkg-config/shared/build.sh index eee240b6cf..c7d6eade58 100755 --- a/examples/projects/bsoncxx/pkg-config/shared/build.sh +++ b/examples/projects/bsoncxx/pkg-config/shared/build.sh @@ -5,11 +5,10 @@ set -o pipefail # Sanity-check that static library macros are not set when building against the shared library. # Users don't need to include this section in their projects. -(pkg-config --cflags libbsoncxx | grep -v -- -DBSONCXX_STATIC) || - ( - echo "Expected BSONCXX_STATIC to not be set" >&2 - exit 1 - ) +if ! pkg-config --cflags libbsoncxx | grep -v -q -- -DBSONCXX_STATIC; then + echo "Expected BSONCXX_STATIC to not be set" >&2 + exit 1 +fi rm -rf build/* cd build diff --git a/examples/projects/bsoncxx/pkg-config/static/build.sh b/examples/projects/bsoncxx/pkg-config/static/build.sh index 7b285836de..6c724769bf 100755 --- a/examples/projects/bsoncxx/pkg-config/static/build.sh +++ b/examples/projects/bsoncxx/pkg-config/static/build.sh @@ -5,19 +5,16 @@ set -o pipefail # Sanity-check that static library macros are set when building against the static library. Users # don't need to include this section in their projects. -(pkg-config --cflags libbsoncxx-static | grep -- -DBSONCXX_STATIC) || - ( - echo "Expected BSONCXX_STATIC to be set" >&2 - exit 1 - ) +if ! pkg-config --cflags libbsoncxx-static | grep -q -- -DBSONCXX_STATIC; then + echo "Expected BSONCXX_STATIC to be set" >&2 + exit 1 +fi # Sanity-check that static libbson is required. Regression test for CXX-3290. -(pkg-config --print-requires libbsoncxx-static | grep -- bson2-static || ( - ( - echo "Expected bson2-static to be required" >&2 - exit 1 - ) -)) +if ! pkg-config --print-requires libbsoncxx-static | grep -q -- bson2-static; then + echo "Expected bson2-static to be required" >&2 + exit 1 +fi rm -rf build/* cd build diff --git a/examples/projects/mongocxx/pkg-config/shared/build.sh b/examples/projects/mongocxx/pkg-config/shared/build.sh index c34d97c000..38c6a9ca61 100755 --- a/examples/projects/mongocxx/pkg-config/shared/build.sh +++ b/examples/projects/mongocxx/pkg-config/shared/build.sh @@ -5,16 +5,15 @@ set -o pipefail # Sanity-check that static library macros are not set when building against the shared library. # Users don't need to include this section in their projects. -(pkg-config --cflags libmongocxx | grep -v -- -DBSONCXX_STATIC) || - ( - echo "Expected BSONCXX_STATIC to not be set" >&2 - exit 1 - ) -(pkg-config --cflags libmongocxx | grep -v -- -DMONGOCXX_STATIC) || - ( - echo "Expected MONGOCXX_STATIC to not be set" >&2 - exit 1 - ) +if ! pkg-config --cflags libmongocxx | grep -v -q -- -DBSONCXX_STATIC; then + echo "Expected BSONCXX_STATIC to not be set" >&2 + exit 1 +fi + +if ! pkg-config --cflags libmongocxx | grep -v -q -- -DMONGOCXX_STATIC; then + echo "Expected MONGOCXX_STATIC to not be set" >&2 + exit 1 +fi rm -rf build/* cd build diff --git a/examples/projects/mongocxx/pkg-config/static/build.sh b/examples/projects/mongocxx/pkg-config/static/build.sh index 7ddcce8a67..dd662ee6fd 100755 --- a/examples/projects/mongocxx/pkg-config/static/build.sh +++ b/examples/projects/mongocxx/pkg-config/static/build.sh @@ -5,24 +5,21 @@ set -o pipefail # Sanity-check that static library macros are set when building against the static library. Users # don't need to include this section in their projects. -(pkg-config --cflags libmongocxx-static | grep -- -DBSONCXX_STATIC) || - ( - echo "Expected BSONCXX_STATIC to be set" >&2 - exit 1 - ) -(pkg-config --cflags libmongocxx-static | grep -- -DMONGOCXX_STATIC) || - ( - echo "Expected MONGOCXX_STATIC to be set" >&2 - exit 1 - ) +if ! pkg-config --cflags libmongocxx-static | grep -q -- -DBSONCXX_STATIC; then + echo "Expected BSONCXX_STATIC to be set" >&2 + exit 1 +fi + +if ! pkg-config --cflags libmongocxx-static | grep -q -- -DMONGOCXX_STATIC; then + echo "Expected MONGOCXX_STATIC to be set" >&2 + exit 1 +fi # Sanity-check that static libmongoc is required. Regression test for CXX-3290. -(pkg-config --print-requires libmongocxx-static | grep -- mongoc2-static || ( - ( - echo "Expected mongoc2-static to be required" >&2 - exit 1 - ) -)) +if ! pkg-config --print-requires libmongocxx-static | grep -q -- mongoc2-static; then + echo "Expected mongoc2-static to be required" >&2 + exit 1 +fi rm -rf build/* cd build