]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/docs/maintainers/maintainer-guide.md
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / tools / vcpkg / docs / maintainers / maintainer-guide.md
CommitLineData
1e59de90
TL
1# Maintainer Guidelines and Policies\r
2\r
3This document lists a set of policies that you should apply when adding or updating a port recipe.\r
4It is intended to serve the role of\r
5[Debian's Policy Manual](https://www.debian.org/doc/debian-policy/),\r
6[Homebrew's Maintainer Guidelines](https://docs.brew.sh/Maintainer-Guidelines), and\r
7[Homebrew's Formula Cookbook](https://docs.brew.sh/Formula-Cookbook).\r
8\r
9## PR Structure\r
10\r
11### Make separate Pull Requests per port\r
12\r
13Whenever possible, separate changes into multiple PRs.\r
14This makes them significantly easier to review and prevents issues with one set of changes from holding up every other change.\r
15\r
16### Avoid trivial changes in untouched files\r
17\r
18For example, avoid reformatting or renaming variables in portfiles that otherwise have no reason to be modified for the issue at hand.\r
19However, if you need to modify the file for the primary purpose of the PR (updating the library),\r
20then obviously beneficial changes like fixing typos are appreciated!\r
21\r
22### Check names against other repositories\r
23\r
24A good service to check many at once is [Repology](https://repology.org/).\r
25If the library you are adding could be confused with another one,\r
26consider renaming to make it clear.\r
27\r
28### Use GitHub Draft PRs\r
29\r
30GitHub Draft PRs are a great way to get CI or human feedback on work that isn't yet ready to merge.\r
31Most new PRs should be opened as drafts and converted to normal PRs once the CI passes.\r
32\r
33More information about GitHub Draft PRs:\r
34https://github.blog/2019-02-14-introducing-draft-pull-requests/\r
35\r
36## Portfiles\r
37\r
38### Avoid deprecated helper functions\r
39\r
40At this time, the following helpers are deprecated:\r
41\r
421. `vcpkg_extract_source_archive()` should be replaced by [`vcpkg_extract_source_archive_ex()`](vcpkg_extract_source_archive_ex.md)\r
432. `vcpkg_apply_patches()` should be replaced by the `PATCHES` arguments to the "extract" helpers (e.g. [`vcpkg_from_github()`](vcpkg_from_github.md))\r
443. `vcpkg_build_msbuild()` should be replaced by [`vcpkg_install_msbuild()`](vcpkg_install_msbuild.md)\r
454. `vcpkg_copy_tool_dependencies()` should be replaced by [`vcpkg_copy_tools()`](vcpkg_copy_tools.md)\r
46\r
47### Avoid excessive comments in portfiles\r
48\r
49Ideally, portfiles should be short, simple, and as declarative as possible.\r
50Remove any boiler plate comments introduced by the `create` command before submitting a PR.\r
51\r
52## Features\r
53\r
54### Do not use features to implement alternatives\r
55\r
56Features must be treated as additive functionality. If port[featureA] installs and port[featureB] installs, then port[featureA,featureB] must install. Moreover, if a second port depends on [featureA] and a third port depends on [featureB], installing both the second and third ports should have their dependencies satisfied.\r
57\r
58Libraries in this situation must choose one of the available options as expressed in vcpkg, and users who want a different setting must use overlay ports at this time.\r
59\r
60Existing examples we would not accept today retained for backwards compatibility:\r
61 * `libgit2`, `libzip`, `open62541` all have features for selecting a TLS or crypto backend. Note that `curl` has different crypto backend options but allows selecting between them at runtime, meaning the above tenet is maintained.\r
62 * `darknet` has `opencv2`, `opencv3`, features to control which version of opencv to use for its dependencies.\r
63\r
64### A feature may engage preview or beta functionality\r
65\r
66Notwithstanding the above, if there is a preview branch or similar where the preview functionality has a high probability of not disrupting the non-preview functionality (for example, no API removals), a feature is acceptable to model this setting.\r
67\r
68Examples:\r
69 * The Azure SDKs (of the form `azure-Xxx`) have a `public-preview` feature.\r
70 * `imgui` has an `experimental-docking` feature which engages their preview docking branch which uses a merge commit attached to each of their public numbered releases.\r
71\r
72### Default features should enable behaviors, not APIs\r
73\r
74If a consumer is depending directly upon a library, they can list out any desired features easily (`library[feature1,feature2]`). However, if a consumer _does not know_ they are using a library, they cannot list out those features. If that hidden library is like `libarchive` where features are adding additional compression algorithms (and thus behaviors) to an existing generic interface, default features offer a way to ensure a reasonably functional transitive library is built even if the final consumer doesn't name it directly.\r
75\r
76If the feature adds additional APIs (or executables, or library binaries) and doesn't modify the behavior of existing APIs, it should be left off by default. This is because any consumer which might want to use those APIs can easily require it via their direct reference.\r
77\r
78If in doubt, do not mark a feature as default.\r
79\r
80### Do not use features to control alternatives in published interfaces\r
81\r
82If a consumer of a port depends on only the core functionality of that port, with high probability they must not be broken by turning on the feature. This is even more important when the alternative is not directly controlled by the consumer, but by compiler settings like `/std:c++17` / `-std=c++17`.\r
83\r
84Existing examples we would not accept today retained for backwards compatibility:\r
85 * `redis-plus-plus[cxx17]` controls a polyfill but does not bake the setting into the installed tree.\r
86 * `ace[wchar]` changes all APIs to accept `const wchar_t*` rather than `const char*`.\r
87\r
88### A feature may replace polyfills with aliases provided that replacement is baked into the installed tree\r
89\r
90Notwithstanding the above, ports may remove polyfills with a feature, as long as:\r
91 1. Turning on the feature changes the polyfills to aliases of the polyfilled entity\r
92 2. The state of the polyfill is baked into the installed headers, such that ABI mismatch "impossible" runtime errors are unlikely\r
93 3. It is possible for a consumer of the port to write code which works in both modes, for example by using a typedef which is either polyfilled or not\r
94\r
95Example:\r
96 * `abseil[cxx17]` changes `absl::string_view` to a replacement or `std::string_view`; the patch\r
97https://github.com/microsoft/vcpkg/blob/981e65ce0ac1f6c86e5a5ded7824db8780173c76/ports/abseil/fix-cxx-standard.patch implements the baking requirement\r
98\r
99### Recommended solutions\r
100\r
101If it's critical to expose the underlying alternatives, we recommend providing messages at build time to instruct the user on how to copy the port into a private overlay:\r
102```cmake\r
103set(USING_DOG 0)\r
104message(STATUS "This version of LibContosoFrobnicate uses the Kittens backend. To use the Dog backend instead, create an overlay port of this with USING_DOG set to 1 and the `kittens` dependency replaced with `dog`.")\r
105message(STATUS "This recipe is at ${CMAKE_CURRENT_LIST_DIR}")\r
106message(STATUS "See the overlay ports documentation at https://github.com/microsoft/vcpkg/blob/master/docs/specifications/ports-overlay.md")\r
107```\r
108\r
109## Build Techniques\r
110\r
111### Do not use vendored dependencies\r
112\r
113Do not use embedded copies of libraries.\r
114All dependencies should be split out and packaged separately so they can be updated and maintained.\r
115\r
116### Prefer using CMake\r
117\r
118When multiple buildsystems are available, prefer using CMake.\r
119Additionally, when appropriate, it can be easier and more maintainable to rewrite alternative buildsystems into CMake using `file(GLOB)` directives.\r
120\r
121Examples: [abseil](../../ports/abseil/portfile.cmake)\r
122\r
123### Choose either static or shared binaries\r
124\r
125By default, `vcpkg_configure_cmake()` will pass in the appropriate setting for `BUILD_SHARED_LIBS`,\r
126however for libraries that don't respect that variable, you can switch on `VCPKG_LIBRARY_LINKAGE`:\r
127\r
128```cmake\r
129string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" KEYSTONE_BUILD_STATIC)\r
130string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" KEYSTONE_BUILD_SHARED)\r
131\r
132vcpkg_configure_cmake(\r
133 SOURCE_PATH ${SOURCE_PATH}\r
134 PREFER_NINJA\r
135 OPTIONS\r
136 -DKEYSTONE_BUILD_STATIC=${KEYSTONE_BUILD_STATIC}\r
137 -DKEYSTONE_BUILD_SHARED=${KEYSTONE_BUILD_SHARED}\r
138)\r
139```\r
140\r
141### When defining features, explicitly control dependencies\r
142\r
143When defining a feature that captures an optional dependency,\r
144ensure that the dependency will not be used accidentally when the feature is not explicitly enabled.\r
145\r
146```cmake\r
147if ("zlib" IN_LIST FEATURES)\r
148 set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB OFF)\r
149else()\r
150 set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB ON)\r
151endif()\r
152\r
153vcpkg_configure_cmake(\r
154 SOURCE_PATH ${SOURCE_PATH}\r
155 PREFER_NINJA\r
156 OPTIONS\r
157 -CMAKE_DISABLE_FIND_PACKAGE_ZLIB=${CMAKE_DISABLE_FIND_PACKAGE_ZLIB}\r
158)\r
159```\r
160\r
161The snippet below using `vcpkg_check_features()` is equivalent, [see the documentation](vcpkg_check_features.md).\r
162\r
163```cmake\r
164vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS\r
165 INVERTED_FEATURES\r
166 "zlib" CMAKE_DISABLE_FIND_PACKAGE_ZLIB\r
167)\r
168\r
169vcpkg_configure_cmake(\r
170 SOURCE_PATH ${SOURCE_PATH}\r
171 PREFER_NINJA\r
172 OPTIONS\r
173 ${FEATURE_OPTIONS}\r
174)\r
175```\r
176\r
177Note that `ZLIB` in the above is case-sensitive. See the [cmake documentation](https://cmake.org/cmake/help/v3.15/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.html) for more details.\r
178\r
179### Place conflicting libs in a `manual-link` directory\r
180\r
181A lib is considered conflicting if it does any of the following:\r
182+ Define `main`\r
183+ Define malloc\r
184+ Define symbols that are also declared in other libraries\r
185\r
186Conflicting libs are typically by design and not considered a defect. Because some build systems link against everything in the lib directory, these should be moved into a subdirectory named `manual-link`.\r
187\r
188## Manifests and CONTROL files\r
189\r
190When adding a new port, use the new manifest syntax for defining a port;\r
191you may also change over to manifests when modifying an existing port.\r
192You may do so easily by running the `vcpkg format-manifest` command, which will convert existing CONTROL\r
193files into manifest files. Do not convert CONTROL files that have not been modified.\r
194\r
195## Versioning\r
196\r
197### Follow common conventions for the `"version"` field\r
198\r
199See our [versioning documentation](../users/versioning.md#version-schemes) for a full explanation of our conventions.\r
200\r
201### Update the `"port-version"` field in the manifest file of any modified ports\r
202\r
203Vcpkg uses this field to determine whether a given port is out-of-date and should be changed whenever the port's behavior changes.\r
204\r
205Our convention is to use the `"port-version"` field for changes to the port that don't change the upstream version, and to reset the `"port-version"` back to zero when an update to the upstream version is made.\r
206\r
207For Example:\r
208\r
209- Zlib's package version is currently `1.2.1`, with no explicit `"port-version"` (equivalent to a `"port-version"` of `0`).\r
210- You've discovered that the wrong copyright file has been deployed, and fixed that in the portfile.\r
211- You should update the `"port-version"` field in the manifest file to `1`.\r
212\r
213See our [manifest files document](manifest-files.md#port-version) for a full explanation of our conventions.\r
214\r
215### Update the version files in `versions/` of any modified ports\r
216\r
217Vcpkg uses a set of metadata files to power its versioning feature.\r
218These files are located in the following locations:\r
219* `${VCPKG_ROOT}/versions/baseline.json`, (this file is common to all ports) and\r
220* `${VCPKG_ROOT}/versions/${first-letter-of-portname}-/${portname}.json` (one per port).\r
221\r
222For example, for `zlib` the relevant files are:\r
223* `${VCPKG_ROOT}/versions/baseline.json`\r
224* `${VCPKG_ROOT}/versions/z-/zlib.json`\r
225\r
226We expect that each time you update a port, you also update its version files.\r
227\r
228**The recommended method to update these files is to run the `x-add-version` command, e.g.:**\r
229\r
230```\r
231vcpkg x-add-version zlib\r
232```\r
233\r
234If you're updating multiple ports at the same time, instead you can run:\r
235\r
236```\r
237vcpkg x-add-version --all\r
238```\r
239\r
240To update the files for all modified ports at once.\r
241\r
242_NOTE: These commands require you to have committed your changes to the ports before running them. The reason is that the Git SHA of the port directory is required in these version files. But don't worry, the `x-add-version` command will warn you if you have local changes that haven't been committed._\r
243\r
244See our [versioning specification](../specifications/versioning.md) and [registries specification](../specifications/registries-2.md) to learn how vcpkg interacts with these files.\r
245\r
246## Patching\r
247\r
248### Prefer options over patching\r
249\r
250It is preferable to set options in a call to `vcpkg_configure_xyz()` over patching the settings directly.\r
251\r
252Common options that allow avoiding patching:\r
2531. [MSBUILD] `<PropertyGroup>` settings inside the project file can be overridden via `/p:` parameters\r
2542. [CMAKE] Calls to `find_package(XYz)` in CMake scripts can be disabled via [`-DCMAKE_DISABLE_FIND_PACKAGE_XYz=ON`](https://cmake.org/cmake/help/v3.15/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.html)\r
2553. [CMAKE] Cache variables (declared as `set(VAR "value" CACHE STRING "Documentation")` or `option(VAR "Documentation" "Default Value")`) can be overridden by just passing them in on the command line as `-DVAR:STRING=Foo`. One notable exception is if the `FORCE` parameter is passed to `set()`. See also the [CMake `set` documentation](https://cmake.org/cmake/help/v3.15/command/set.html)\r
256\r
257### Prefer patching over overriding `VCPKG_<VARIABLE>` values\r
258\r
259Some variables prefixed with `VCPKG_<VARIABLE>` have an equivalent `CMAKE_<VARIABLE>`.\r
260However, not all of them are passed to the internal package build [(see implementation: Windows toolchain)](../../scripts/toolchains/windows.cmake).\r
261\r
262Consider the following example:\r
263\r
264```cmake\r
265set(VCPKG_C_FLAGS "-O2 ${VCPKG_C_FLAGS}")\r
266set(VCPKG_CXX_FLAGS "-O2 ${VCPKG_CXX_FLAGS}")\r
267```\r
268\r
269Using `vcpkg`'s built-in toolchains this works, because the value of `VCPKG_<LANG>_FLAGS` is forwarded to the appropriate `CMAKE_LANG_FLAGS` variable. But, a custom toolchain that is not aware of `vcpkg`'s variables will not forward them.\r
270\r
271Because of this, it is preferable to patch the buildsystem directly when setting `CMAKE_<LANG>_FLAGS`.\r
272\r
273### Minimize patches\r
274\r
275When making changes to a library, strive to minimize the final diff. This means you should _not_ reformat the upstream source code when making changes that affect a region. Also, when disabling a conditional, it is better to add a `AND FALSE` or `&& 0` to the condition than to delete every line of the conditional.\r
276\r
277This helps to keep the size of the vcpkg repository down as well as improves the likelihood that the patch will apply to future code versions.\r
278\r
279### Do not implement features in patches\r
280\r
281The purpose of patching in vcpkg is to enable compatibility with compilers, libraries, and platforms. It is not to implement new features in lieu of following proper Open Source procedure (submitting an Issue/PR/etc).\r
282\r
283## Do not build tests/docs/examples by default\r
284\r
285When submitting a new port, check for any options like `BUILD_TESTS` or `WITH_TESTS` or `POCO_ENABLE_SAMPLES` and ensure the additional binaries are disabled. This minimizes build times and dependencies for the average user.\r
286\r
287Optionally, you can add a `test` feature which enables building the tests, however this should not be in the `Default-Features` list.\r
288\r
289## Enable existing users of the library to switch to vcpkg\r
290\r
291### Do not add `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS`\r
292\r
293Unless the author of the library is already using it, we should not use this CMake functionality because it interacts poorly with C++ templates and breaks certain compiler features. Libraries that don't provide a .def file and do not use __declspec() declarations simply do not support shared builds for Windows and should be marked as such with `vcpkg_check_linkage(ONLY_STATIC_LIBRARY)`.\r
294\r
295### Do not rename binaries outside the names given by upstream\r
296\r
297This means that if the upstream library has different names in release and debug (libx versus libxd), then the debug library should not be renamed to `libx`. Vice versa, if the upstream library has the same name in release and debug, we should not introduce a new name.\r
298\r
299Important caveat:\r
300- Static and shared variants often should be renamed to a common scheme. This enables consumers to use a common name and be ignorant of the downstream linkage. This is safe because we only make one at a time available.\r
301\r
302Note that if a library generates CMake integration files (`foo-config.cmake`), renaming must be done through patching the CMake build itself instead of simply calling `file(RENAME)` on the output archives/LIBs.\r
303\r
304Finally, DLL files on Windows should never be renamed post-build because it breaks the generated LIBs.\r
305\r
306## Code format\r
307\r
308### Vcpkg internal code\r
309\r
310We require the C++ code inside vcpkg to follow the clang-format, if you change them. Please perform the following steps after modification:\r
311\r
312- Use Visual Studio:\r
3131. Configure your [clang-format tools](https://devblogs.microsoft.com/cppblog/clangformat-support-in-visual-studio-2017-15-7-preview-1/).\r
3142. Open the modified file.\r
3153. Use shortcut keys Ctrl+K, Ctrl+D to format the current file.\r
316\r
317- Use tools:\r
3181. Install [llvm clang-format](https://releases.llvm.org/download.html#10.0.0)\r
3192. Run command:\r
320```cmd\r
321> LLVM_PATH/bin/clang-format.exe -style=file -i changed_file.cpp\r
322```\r
323\r
324### Manifests\r
325\r
326We require that the manifest file be formatted. Use the following command to format all manifest files:\r
327\r
328```cmd\r
329> vcpkg format-manifest --all\r
330```\r
331\r
332## Useful implementation notes\r
333\r
334### Portfiles are run in Script Mode\r
335\r
336While `portfile.cmake`'s and `CMakeLists.txt`'s share a common syntax and core CMake language constructs, portfiles run in "Script Mode", whereas `CMakeLists.txt` files run in "Build Mode" (unofficial term). The most important difference between these two modes is that "Script Mode" does not have a concept of "Target" -- any behaviors that depend on the "target" machine (`CMAKE_CXX_COMPILER`, `CMAKE_EXECUTABLE_SUFFIX`, `CMAKE_SYSTEM_NAME`, etc) will not be correct.\r
337\r
338Portfiles have direct access to variables set in the triplet file, but `CMakeLists.txt`s do not (though there is often a translation that happens -- `VCPKG_LIBRARY_LINKAGE` versus `BUILD_SHARED_LIBS`).\r
339\r
340Portfiles and CMake builds invoked by portfiles are run in different processes. Conceptually:\r
341\r
342```no-highlight\r
343+----------------------------+ +------------------------------------+\r
344| CMake.exe | | CMake.exe |\r
345+----------------------------+ +------------------------------------+\r
346| Triplet file | ====> | Toolchain file |\r
347| (x64-windows.cmake) | | (scripts/buildsystems/vcpkg.cmake) |\r
348+----------------------------+ +------------------------------------+\r
349| Portfile | ====> | CMakeLists.txt |\r
350| (ports/foo/portfile.cmake) | | (buildtrees/../CMakeLists.txt) |\r
351+----------------------------+ +------------------------------------+\r
352```\r
353\r
354To determine the host in a portfile, the standard CMake variables are fine (`CMAKE_HOST_WIN32`).\r
355\r
356To determine the target in a portfile, the vcpkg triplet variables should be used (`VCPKG_CMAKE_SYSTEM_NAME`).\r
357\r
358See also our [triplet documentation](../users/triplets.md) for a full enumeration of possible settings.\r