Skip to content

Reducing Warnings - Compile with C99 on Evergreen by default #1067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2022

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Jul 12, 2022

Description

This PR is a followup to #920 and is related to CDRIVER-4136.

This PR ensures that all builds of the C Driver on Evergreen are able to be compiled with -std=c99 (or equivalent) by default to ensure strict conformance with the C99 standard across all platforms and configurations. This addresses all C89/C90 compatibility related warnings emitted due to use of C99 features.

In the spirit of minimizing platform-specific configuration flags, the C standard is specified via CMake's CMAKE_C_STANDARD and CMAKE_C_STANDARD_REQUIRED on both Linux and Windows. CMAKE_C_EXTENSIONS is set to OFF to ensure strict C99 conformance and that any extensions being depended on are explicitly opted into.

Setting CMAKE_C_EXTENSIONS to OFF exposed a configuration bug on RHEL 6.2 and RHEL 7.0, which provides glibc versions 2.12 and 2.17 respectively. #920 proposed removing _BSD_SOURCE in favor of _DEFAULT_SOURCE due to the former being deprecated; however, _DEFAULT_SOURCE is only supported given glibc version 2.19 and newer. To support glibc version 2.19 and earlier while also supporting strict C99 conformance, this PR partially reverts the changes in #920.

Therefore, the full set of compile definitions to explicitly opt into POSIX features and non-standard extensions currently being used by the C driver include:

  • _XOPEN_SOURCE=700: required to enable use of strnlen (>=700) in addition to other features in the X/Open namespace (i.e. pthread_rwlock_* (>=500)) as required by the POSIX specification.
  • _DEFAULT_SOURCE: required to enable use of getpagesize, h_errno, and other BSD-derived definitions.
  • _BSD_SOURCE: required for compatibility with glibc 2.19 and earlier.
  • _DARWIN_C_SOURCE: required to enable use of _SC_NPROCESSORS_ONLN and other non-POSIX extensions on MacOS that are otherwise disabled by _POSIX_C_SOURCE (set to 200112L by _XOPEN_SOURCE=700).

_BSD_SOURCE could be removed once all platforms with glibc version 2.19 or earlier are no longer supported.

The debug-compile-c99 task is removed due to redundancy.

@eramongodb eramongodb self-assigned this Jul 12, 2022
@@ -28,6 +29,7 @@ set -o errexit # Exit the script with error if any of the commands fail
# ZSTD Build against system zstd.

# Options for this script.
C_STD_VERSION=${CSTD_VERSION:-99}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a dedicated env var

@jmikola jmikola removed their request for review July 13, 2022 03:30
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The comments in CMakeLists.txt look helpful for future readers.

@kevinAlbs
Copy link
Collaborator

If you have not already, I suggest running a full patch build to check compile tasks on all platforms.

@eramongodb
Copy link
Contributor Author

@kevinAlbs Latest patch builds are noisy due to unrelated server compat issues, but compile tasks were verified here: https://spruce.mongodb.com/version/62cc9a6557e85a7ecf6b16f2/tasks

@@ -28,6 +29,7 @@ set -o errexit # Exit the script with error if any of the commands fail
# ZSTD Build against system zstd.

# Options for this script.
C_STD_VERSION=${CSTD_VERSION:-99}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eramongodb: I think this was a typo, but it appears to have been fixed in a subsequent commit: f4a83c0#diff-5621bd7804f10985a5f14a01ee66b14439494aa0a6cdfa6c6debd151e7c90d7aR10

Likewise for compile-windows.sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This mistake was in part what motivated the addition of the check_var_opt/check_var_req functions in the referenced commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants