|
| 1 | +VERSION --arg-scope-and-set 0.7 |
| 2 | +LOCALLY |
| 3 | + |
| 4 | +# PREP_CMAKE "warms up" the CMake installation cache for the current environment |
| 5 | +PREP_CMAKE: |
| 6 | + COMMAND |
| 7 | + LET scratch=/opt/mongoc-cmake |
| 8 | + # Copy the minimal amount that we need, as to avoid cache invalidation |
| 9 | + COPY tools/use.sh tools/platform.sh tools/paths.sh tools/base.sh tools/download.sh \ |
| 10 | + $scratch/tools/ |
| 11 | + COPY .evergreen/scripts/find-cmake-version.sh \ |
| 12 | + .evergreen/scripts/use-tools.sh \ |
| 13 | + .evergreen/scripts/find-cmake-latest.sh \ |
| 14 | + .evergreen/scripts/cmake.sh \ |
| 15 | + $scratch/.evergreen/scripts/ |
| 16 | + # "Install" a shim that runs our managed CMake executable: |
| 17 | + RUN printf '#!/bin/sh\n /opt/mongoc-cmake/.evergreen/scripts/cmake.sh "$@"\n' \ |
| 18 | + > /usr/local/bin/cmake && \ |
| 19 | + chmod +x /usr/local/bin/cmake |
| 20 | + # Executing any CMake command will warm the cache: |
| 21 | + RUN cmake --version |
| 22 | + |
| 23 | +# version-current creates the VERSION_CURRENT file using Git. This file is exported as an artifact at / |
| 24 | +version-current: |
| 25 | + # Run on Alpine, which does this work the fastest |
| 26 | + FROM alpine:3.18 |
| 27 | + # Install Python and Git, the only things required for this job: |
| 28 | + RUN apk add git python3 |
| 29 | + COPY --dir .git/ build/calc_release_version.py /s/ |
| 30 | + # Calculate it: |
| 31 | + RUN cd /s/ && \ |
| 32 | + python calc_release_version.py > VERSION_CURRENT |
| 33 | + SAVE ARTIFACT /s/VERSION_CURRENT |
| 34 | + |
| 35 | +# BUILD_AND_INSTALL executes the mongo-c-driver build and installs it to a prefix |
| 36 | +BUILD_AND_INSTALL: |
| 37 | + COMMAND |
| 38 | + ARG config=RelWithDebInfo |
| 39 | + ARG install_prefix=/opt/mongo-c-driver |
| 40 | + LET source_dir=/opt/mongoc/source |
| 41 | + LET build_dir=/opt/mongoc/build |
| 42 | + COPY --dir \ |
| 43 | + src/ \ |
| 44 | + build/ \ |
| 45 | + COPYING \ |
| 46 | + CMakeLists.txt \ |
| 47 | + README.rst \ |
| 48 | + THIRD_PARTY_NOTICES \ |
| 49 | + NEWS \ |
| 50 | + "$source_dir" |
| 51 | + COPY +version-current/ $source_dir |
| 52 | + ENV CCACHE_HOME=/root/.cache/ccache |
| 53 | + RUN cmake -S "$source_dir" -B "$build_dir" -G "Ninja Multi-Config" \ |
| 54 | + -D ENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \ |
| 55 | + -D ENABLE_MAINTAINER_FLAGS=ON \ |
| 56 | + -D ENABLE_RDTSCP=ON \ |
| 57 | + -D ENABLE_SHM_COUNTERS=ON \ |
| 58 | + -D ENABLE_EXTRA_ALIGNMENT=OFF \ |
| 59 | + -D ENABLE_SASL=CYRUS \ |
| 60 | + -D ENABLE_SNAPPY=ON \ |
| 61 | + -D ENABLE_SRV=ON \ |
| 62 | + -D ENABLE_ZLIB=BUNDLED \ |
| 63 | + -D ENABLE_SSL=OPENSSL \ |
| 64 | + -D ENABLE_COVERAGE=ON \ |
| 65 | + -D ENABLE_DEBUG_ASSERTIONS=ON \ |
| 66 | + -Werror |
| 67 | + RUN --mount=type=cache,target=$CCACHE_HOME \ |
| 68 | + env CCACHE_BASE="$source_dir" \ |
| 69 | + cmake --build $build_dir --config $config |
| 70 | + RUN cmake --install $build_dir --prefix="$install_prefix" --config $config |
| 71 | + |
| 72 | +alpine-base: |
| 73 | + ARG --required version |
| 74 | + FROM alpine:$version |
| 75 | + RUN apk add cmake ninja-is-really-ninja gcc musl-dev |
| 76 | + |
| 77 | +alpine3.18-build-env: |
| 78 | + FROM +alpine-base --version=3.18 |
| 79 | + RUN apk add openssl-dev cyrus-sasl-dev snappy-dev |
| 80 | + |
| 81 | +alpine3.18-test-env: |
| 82 | + FROM +alpine-base --version=3.18 |
| 83 | + RUN apk add libsasl snappy |
| 84 | + |
| 85 | +archlinux-base: |
| 86 | + FROM archlinux |
| 87 | + RUN pacman --sync --refresh --sysupgrade --noconfirm --quiet ninja gcc snappy |
| 88 | + |
| 89 | +archlinux-build-env: |
| 90 | + FROM +archlinux-base |
| 91 | + DO +PREP_CMAKE |
| 92 | + |
| 93 | +archlinux-test-env: |
| 94 | + FROM +archlinux-base |
| 95 | + DO +PREP_CMAKE |
| 96 | + |
| 97 | +ubuntu-base: |
| 98 | + ARG --required version |
| 99 | + FROM ubuntu:$version |
| 100 | + RUN apt-get update && apt-get -y install curl build-essential |
| 101 | + |
| 102 | +u22-build-env: |
| 103 | + FROM +ubuntu-base --version=22.04 |
| 104 | + # Build dependencies: |
| 105 | + RUN apt-get update && apt-get -y install \ |
| 106 | + ninja-build gcc ccache libssl-dev libsnappy-dev zlib1g-dev \ |
| 107 | + libsasl2-dev |
| 108 | + DO +PREP_CMAKE |
| 109 | + |
| 110 | +u22-test-env: |
| 111 | + FROM +ubuntu-base --version=22.04 |
| 112 | + RUN apt-get update && apt-get -y install libsnappy1v5 libsasl2-2 ninja-build |
| 113 | + DO +PREP_CMAKE |
| 114 | + |
| 115 | +# build will build libmongoc and libbson using the specified environment. |
| 116 | +# |
| 117 | +# The --env argument specifies the build environment, which must be one of: |
| 118 | +# • u22 (Ubuntu 22.04) |
| 119 | +# • archlinux |
| 120 | +# • alpine3.18 |
| 121 | +build: |
| 122 | + # env is an argument |
| 123 | + ARG --required env |
| 124 | + FROM +$env-build-env |
| 125 | + DO +BUILD_AND_INSTALL --config=RelWithDebInfo |
| 126 | + SAVE ARTIFACT /opt/mongoc/build/* /build-tree/ |
| 127 | + SAVE ARTIFACT /opt/mongo-c-driver/* /root/ |
| 128 | + |
| 129 | +# test-example will build one of the libmongoc example projects using the build |
| 130 | +# that comes from the +build target. |
| 131 | +test-example: |
| 132 | + ARG --required env |
| 133 | + FROM +$env-test-env |
| 134 | + # Grab the built |
| 135 | + COPY (+build/root --env=$env) /opt/mongo-c-driver |
| 136 | + COPY --dir \ |
| 137 | + src/libmongoc/examples/cmake \ |
| 138 | + src/libmongoc/examples/cmake-deprecated \ |
| 139 | + src/libmongoc/examples/hello_mongoc.c \ |
| 140 | + /opt/mongoc-test/ |
| 141 | + RUN cmake \ |
| 142 | + -S /opt/mongoc-test/cmake/find_package \ |
| 143 | + -B /bld \ |
| 144 | + -G Ninja \ |
| 145 | + -D CMAKE_PREFIX_PATH=/opt/mongo-c-driver |
| 146 | + RUN cmake --build /bld |
| 147 | + |
| 148 | +# Simultaneously builds and tests multiple different platforms |
| 149 | +multibuild: |
| 150 | + BUILD +test-example --env=u22 --env=archlinux --env=alpine3.18 |
0 commit comments