Skip to content

Commit d4e08e5

Browse files
authored
CDRIVER-6064 Restore cmake_policy, fix uninstall checks, and use Ninja with mingw-w64 (#2070)
* Remove obsolete ENABLE_AUTOMATIC_INIT_AND_CLEANUP config variable * Restore cmake_policy() in GenerateUninstaller.cmake * Improve Batch script error-handling behavior * Use Ninja generator for mingw-w64 compilation * Fix simple HTTP server port number * Move uninstall checks into std-matrix * Avoid using ls --almost-all for MacOS compatibility * Add NEWS entries
1 parent d3165e0 commit d4e08e5

19 files changed

+170
-666
lines changed

.evergreen/config_generator/etc/distros.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ def compiler_to_vars(compiler):
221221
'CMAKE_GENERATOR_PLATFORM': to_platform(vs),
222222
}
223223

224+
case _, ['mingw', *rest]:
225+
return {
226+
'CC': '-'.join(['gcc'] + rest),
227+
'CXX': '-'.join(['g++'] + rest),
228+
}
229+
224230
case compiler, _:
225231
return {
226232
'CC': compiler,

.evergreen/generated_configs/legacy-config.yml

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -797,57 +797,6 @@ tasks:
797797
sudo rm -rf ../build ../mock-result ../rpm.tar.gz
798798
export MOCK_TARGET_CONFIG=rocky+epel-8-aarch64
799799
.evergreen/scripts/build_snapshot_rpm.sh
800-
- name: install-uninstall-check-mingw
801-
commands:
802-
- func: find-cmake-latest
803-
- command: shell.exec
804-
type: test
805-
params:
806-
working_dir: mongoc
807-
include_expansions_in_env:
808-
- distro_id
809-
shell: bash
810-
script: |-
811-
set -o errexit
812-
. .evergreen/scripts/find-cmake-latest.sh
813-
export CMAKE="$(find_cmake_latest)"
814-
export CC="C:/mingw-w64/x86_64-4.9.1-posix-seh-rt_v3-rev1/mingw64/bin/gcc.exe"
815-
BSON_ONLY=1 cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
816-
cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
817-
- name: install-uninstall-check-msvc
818-
commands:
819-
- func: find-cmake-latest
820-
- command: shell.exec
821-
type: test
822-
params:
823-
working_dir: mongoc
824-
include_expansions_in_env:
825-
- distro_id
826-
shell: bash
827-
script: |-
828-
set -o errexit
829-
. .evergreen/scripts/find-cmake-latest.sh
830-
export CMAKE="$(find_cmake_latest)"
831-
export CC="Visual Studio 14 2015 Win64"
832-
BSON_ONLY=1 cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
833-
cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
834-
- name: install-uninstall-check
835-
commands:
836-
- func: find-cmake-latest
837-
- command: shell.exec
838-
type: test
839-
params:
840-
working_dir: mongoc
841-
include_expansions_in_env:
842-
- distro_id
843-
shell: bash
844-
script: |-
845-
set -o errexit
846-
. .evergreen/scripts/find-cmake-latest.sh
847-
export CMAKE="$(find_cmake_latest)"
848-
DESTDIR="$(pwd)/dest" .evergreen/scripts/install-uninstall-check.sh
849-
BSON_ONLY=1 .evergreen/scripts/install-uninstall-check.sh
850-
.evergreen/scripts/install-uninstall-check.sh
851800
- name: debug-compile-with-warnings
852801
commands:
853802
- func: find-cmake-latest
@@ -16284,13 +16233,6 @@ buildvariants:
1628416233
distros:
1628516234
- windows-vsCurrent-large
1628616235
- check-headers
16287-
- install-uninstall-check
16288-
- name: install-uninstall-check-mingw
16289-
distros:
16290-
- windows-vsCurrent-large
16291-
- name: install-uninstall-check-msvc
16292-
distros:
16293-
- windows-vsCurrent-large
1629416236
- debug-compile-with-warnings
1629516237
- name: build-and-test-with-toolchain
1629616238
distros:

.evergreen/generated_configs/tasks.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,8 +5181,8 @@ tasks:
51815181
- func: find-cmake-latest
51825182
- func: sasl-sspi-winssl-compile
51835183
vars:
5184-
CC: mingw
5185-
CXX: mingw
5184+
CC: gcc
5185+
CXX: g++
51865186
- func: upload-build
51875187
- name: sasl-sspi-winssl-windows-2019-mingw-test-8.0-server-auth
51885188
run_on: windows-vsCurrent-small
@@ -5195,8 +5195,8 @@ tasks:
51955195
- command: expansions.update
51965196
params:
51975197
updates:
5198-
- { key: CC, value: mingw }
5199-
- { key: CXX, value: mingw }
5198+
- { key: CC, value: gcc }
5199+
- { key: CXX, value: g++ }
52005200
- { key: AUTH, value: auth }
52015201
- { key: MONGODB_VERSION, value: "8.0" }
52025202
- { key: TOPOLOGY, value: server }
@@ -5216,8 +5216,8 @@ tasks:
52165216
- command: expansions.update
52175217
params:
52185218
updates:
5219-
- { key: CC, value: mingw }
5220-
- { key: CXX, value: mingw }
5219+
- { key: CC, value: gcc }
5220+
- { key: CXX, value: g++ }
52215221
- { key: AUTH, value: auth }
52225222
- { key: MONGODB_VERSION, value: latest }
52235223
- { key: TOPOLOGY, value: server }

.evergreen/legacy_config_generator/evergreen_config_lib/tasks.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -279,51 +279,6 @@ def __init__(
279279
shell_mongoc("sudo rm -rf ../build ../mock-result ../rpm.tar.gz\n" "export MOCK_TARGET_CONFIG=rocky+epel-8-aarch64\n" ".evergreen/scripts/build_snapshot_rpm.sh"),
280280
],
281281
),
282-
NamedTask(
283-
"install-uninstall-check-mingw",
284-
commands=[
285-
func("find-cmake-latest"),
286-
shell_mongoc(
287-
r"""
288-
. .evergreen/scripts/find-cmake-latest.sh
289-
export CMAKE="$(find_cmake_latest)"
290-
export CC="C:/mingw-w64/x86_64-4.9.1-posix-seh-rt_v3-rev1/mingw64/bin/gcc.exe"
291-
BSON_ONLY=1 cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
292-
cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd""",
293-
include_expansions_in_env=["distro_id"],
294-
)
295-
],
296-
),
297-
NamedTask(
298-
"install-uninstall-check-msvc",
299-
commands=[
300-
func("find-cmake-latest"),
301-
shell_mongoc(
302-
r"""
303-
. .evergreen/scripts/find-cmake-latest.sh
304-
export CMAKE="$(find_cmake_latest)"
305-
export CC="Visual Studio 14 2015 Win64"
306-
BSON_ONLY=1 cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd
307-
cmd.exe /c .\\.evergreen\\scripts\\install-uninstall-check-windows.cmd""",
308-
include_expansions_in_env=["distro_id"],
309-
)
310-
],
311-
),
312-
NamedTask(
313-
"install-uninstall-check",
314-
commands=[
315-
func("find-cmake-latest"),
316-
shell_mongoc(
317-
r"""
318-
. .evergreen/scripts/find-cmake-latest.sh
319-
export CMAKE="$(find_cmake_latest)"
320-
DESTDIR="$(pwd)/dest" .evergreen/scripts/install-uninstall-check.sh
321-
BSON_ONLY=1 .evergreen/scripts/install-uninstall-check.sh
322-
.evergreen/scripts/install-uninstall-check.sh""",
323-
include_expansions_in_env=["distro_id"],
324-
)
325-
],
326-
),
327282
CompileTask("debug-compile-with-warnings", CFLAGS="-Werror -Wno-cast-align"),
328283
CompileTask(
329284
"debug-compile-nosasl-openssl-1.0.1",

.evergreen/legacy_config_generator/evergreen_config_lib/variants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ def days(n: int) -> int:
6464
OD([("name", "link-with-bson-mac"), ("distros", ["macos-14-arm64"])]),
6565
OD([("name", "link-with-bson-mingw"), ("distros", ["windows-vsCurrent-large"])]),
6666
"check-headers",
67-
"install-uninstall-check",
68-
OD([("name", "install-uninstall-check-mingw"), ("distros", ["windows-vsCurrent-large"])]),
69-
OD([("name", "install-uninstall-check-msvc"), ("distros", ["windows-vsCurrent-large"])]),
7067
"debug-compile-with-warnings",
7168
OD([("name", "build-and-test-with-toolchain"), ("distros", ["debian11-small"])]),
7269
"install-libmongoc-after-libbson",

.evergreen/scripts/compile-std.sh

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ script_dir="$(to_absolute "$(dirname "${BASH_SOURCE[0]}")")"
2222
declare mongoc_dir
2323
mongoc_dir="$(to_absolute "${script_dir}/../..")"
2424

25-
declare install_dir="${mongoc_dir}/install-dir"
25+
declare libmongocrypt_install_dir="${mongoc_dir}/libmongocrypt-install-dir"
2626

2727
declare -a configure_flags
2828

@@ -38,7 +38,7 @@ configure_flags_append_if_not_null() {
3838
fi
3939
}
4040

41-
configure_flags_append "-DCMAKE_PREFIX_PATH=${install_dir}"
41+
configure_flags_append "-DCMAKE_PREFIX_PATH=${libmongocrypt_install_dir:?}"
4242
configure_flags_append "-DCMAKE_SKIP_RPATH=TRUE" # Avoid hardcoding absolute paths to dependency libraries.
4343
configure_flags_append "-DENABLE_CLIENT_SIDE_ENCRYPTION=ON"
4444
configure_flags_append "-DENABLE_DEBUG_ASSERTIONS=ON"
@@ -90,15 +90,15 @@ CXXFLAGS+=" ${flags+${flags[*]}}"
9090
declare cmake_binary
9191
cmake_binary="$(find_cmake_latest)"
9292

93-
declare build_dir
94-
build_dir="cmake-build"
93+
declare mongoc_build_dir mongoc_install_dir
94+
mongoc_build_dir="cmake-build"
95+
mongoc_install_dir="cmake-install"
96+
97+
configure_flags_append "-DCMAKE_INSTALL_PREFIX=${mongoc_install_dir:?}"
9598

9699
# shellcheck source=.evergreen/scripts/add-build-dirs-to-paths.sh
97100
. "${script_dir}/add-build-dirs-to-paths.sh"
98101

99-
export PKG_CONFIG_PATH
100-
PKG_CONFIG_PATH="${install_dir}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
101-
102102
if [[ "${OSTYPE}" == darwin* ]]; then
103103
# MacOS does not have nproc.
104104
nproc() {
@@ -164,7 +164,7 @@ echo "Checking requested C standard is supported... done."
164164

165165
echo "Installing libmongocrypt..."
166166
# shellcheck source=.evergreen/scripts/compile-libmongocrypt.sh
167-
"${script_dir}/compile-libmongocrypt.sh" "${cmake_binary}" "${mongoc_dir}" "${install_dir}" &>output.txt || {
167+
"${script_dir}/compile-libmongocrypt.sh" "${cmake_binary}" "${mongoc_dir}" "${libmongocrypt_install_dir:?}" &>output.txt || {
168168
cat output.txt 1>&2
169169
exit 1
170170
}
@@ -187,9 +187,39 @@ else
187187
all_target="all"
188188
fi
189189

190-
"${cmake_binary}" -S . -B "${build_dir:?}" "${configure_flags[@]}"
191-
"${cmake_binary}" --build "${build_dir:?}" --config Debug \
190+
# Ensure we're starting with a clean slate.
191+
rm -rf "${mongoc_build_dir:?}" "${mongoc_install_dir:?}"
192+
193+
"${cmake_binary}" -S . -B "${mongoc_build_dir:?}" "${configure_flags[@]}"
194+
"${cmake_binary}" --build "${mongoc_build_dir:?}" --config Debug \
192195
--target mongo_c_driver_tests \
193196
--target mongo_c_driver_examples \
194197
--target public-header-warnings \
195198
--target "${all_target:?}"
199+
"${cmake_binary}" --install "${mongoc_build_dir:?}" --config Debug
200+
201+
# "lib" vs. "lib64"
202+
if [[ -d "${mongoc_install_dir:?}/lib64" ]]; then
203+
lib_dir="lib64"
204+
else
205+
lib_dir="lib"
206+
fi
207+
208+
# This file should not be deleted!
209+
touch "${mongoc_install_dir:?}/${lib_dir:?}/canary.txt"
210+
211+
# Linux/MacOS: uninstall.sh
212+
# Windows: uninstall.cmd
213+
"${cmake_binary}" --build "${mongoc_build_dir:?}" --target uninstall || true # CDRIVER-6062
214+
215+
# No files should remain except canary.txt.
216+
# No directories except top-level directories should remain.
217+
echo "Checking results of uninstall..."
218+
diff <(cd "${mongoc_install_dir:?}" && find . -mindepth 1 | sort) <(
219+
echo "./bin"
220+
echo "./include"
221+
echo "./${lib_dir:?}"
222+
echo "./${lib_dir:?}/canary.txt"
223+
echo "./share"
224+
)
225+
echo "Checking results of uninstall... done."

.evergreen/scripts/compile-windows.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ IFS=' ' read -ra extra_configure_flags <<<"${EXTRA_CONFIGURE_FLAGS:-}"
5656

5757
configure_flags_append "-DCMAKE_INSTALL_PREFIX=$(native-path "${install_dir}")"
5858
configure_flags_append "-DCMAKE_PREFIX_PATH=$(native-path "${install_dir}")"
59-
configure_flags_append "-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF"
6059
configure_flags_append "-DENABLE_MAINTAINER_FLAGS=ON"
6160

6261
configure_flags_append_if_not_null C_STD_VERSION "-DCMAKE_C_STANDARD=${C_STD_VERSION:-}"
@@ -98,17 +97,15 @@ CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
9897
declare build_dir
9998
build_dir="cmake-build"
10099

101-
if [[ "${CC}" =~ mingw ]]; then
100+
if [[ "${CC}" =~ 'gcc' ]]; then
102101
# MinGW has trouble compiling src/cpp-check.cpp without some assistance.
103102
configure_flags_append "-DCMAKE_CXX_STANDARD=11"
104103

105104
env \
106-
"CC=gcc" \
107-
"CXX=g++" \
108105
"${cmake_binary:?}" \
109106
-S . \
110107
-B "${build_dir:?}" \
111-
-G "MinGW Makefiles" \
108+
-G "Ninja" \
112109
"${configure_flags[@]}" \
113110
"${extra_configure_flags[@]}"
114111

0 commit comments

Comments
 (0)