Skip to content

CDRIVER-4234 Detect arc4random_buf using cmake #911

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
Dec 13, 2021

Conversation

ryandesign
Copy link
Contributor

Detect the availability of arc4random_buf when running cmake rather than using a hardcoded list of platforms on which it is available. Fixes build failure on Mac OS X 10.6 where it is not available.

Also now make arc4random_buf the first choice to use if it is available. Previously, if rand_r was not available, the older rand would be used even if arc4random_buf was available.

Detect the availability of arc4random_buf when running cmake rather than
using a hardcoded list of platforms on which it is available. Fixes
build failure on Mac OS X 10.6 where it is not available.
Make arc4random_buf the first choice to use if it is available.
Previously, if rand_r was not available, the older rand would be used
even if arc4random_buf was available.
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, thank you for the contribution @ryandesign!

@muzuiget
Copy link

This issue also happen in macOS 11

@ryandesign
Copy link
Contributor Author

@muzuiget Which issue are you referring to? The code should have already built fine on Mac OS X 10.7 and later, including macOS 11 and 12; it did for me. This PR was specifically to fix Mac OS X 10.6 and earlier which don't have arc4random_buf.

@muzuiget
Copy link

@ryandesign I built v1.20.0 fail on macOS 11, it report a arc4random_buf error. It looks like this PR should fix this issue.

@ryandesign
Copy link
Contributor Author

It may, but arc4random_buf exists on 10.7 and later, so if your machine is reporting that it doesn't, there is something else wrong.

@muzuiget
Copy link

muzuiget commented Dec 12, 2021

@ryandesign

I built it on Azure Pipelines macOS-11 image, it was success in v1.19.1, but fail in v1.20.0. I just update the version number, the build script didn't changed.

The build script:

VERSION=1.20.0
URL=https://github.com/mongodb/mongo-c-driver/releases/download/$VERSION/mongo-c-driver-$VERSION.tar.gz
mkdir mongo-c-driver
cd mongo-c-driver
wget -q $URL -O - | tar xz --strip-components=1
mkdir out
cd out
cmake \
    -DCMAKE_INSTALL_PREFIX="$OUTPUT_DIR" \
    -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \
    -DENABLE_MONGOC=OFF \
    ..
cmake --build . --config Release --target install

The build log:

+ cmake --build . --config Release --target install
[  1%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.o
[  2%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bson.c.o
[  4%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bson-atomic.c.o
[  5%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bson-clock.c.o
[  7%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bson-context.c.o
/Users/runner/work/1/s/build/mongo-c-driver/src/libbson/src/bson/bson-context.c:234:4: error: implicit declaration of function 'arc4random_buf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
   arc4random_buf (&result, sizeof (result));
   ^
1 error generated.
make[2]: *** [src/libbson/CMakeFiles/bson_shared.dir/src/bson/bson-context.c.o] Error 1
make[1]: *** [src/libbson/CMakeFiles/bson_shared.dir/all] Error 2
make: *** [all] Error 2
##[error]Bash exited with code '2'.

Or maybe Azure Pipelines has update the macOS-11 image, but I don't know what cause this error.

@muzuiget
Copy link

muzuiget commented Dec 12, 2021

Here is more details the macOS-11 image in build log:

Virtual Environment
Environment: macos-11
Version: 20211207.1
Included Software: https://github.com/actions/virtual-environments/blob/macOS-11/20211207.1/images/macos/macos-11-Readme.md
Image Release: https://github.com/actions/virtual-environments/releases/tag/macOS-11%2F20211207.1

@kevinAlbs
Copy link
Collaborator

@muzuiget / @ryandesign, the error on macOS 11 may be caused by CDRIVER-4233. There is a proposed fix in #910.

@ryandesign
Copy link
Contributor Author

Ohh right, I forgot about that already.

@kevinAlbs kevinAlbs merged commit 54e5ecb into mongodb:master Dec 13, 2021
@ryandesign ryandesign deleted the CDRIVER-4234 branch December 13, 2021 21:31
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