@@ -122,3 +122,73 @@ for a number of reasons:
122122
123123Since downstreams frequently also run tests and build documentation, the above
124124should ideally extend to these processes as well.
125+
126+
127+ .. _Support building against system dependencies :
128+
129+ Support building against system dependencies
130+ --------------------------------------------
131+ Some Python projects have non-Python dependencies, such as libraries written
132+ in C or C++. Trying to use the system versions of these dependencies
133+ in upstream packaging may cause a number of problems for end users:
134+
135+ - The published wheels require a binary-compatible version of the used library
136+ to be present on the user's system. If the library is missing or installed
137+ in incompatible version, the Python package may fail with errors that
138+ are not clear to inexperienced users, or even misbehave at runtime.
139+
140+ - Building from source distribution requires a source-compatible version
141+ of the dependency to be present, along with its development headers and other
142+ auxiliary files that some systems package separately from the library itself.
143+
144+ - Even for an experienced user, installing a compatible dependency version
145+ may be very hard. For example, the used Linux distribution may not provide
146+ the required version, or some other package may require an incompatible
147+ version.
148+
149+ - The linkage between the Python package and its system dependency is not
150+ recorded by the packaging system. The next system update may upgrade
151+ the library to a newer version that breaks binary compatibility with
152+ the Python package, and requires user intervention to fix.
153+
154+ For these reasons, you may reasonable to decide to either link statically
155+ to your dependencies, or to provide a local copies in the installed package.
156+ You may also vendor the dependency in your source distribution. Sometimes
157+ these dependencies are also repackaged on PyPI, and can be installed
158+ like a regular Python packages.
159+
160+ However, none of these issues apply to downstream packaging, and downstreams
161+ have good reasons to prefer dynamically linking to system dependencies.
162+ In particular:
163+
164+ - Static linking and vendoring obscures the use of external dependencies,
165+ making source auditing harder.
166+
167+ - Dynamic linking makes it possible to easily and quickly replace the used
168+ libraries, which can be particularly important when they turn out to
169+ be vulnerable or buggy.
170+
171+ - Using system dependencies makes the package benefit from downstream
172+ customization that can improve the user experience on a particular platform,
173+ without the downstream maintainers having to consistently patch
174+ the dependencies vendored in different packages. This can include
175+ compatibility improvements and security hardening.
176+
177+ - Static linking and vendoring could result in multiple different versions
178+ of the same library being loaded in the same process (e.g. when you use two
179+ Python packages that link to different versions of the same library).
180+ This can cause no problems, but it could also lead to anything from subtle
181+ bugs to catastrophic failures.
182+
183+ - Last but not least, static linking and vendoring results in duplication,
184+ and may increase the use of both the disk space and memory.
185+
186+ A good compromise between the needs of both parties is to provide a switch
187+ between using vendored and system dependencies. Ideally, if the package has
188+ multiple vendored dependencies, it should provide both individual switches
189+ for each dependency, and a general switch, for example using
190+ a ``USE_SYSTEM_DEPS `` environment variable to control the default. If switched
191+ on, and a particular dependency is either missing or incompatible, the build
192+ should fail with an explanatory message, giving the packager an explicit
193+ indication of the problem and a chance to consciously decide on the preferred
194+ course of action.
0 commit comments