Skip to content

Commit 54aa89c

Browse files
[CDRIVER-4651] Documentation on vcpkg installation + more (#1424)
* Docs additions and updates: - Enable the documentation index. Begin using index entries. - Add a reference page for Linux, Conand, and vcpkg packages and how they can be found/used. - Add a tutorial section for installing via vcpkg. * Add an in-source example/test that uses vcpkg This is a very minimal example and test case that installs the release (not local!) version of libbson and libmongoc, and then tests that the application builds and runs correctly. There is no CI task for this yet, as it is unstable and does not make use of the local source tree. Future updates may make a more thorough test case that overrides the source for the vcpkg mongo-c-driver port to use the local source tree, thus giving a route for automated testing of changes against the third-party portfile. * Add links to external port+recipes * Tweak inclusion of the genindex page. Including the genindex in a toctree seems to create a conflict with the full_index page which tries to include the root `index.rst` via another toctree? This is odd, but easy enough to work around.
1 parent 4998148 commit 54aa89c

11 files changed

+454
-15
lines changed

Earthfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,45 @@ multibuild:
245245
--sasl=Cyrus --sasl=off \
246246
--tls=LibreSSL
247247

248+
# test-vcpkg-classic :
249+
# Builds src/libmongoc/examples/cmake/vcpkg by using vcpkg to download and
250+
# install a mongo-c-driver build in "classic mode". *Does not* use the local
251+
# mongo-c-driver repository.
252+
test-vcpkg-classic:
253+
FROM +vcpkg-base
254+
RUN vcpkg install mongo-c-driver
255+
RUN rm -rf _build && \
256+
make test-classic
257+
258+
# test-vcpkg-manifest-mode :
259+
# Builds src/libmongoc/examples/cmake/vcpkg by using vcpkg to download and
260+
# install a mongo-c-driver package based on the content of a vcpkg.json manifest
261+
# that is injected into the project.
262+
test-vcpkg-manifest-mode:
263+
FROM +vcpkg-base
264+
RUN apk add jq
265+
RUN jq -n ' { \
266+
name: "test-app", \
267+
version: "1.2.3", \
268+
dependencies: ["mongo-c-driver"], \
269+
}' > vcpkg.json && \
270+
cat vcpkg.json
271+
RUN rm -rf _build && \
272+
make test-manifest-mode
273+
274+
vcpkg-base:
275+
FROM alpine:3.18
276+
RUN apk add cmake curl gcc g++ musl-dev ninja-is-really-ninja zip unzip tar \
277+
build-base git pkgconf perl bash linux-headers
278+
ENV VCPKG_ROOT=/opt/vcpkg-git
279+
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
280+
GIT CLONE --branch=2023.06.20 https://github.com/microsoft/vcpkg $VCPKG_ROOT
281+
RUN sh $VCPKG_ROOT/bootstrap-vcpkg.sh -disableMetrics && \
282+
install -spD -m 755 $VCPKG_ROOT/vcpkg /usr/local/bin/
283+
LET src_dir=/opt/mongoc-vcpkg-example
284+
COPY src/libmongoc/examples/cmake/vcpkg/ $src_dir
285+
WORKDIR $src_dir
286+
248287
# run :
249288
# Run one or more targets simultaneously.
250289
#

src/libmongoc/doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _maybe_update_inventories(app: Sphinx, config: Config):
105105
html_theme = "furo"
106106
html_title = html_shorttitle = "libmongoc %s" % version
107107
# html_favicon = None
108-
html_use_index = False
108+
html_use_index = True
109109

110110
rst_prolog = rf"""
111111
.. |qenc:is-experimental| replace::

src/libmongoc/doc/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ It depends on :doc:`libbson <bson:index>` to generate and parse BSON documents,
2626
guides
2727
api
2828
application-performance-monitoring
29+
30+
31+
* :ref:`genindex`

src/libmongoc/doc/learn/get/from-source.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ with |libmongoc|. Follow the process at :ref:`learn.get.build` and
354354
355355
.. [#vs_env]
356356
357-
If you with to configure and build the project using Microsoft Visual C++,
357+
If you wish to configure and build the project using Microsoft Visual C++,
358358
then the Visual C++ tools and environment variables may need to be set when
359359
running any CMake or build command.
360360

src/libmongoc/doc/learn/get/installing.rst

Lines changed: 133 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ Installing Prebuilt MongoDB C Driver Libraries
1111
.. _Homebrew: https://brew.sh/
1212

1313
The |libmongoc| and |libbson| libraries are often available in the package
14-
management repositories of `common Linux distributions <linux_>`_ and
15-
`macOS via Homebrew <macos_>`_.
14+
management repositories of `common Linux distributions <installing.linux_>`_ and
15+
`macOS via Homebrew <installing.macos_>`_.
1616

1717
.. note::
1818

19-
For Windows, it is recommended to instead
19+
For :index:`Windows`, it is recommended to instead
2020
:doc:`build the libraries from source <from-source>`, for maximum
21-
compatibility with the local toolchain.
21+
compatibility with the local toolchain. Building from source can be automated
22+
by using a from-source library package management tool such as Conan_ or
23+
vcpkg_ (See: :ref:`installing.pkgman`).
2224

2325
.. caution::
2426

@@ -30,8 +32,110 @@ management repositories of `common Linux distributions <linux_>`_ and
3032
For the most up-to-date versions of the C driver libraries, prefer to instead
3133
:doc:`build from source <from-source>`.
3234

35+
.. seealso::
3336

34-
.. _linux:
37+
For a listing and common reference on available packages, refer to
38+
:doc:`/ref/packages`.
39+
40+
41+
.. index::
42+
package managers; Conan
43+
package managers; vcpkg
44+
pair: installation; package managers
45+
:name: installing.pkgman
46+
47+
Cross Platform Installs Using Library Package Managers
48+
******************************************************
49+
50+
Various library package managers offer |libbson| and |libmongoc| as installable
51+
packages, including Conan_ and vcpkg_. This section will detail how to install
52+
using those tools.
53+
54+
.. _conan: https://conan.io/
55+
.. _vcpkg: https://vcpkg.io/
56+
57+
58+
.. index::
59+
! pair: installation; vcpkg
60+
61+
Installing using vcpkg
62+
======================
63+
64+
.. note::
65+
This page will not detail how to get started using vcpkg_. For that, refer to
66+
`Get started with vcpkg`__
67+
68+
__ https://vcpkg.io/en/getting-started
69+
70+
.. tab-set::
71+
72+
.. tab-item:: vcpkg Manifest Mode (Recommended)
73+
74+
In `vcpkg manifest mode`__, add the desired libraries to your project's
75+
``vcpkg.json`` manifest file:
76+
77+
__ https://learn.microsoft.com/en-us/vcpkg/users/manifests
78+
79+
.. code-block:: js
80+
:caption: ``vcpkg.json``
81+
:linenos:
82+
83+
{
84+
// ...
85+
"dependencies": [
86+
// ...
87+
"mongo-c-driver"
88+
]
89+
}
90+
91+
When you build a CMake project with vcpkg integration and have a
92+
``vcpkg.json`` manifest file, vcpkg will automatically install the project's
93+
dependencies before proceeding with the configuration phase, so no
94+
additional manual work is required.
95+
96+
97+
.. tab-item:: vcpkg Classic Mode
98+
99+
In `vcpkg classic mode`__, |libbson| and |libmongoc| can be installed through the
100+
names ``libbson`` and ``mongo-c-driver``, respectively::
101+
102+
$ vcpkg install mongo-c-driver
103+
104+
__ https://learn.microsoft.com/en-us/vcpkg/users/classic-mode
105+
106+
(Installing ``mongo-c-driver`` will transitively install |libbson| as well.)
107+
108+
When the |libmongoc| and |libbson| packages are installed and vcpkg has been
109+
properly integrated into your build system, the desired libraries will be
110+
available for import.
111+
112+
With CMake, the standard config-file package will be available, as well as the
113+
generated ``IMPORTED`` targets:
114+
115+
.. code-block:: cmake
116+
:caption: ``CMakeLists.txt``
117+
118+
find_package(mongoc-1.0 CONFIG REQUIRED)
119+
target_link_libraries(my-application
120+
PRIVATE $<IF:$<TARGET_EXISTS:mongo::mongoc_shared>,mongo::mongoc_shared,mongo::mongoc_static>)
121+
122+
.. note::
123+
124+
The large ``$<IF:$<TARGET_EXISTS...>:...>`` generator expression
125+
(:external:doc:`manual/cmake-generator-expressions.7`) can be used to switch
126+
the link type of |libmongoc| based on whichever form is available from the
127+
``find_package()`` command. |libmongoc| supports building with both *dynamic*
128+
and *static* library types, but vcpkg will only install one of the two library
129+
types at a time.
130+
131+
Configuring a CMake project with vcpkg integration is a matter of setting the
132+
CMake toolchain file at the initial configure command::
133+
134+
$ cmake -S . -B _build -D CMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
135+
136+
.. index::
137+
! pair: Linux; installation
138+
:name: installing.linux
35139

36140
Installing in Linux
37141
*******************
@@ -48,7 +152,20 @@ The following Linux distributions provide |libbson| and |libmongoc| packages:
48152
- `Debian <debian_>`_ and Debian-based distributions, including
49153
`Ubuntu <debian_>`_ and Ubuntu derivatives, via APT.
50154

155+
.. seealso::
156+
157+
For a list of available packages and package options, see:
158+
:doc:`/ref/packages`.
51159

160+
161+
.. index::
162+
!pair: installation; RHEL
163+
!pair: installation; Fedora
164+
!pair: installation; CentOS
165+
!pair: installation; Rocky Linux
166+
!pair: installation; AlmaLinux
167+
!pair: installation; Yum
168+
!pair: installation; DNF
52169
.. _redhat:
53170

54171
RedHat-based Systems
@@ -91,6 +208,10 @@ To install the full C database driver (|libmongoc|), install
91208
# yum install mongo-c-driver-devel
92209

93210

211+
.. index::
212+
!pair: installation; Debian
213+
!pair: installation; Ubuntu
214+
!pair: installation; APT
94215
.. _debian:
95216

96217
Debian-based Systems
@@ -112,26 +233,25 @@ To install |libmongoc| (which will also install |libbson|)::
112233
# apt install libmongoc-dev
113234

114235

115-
.. _macos:
236+
.. index::
237+
!pair: installation; macOS
238+
!pair: installation; Homebrew
239+
package managers; Homebrew
240+
.. _installing.macos:
116241

117242
Installing on macOS with Homebrew
118243
*********************************
119244

120245
If you are using a macOS system, the C driver libraries (including both
121-
|libmongoc| and |libbson|) may be installed using the Homebrew_ package manager [#macos_brew]_
122-
with the following command::
246+
|libmongoc| and |libbson|) may be installed using the Homebrew_ package manager
247+
[#macos_brew]_ with the following command::
123248

124249
$ brew install mongo-c-driver
125250

126251
.. note::
127252

128253
Homebrew does not provide separate packages for |libbson| and |libmongoc|.
129254

130-
131-
.. todo
132-
Packages for Windows, via Conan, and via vcpkg
133-
134-
135255
.. [#macos_brew]
136256
137257
The Homebrew_ package manager is not installed by default on macOS. For

src/libmongoc/doc/mongoc_client_encryption_opts_set_kms_credential_provider_callback.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ Parameters
3434
.. rubric:: Related:
3535

3636
.. c:type:: mongoc_kms_credentials_provider_callback_fn
37+
:noindexentry:
38+
39+
.. -
40+
The :noindexentry: prevents a one-off index entry for this item.
41+
Most entities are not documented as Sphinx objects, and thus do not generate
42+
index entries. Future changes may flip the script.
3743
3844
.. code-block:: c
3945

0 commit comments

Comments
 (0)