Skip to content
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

[vcpkg_check_linkage] Clarify ONLY_DYNAMIC_LIBRARY failures and supports expressions. #432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 33 additions & 4 deletions vcpkg/maintainers/functions/vcpkg_check_linkage.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: vcpkg_check_linkage
description: Assert the available library and CRT linkage options for the port.
ms.date: 01/30/2024
ms.date: 12/05/2024
---
# vcpkg_check_linkage

Expand All @@ -22,11 +22,14 @@ vcpkg_check_linkage(

Indicates that this port can only be built with static library linkage.

If the user requested a dynamic build, `ONLY_STATIC_LIBRARY` will result in a note being printed, not a fatal error.
If the user requested a dynamic build, `ONLY_STATIC_LIBRARY` will result in a note being printed,
not a fatal error.

### ONLY_DYNAMIC_LIBRARY

Indicates that this port can only be built with dynamic/shared library linkage.
Indicates that this port can only be built with dynamic/shared library linkage. When using this
option, port authors should add `!(static & static-crt)` to the `"supports"` expression in the
port's `vcpkg.json` to warn consumers it will fail early.

### ONLY_STATIC_CRT

Expand All @@ -38,7 +41,33 @@ Indicates that this port can only be built with dynamic/shared CRT linkage.

## Notes

This command will either alter the settings for `VCPKG_LIBRARY_LINKAGE` or fail, depending on what was requested by the user versus what the library supports.
If the triplet requests a setting of `VCPKG_LIBRARY_LINAKGE` different than the port supports,
and changing `VCPKG_LIBRARY_LINKAGE` to that the port supports is cosidered safe,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
and changing `VCPKG_LIBRARY_LINKAGE` to that the port supports is cosidered safe,
and changing `VCPKG_LIBRARY_LINKAGE` to that the port supports is considered safe,

`vcpkg_check_linkage` changes `VCPKG_LIBRARY_LINKAGE` to that the port supports and emits a warning.
This means that the port may produce something that the user does not expect, but the alternative
would be to just fail.

If `vcpkg_check_linkage` would change `VCPKG_LIBRARY_LINKAGE` to `dynamic` while the triplet
requests `VCPKG_CRT_LINKAGE` of `static`, the change is not considered safe and
`vcpkg_check_linkage` fails. Building a dynamic library with a static CRT creates conditions many
developers find surprising, and for which most ports are unprepared.

For example, on Windows, each DLL will get its own copy of the CRT, meaning such DLLs cannot share
standard library components over the DLL boundary. On non-Windows, different .sos or .dylibs may
cause mutually incompatible symbols from different CRT versions to be concurrently loaded.

If you are consuming a port and it fails in `vcpkg_check_linkage`, consider choosing a triplet that
sets `VCPKG_CRT_LINKAGE` to `dynamic`. If you really know what you're doing, understand the
potential problems a static CRT with a dynamic library can cause, and are confident that the port
safely handles that configuration, author a custom triplet which explicitly sets
`VCPKG_LIBRARY_LINKAGE` to `dynamic` and `VCPKG_CRT_LINKAGE` to static. For example:

```cmake
if("${PORT}" STREQUAL "the-name-of-the-port-you-want-to-control")
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CRT_LINKAGE static)
endif()
```

## Examples

Expand Down