Skip to content

Commit c520651

Browse files
authored
Reducing Warnings - Compile with C99 on Evergreen by default (#1067)
* CDRIVER-4136 Use -std=c99 by default for all compilation on Evergreen * Fix compatiblity issues with glibc versions 2.19 and earlier * Remove debug-compile-c99 task from Evergreen
1 parent 9c4f49f commit c520651

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

.evergreen/compile-unix.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -o errexit # Exit the script with error if any of the commands fail
44
# Supported/used environment variables:
55
# Options for this script:
66
# CFLAGS Additional compiler flags
7+
# C_STD_VERSION C standard version to compile with (default: 99)
78
# MARCH Machine Architecture. Defaults to lowercase uname -m
89
# RELEASE Use the fully qualified release archive
910
# DEBUG Use debug configure flags
@@ -28,6 +29,7 @@ set -o errexit # Exit the script with error if any of the commands fail
2829
# ZSTD Build against system zstd.
2930

3031
# Options for this script.
32+
C_STD_VERSION=${CSTD_VERSION:-99}
3133
RELEASE=${RELEASE:-OFF}
3234
DEBUG=${DEBUG:-OFF}
3335
TRACING=${TRACING:-OFF}
@@ -46,6 +48,7 @@ ZLIB=${ZLIB:-BUNDLED}
4648
INSTALL_DIR=$(pwd)/install-dir
4749

4850
echo "CFLAGS: $CFLAGS"
51+
echo "C_STD_VERSION: $C_STD_VERSION"
4952
echo "SANITIZE: $SANITIZE"
5053
echo "MARCH: $MARCH"
5154
echo "RELEASE: $RELEASE"
@@ -163,6 +166,8 @@ export ASAN_OPTIONS="detect_leaks=1 abort_on_error=1 symbolize=1"
163166
export ASAN_SYMBOLIZER_PATH="/opt/mongodbtoolchain/v3/bin/llvm-symbolizer"
164167
export TSAN_OPTIONS="suppressions=./.tsan-suppressions"
165168

169+
CONFIGURE_FLAGS="$CONFIGURE_FLAGS -DCMAKE_C_STANDARD=$C_STD_VERSION -DCMAKE_C_STANDARD_REQUIRED=ON -DCMAKE_C_EXTENSIONS=OFF"
170+
166171
case "$MARCH" in
167172
i386)
168173
CFLAGS="$CFLAGS -m32 -march=i386"

.evergreen/compile-windows.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -o errexit # Exit the script with error if any of the commands fail
44

55
# Supported/used environment variables:
66
# CC Which compiler to use
7+
# C_STD_VERSION C standard version to compile with (default: c99)
78
# SSL OPENSSL, OPENSSL_STATIC, WINDOWS, or OFF
89
# SASL AUTO, SSPI, CYRUS, or OFF
910
# SRV Whether to enable SRV: ON or OFF
@@ -21,10 +22,12 @@ CONFIGURE_FLAGS="\
2122
BUILD_FLAGS="/m" # Number of concurrent processes. No value=# of cpus
2223
CMAKE="/cygdrive/c/cmake/bin/cmake"
2324
CC=${CC:-"Visual Studio 15 2017 Win64"}
25+
C_STD_VERSION=${CSTD_VERSION:-99}
2426
SSL=${SSL:-WINDOWS}
2527
SASL=${SASL:-SSPI}
2628

2729
echo "CC: $CC"
30+
echo "C_STD_VERSION: $C_STD_VERSION"
2831
echo "RELEASE: $RELEASE"
2932
echo "SASL: $SASL"
3033

@@ -35,6 +38,8 @@ if [ "$RELEASE" ]; then
3538
cd build-dir
3639
fi
3740

41+
CONFIGURE_FLAGS="$CONFIGURE_FLAGS -DCMAKE_C_STANDARD=$C_STD_VERSION -DCMAKE_C_STANDARD_REQUIRED=ON -DCMAKE_C_EXTENSIONS=OFF"
42+
3843
CONFIGURE_FLAGS="$CONFIGURE_FLAGS -DENABLE_SASL=$SASL"
3944

4045
case "$SSL" in

.evergreen/config.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,26 +1030,7 @@ tasks:
10301030
shell: bash
10311031
script: |-
10321032
set -o errexit
1033-
export CFLAGS="-std=c11"
1034-
export DEBUG="ON"
1035-
export SANITIZE=""
1036-
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh
1037-
- func: upload build
1038-
- name: debug-compile-c99
1039-
tags:
1040-
- c99
1041-
- debug-compile
1042-
- special
1043-
- stdflags
1044-
commands:
1045-
- command: shell.exec
1046-
type: test
1047-
params:
1048-
working_dir: mongoc
1049-
shell: bash
1050-
script: |-
1051-
set -o errexit
1052-
export CFLAGS="-std=c99"
1033+
export C_STD_VERSION="11"
10531034
export DEBUG="ON"
10541035
export SANITIZE=""
10551036
CC='${CC}' MARCH='${MARCH}' sh .evergreen/compile.sh

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,21 @@ set (CMAKE_MACOSX_RPATH ON)
243243
# silence a CMake 3.11 warning that the old behavior is deprecated.
244244
cmake_policy (SET CMP0042 NEW)
245245

246-
# https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
247-
# Enable features from POSIX.1-2008 as well as certain BSD and SVID features.
248-
add_definitions (-D_DEFAULT_SOURCE)
249-
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_DEFAULT_SOURCE)
246+
# https://man7.org/linux/man-pages/man7/feature_test_macros.7.html
247+
# https://pubs.opengroup.org/onlinepubs/7908799/xsh/compilation.html
248+
# Enable POSIX features up to POSIX.1-2008 plus the XSI extension and BSD-derived definitions.
249+
# Both _BSD_SOURCE and _DEFAULT_SOURCE are defined for backwards-compatibility with glibc 2.19 and earlier.
250+
# _BSD_SOURCE and _DEFAULT_SOURCE are required by `getpagesize`, `h_errno`, etc.
251+
# _XOPEN_SOURCE=700 is required by `strnlen`, etc.
252+
add_definitions (-D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)
253+
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)
254+
255+
# https://opensource.apple.com/source/Libc/Libc-1439.40.11/gen/compat.5.auto.html
256+
# Non-POSIX extensions are required by `_SC_NPROCESSORS_ONLN`.
257+
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
258+
add_definitions (-D_DARWIN_C_SOURCE)
259+
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_DARWIN_C_SOURCE)
260+
endif ()
250261

251262
add_subdirectory (src/common)
252263

build/evergreen_config_lib/tasks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ def __init__(self, task_name, suffix_commands, orchestration=True, **kwargs):
198198
CompileTask('debug-compile-lto-thin', CFLAGS='-flto=thin'),
199199
SpecialTask('debug-compile-c11',
200200
tags=['debug-compile', 'c11', 'stdflags'],
201-
CFLAGS='-std=c11'),
202-
SpecialTask('debug-compile-c99',
203-
tags=['debug-compile', 'c99', 'stdflags'],
204-
CFLAGS='-std=c99'),
201+
C_STD_VERSION='11'),
205202
SpecialTask('debug-compile-valgrind',
206203
tags=['debug-compile', 'valgrind'],
207204
SASL='OFF',

0 commit comments

Comments
 (0)