Skip to content

PHPC-2435: Support libmongoc 2.0 #1829

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 6 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .evergreen/compile-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ if [ -n "$LIBMONGOC_VERSION" ]; then
echo "Finding Python3 binary... done."

php scripts/update-submodule-sources.php

# We invoke python manually as it may not be in the path
pushd src/libmongoc/
$PYTHON build/calc_release_version.py > ../LIBMONGOC_VERSION_CURRENT
popd
fi

phpize
Expand Down
1 change: 0 additions & 1 deletion .evergreen/config/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ functions:
echo "Checking out libmongoc version: ${LIBMONGOC_VERSION}"
git fetch
git checkout ${LIBMONGOC_VERSION}
# Note: compile-unix.sh will run `make libmongoc-version-current`
fi
- command: subprocess.exec
type: test
Expand Down
4 changes: 1 addition & 3 deletions .evergreen/config/generate-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
'4.2',
];

// TODO: Change when PHP 8.4 is stable
// $latestPhpVersion = max($phpVersions);
$latestPhpVersion = '8.3';
$latestPhpVersion = max($phpVersions);

// Only test the latest PHP version for libmongoc
$libmongocBuildPhpVersions = [ $latestPhpVersion ];
Expand Down
22 changes: 11 additions & 11 deletions .evergreen/config/generated/build/build-libmongoc.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions .evergreen/config/generated/test-variant/libmongoc.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .evergreen/config/templates/build/build-libmongoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- func: "compile driver"
vars:
PHP_VERSION: "%phpVersion%"
LIBMONGOC_VERSION: "1.30.1"
LIBMONGOC_VERSION: "2.0.1"
- func: "upload build"

- name: "build-php-%phpVersion%-libmongoc-next-stable"
Expand All @@ -19,7 +19,7 @@
- func: "compile driver"
vars:
PHP_VERSION: "%phpVersion%"
LIBMONGOC_VERSION: "r1.30"
LIBMONGOC_VERSION: "r2.0"
- func: "upload build"

- name: "build-php-%phpVersion%-libmongoc-latest"
Expand Down
55 changes: 55 additions & 0 deletions .github/actions/linux/build-libmongoc/action.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/actions/linux/build-libmongocrypt/action.yml
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

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

Suggested change
# Note: no packages for Ubuntu 24.04 noble exist, so we use those for 22.04
# Note: no packages for Ubuntu 24.04 noble exist, so we use those for 22.04. Update after MONGOCRYPT-813 is released.

Aside: MONGOCRYPT-813 is planned for the next 1.14.1 patch release.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I'll update this alongside 1.14.1 then :)

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
6 changes: 6 additions & 0 deletions .github/actions/linux/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
29 changes: 11 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ always refer to libmongoc.
```shell
cd src/libmongoc
git fetch
git checkout 1.20.0
git checkout 2.1.0
```

During development, it may be necessary to temporarily point the submodule to a
Expand All @@ -218,24 +218,16 @@ git submodules set-url src/libmongoc https://github.com/<owner>/<repo>.git
git submodules set-branch -b <branch> src/libmongoc
```

#### Ensure version information is correct
#### Ensure version information is correct (libmongocrypt only)

Various build processes and tools rely on the version files to infer version
information. This file can be regenerated using Makefile targets:
For libmongocrypt, version information needs to be updated after updating to
a newer submodule version. This can be done by running the corresponding make
target:

```shell
make libmongoc-version-current
make libmongocrypt-version-current
```

Alternatively, the `build/calc_release_version.py` script in the submodule can
be executed directly.

Note: If the submodule points to a non-release, non-master branch, the script
may fail to correctly detect the version. This issue is being tracked in
[CDRIVER-3315](https://jira.mongodb.org/browse/CDRIVER-3315) and can be safely ignored since this should only happen
during development (any PHP driver release should point to a tagged submodule
version).

#### Update sources in build configurations

The Autotools and Windows build configurations (`config.m4` and `config.w32`,
Expand All @@ -261,11 +253,11 @@ libmongoc and libbson.
For example, the following lines might be updated for libmongoc:

```
if $PKG_CONFIG libmongoc-1.0 --atleast-version 1.20.0; then
if $PKG_CONFIG mongoc2 --atleast-version 2.1.0; then

...

AC_MSG_ERROR(system libmongoc must be upgraded to version >= 1.20.0)
AC_MSG_ERROR(system libmongoc must be upgraded to version >= 2.1.0)
```

#### Update tested versions in Evergreen configuration (libmongoc only)
Expand All @@ -277,7 +269,7 @@ information about the build tasks and where they are used. In general, we test
against two additional versions of libmongoc:

- The upcoming patch release of the current libmongoc minor version (e.g. the
`r1.x` branch)
`r2.x` branch)
- The upcoming minor release of libmongoc (e.g. the `master` branch)

#### Update sources in PECL package generation script
Expand Down Expand Up @@ -307,5 +299,6 @@ test suite passes. Once done, commit the changes to all of the above
files/paths. For example:

```shell
git commit -m "Bump libmongoc to 1.20.0" config.m4 config.w32 src/libmongoc src/LIBMONGOC_VERSION_CURRENT sbom.json
git commit -m "Bump libmongoc to 2.1.0" config.m4 config.w32 src/libmongoc sbom.
json
```
Loading