diff --git a/.github/actions/linux/build-libmongoc/action.yml b/.github/actions/linux/build-libmongoc/action.yml new file mode 100644 index 000000000..6a804078a --- /dev/null +++ b/.github/actions/linux/build-libmongoc/action.yml @@ -0,0 +1,55 @@ +name: "Build libmongoc" +description: "Builds and install libmongoc" +inputs: + prefix: + description: "Prefix to install libmongoc to" + default: "/usr/local" + version: + description: "Libmongoc version to build" + required: true +runs: + using: composite + + steps: + - name: Download libmongoc + shell: bash + working-directory: /tmp + run: wget "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/${LIBMONGOC_VERSION}.tar.gz" --output-document="mongo-c-driver.tar.gz" + env: + LIBMONGOC_VERSION: ${{ inputs.version }} + + - name: Extract libmongoc + shell: bash + working-directory: /tmp + run: tar xf "mongo-c-driver.tar.gz" + + - name: Configure cmake + shell: bash + working-directory: /tmp + run: | + cmake \ + -S "mongo-c-driver-${LIBMONGOC_VERSION}" \ + -B _build \ + -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D BUILD_VERSION="${LIBMONGOC_VERSION}" \ + -D ENABLE_MONGOC=ON \ + -D ENABLE_TRACING=ON \ + -D ENABLE_CLIENT_SIDE_ENCRYPTION=ON + env: + LIBMONGOC_VERSION: ${{ inputs.version }} + + - name: Build libmongoc + shell: bash + working-directory: /tmp + run: cmake --build _build --config RelWithDebInfo --parallel + + - name: Install libmongoc + shell: bash + working-directory: /tmp + run: sudo cmake --install _build --prefix "${PREFIX}" --config RelWithDebInfo + env: + PREFIX: ${{ inputs.prefix }} + + - name: Check pkg-config availability + shell: bash + run: pkg-config --modversion mongoc2 diff --git a/.github/actions/linux/build-libmongocrypt/action.yml b/.github/actions/linux/build-libmongocrypt/action.yml new file mode 100644 index 000000000..04c12509e --- /dev/null +++ b/.github/actions/linux/build-libmongocrypt/action.yml @@ -0,0 +1,29 @@ +name: "Build libmongocrypt" +description: "Installs libmongocrypt" +inputs: + version: + description: "Libmongocrypt version to install (major.minor)" + required: true +runs: + using: composite + + steps: + - name: Add repository key + shell: bash + run: sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg' + + - name: Add repository + shell: bash + working-directory: /tmp + # Note: no packages for Ubuntu 24.04 noble exist, so we use those for 22.04 + run: echo "deb https://libmongocrypt.s3.amazonaws.com/apt/ubuntu jammy/libmongocrypt/${LIBMONGOCRYPT_VERSION} universe" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list + env: + LIBMONGOCRYPT_VERSION: ${{ inputs.version }} + + - name: Update apt sources + shell: bash + run: sudo apt-get update + + - name: Install libmongocrypt + shell: bash + run: sudo apt-get install -y libmongocrypt-dev diff --git a/.github/actions/linux/build/action.yml b/.github/actions/linux/build/action.yml index a66462268..20378e2a7 100644 --- a/.github/actions/linux/build/action.yml +++ b/.github/actions/linux/build/action.yml @@ -4,6 +4,10 @@ inputs: version: description: "PHP version to build for" required: true + configureOpts: + description: "Extra options to use for the call to ./configure" + default: "" + runs: using: composite steps: @@ -17,6 +21,8 @@ runs: - name: "Configure driver" run: .github/workflows/configure.sh shell: bash + env: + CONFIGURE_OPTS: ${{ inputs.configureOpts }} - name: "Build driver" run: "make all" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ac706fa3e..29c74c922 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -128,3 +128,54 @@ jobs: php: [ "8.1", "8.2", "8.3", "8.4" ] arch: [ x64, x86 ] ts: [ ts, nts ] + + test-system-libs: + name: "System Library Tests" + runs-on: "ubuntu-latest" + env: + PHP_VERSION: "8.3" + LIBMONGOCRYPT_VERSION: "1.14" + LIBMONGOC_VERSION: "2.0.1" + SERVER_VERSION: "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + with: + submodules: true + + - name: "Install libmongocrypt" + uses: ./.github/actions/linux/build-libmongocrypt + with: + version: ${{ env.LIBMONGOCRYPT_VERSION }} + + - name: "Build libmongoc" + uses: ./.github/actions/linux/build-libmongoc + with: + version: ${{ env.LIBMONGOC_VERSION }} + + - name: "Build Driver" + uses: ./.github/actions/linux/build + with: + version: ${{ env.PHP_VERSION }} + configureOpts: "--with-mongodb-system-libs=yes" + + - name: "Check driver version" + shell: bash + run: make show-config + + - uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Setup MongoDB + id: setup-mongodb + uses: ./tests/drivers-evergreen-tools + with: + version: ${{ ENV.SERVER_VERSION }} + topology: "server" + + - name: "Run Tests" + run: TEST_PHP_ARGS="-q -x --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP" make test + env: + MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }} diff --git a/Makefile.frag b/Makefile.frag index c1f83b808..46eb786af 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -1,4 +1,4 @@ -.PHONY: mv-coverage lcov-coveralls lcov-local coverage coveralls format format-changed format-check test-clean package package.xml libmongocrypt-version-current generate-function-map +.PHONY: mv-coverage lcov-coveralls lcov-local coverage coveralls format format-changed format-check test-clean package package.xml libmongocrypt-version-current generate-function-map show-config ifneq (,$(realpath $(EXTENSION_DIR)/json.so)) PHP_TEST_SHARED_EXTENSIONS := "-d" "extension=$(EXTENSION_DIR)/json.so" $(PHP_TEST_SHARED_EXTENSIONS) @@ -88,6 +88,28 @@ generate-function-map: all echo "ERROR: Cannot generate function maps without CLI sapi."; \ fi +show-config: all + @if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \ + INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \ + if test "$$INI_FILE"; then \ + $(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \ + else \ + echo > $(top_builddir)/tmp-php.ini; \ + fi; \ + INI_SCANNED_PATH=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/null`; \ + if test "$$INI_SCANNED_PATH"; then \ + INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \ + $(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \ + fi; \ + CC="$(CC)" \ + $(PHP_EXECUTABLE) -n -c $(top_builddir)/tmp-php.ini -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS) --ri mongodb; \ + RESULT_EXIT_CODE=$$?; \ + rm $(top_builddir)/tmp-php.ini; \ + exit $$RESULT_EXIT_CODE; \ + else \ + echo "ERROR: Cannot show config without CLI sapi."; \ + fi + test-no-build: @if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \ INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \