mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-09 16:18:34 +01:00
cc-wrapper: make availability warnings into errors (#445119)
This commit is contained in:
commit
5c2b79edfa
|
|
@ -222,6 +222,9 @@
|
|||
"sec-building-packages-with-llvm-using-clang-stdenv": [
|
||||
"index.html#sec-building-packages-with-llvm-using-clang-stdenv"
|
||||
],
|
||||
"sec-darwin-availability-checks": [
|
||||
"index.html#sec-darwin-availability-checks"
|
||||
],
|
||||
"sec-darwin-libcxx-deployment-targets": [
|
||||
"index.html#sec-darwin-libcxx-deployment-targets"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -47,6 +47,17 @@ See below for how to use a newer deployment target.
|
|||
For example, `std::print` depends on features that are only available on macOS 13.3 or newer.
|
||||
To make them available, set the deployment target to 13.3 using `darwinMinVersionHook`.
|
||||
|
||||
#### Package fails to build due to missing API availability checks {#sec-darwin-availability-checks}
|
||||
|
||||
This is normally a bug in the package or a misconfigured deployment target.
|
||||
* If it is using an API from a newer release (e.g., from macOS 26.0 while targeting macOS 14.0), it needs to use an availability check.
|
||||
The code should be patched to use [`__builtin_available`](https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available).
|
||||
Note that while the linked documentation is for Objective-C, it is applicable to C and C++ except that you use `__builtin_available` in place of `@available`.
|
||||
* If the package intends to require the newer platform (i.e., it does not support running on older versions with reduced functionality), use `darwinMinVersionHook` to set the deployment target to the required version.
|
||||
See below for how to use a newer deployment target.
|
||||
* If the package actually handles this through some other mechanism (e.g., MoltenVK relies on the running platform’s MSL version), the error can be suppressed.
|
||||
To suppress the error, add `-Wno-error=unguarded-availability` to `env.NIX_CFLAGS_COMPILE`.
|
||||
|
||||
#### Package requires a non-default SDK or fails to build due to missing frameworks or symbols {#sec-darwin-troubleshooting-using-sdks}
|
||||
|
||||
In some cases, you may have to use a non-default SDK.
|
||||
|
|
|
|||
|
|
@ -35,3 +35,7 @@ elif [[ $0 != *cpp ]]; then
|
|||
extraBefore+=(-mabi=@explicitAbiValue@)
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "@darwinMinVersion@" ]]; then
|
||||
extraBefore+=(-Werror=unguarded-availability)
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -51,6 +51,13 @@ stdenv.mkDerivation (finalAttrs: {
|
|||
};
|
||||
|
||||
postPatch = ''
|
||||
# Update the deployment target for the minimum target used by nixpkgs.
|
||||
while IFS= read -d "" proj; do
|
||||
echo "Updating deployment target to ${stdenv.hostPlatform.darwinMinVersion}: $proj"
|
||||
substituteInPlace "$proj" \
|
||||
--replace-fail 'MACOSX_DEPLOYMENT_TARGET = 10.15' "MACOSX_DEPLOYMENT_TARGET = $MACOSX_DEPLOYMENT_TARGET"
|
||||
done < <(grep -Z -rl --include=project.pbxproj MACOSX_DEPLOYMENT_TARGET)
|
||||
|
||||
# Move `mvkGitRevDerived.h` to a stable location
|
||||
substituteInPlace Scripts/gen_moltenvk_rev_hdr.sh \
|
||||
--replace-fail '$'''{BUILT_PRODUCTS_DIR}' "$NIX_BUILD_TOP/$sourceRoot/build/include" \
|
||||
|
|
@ -91,7 +98,11 @@ stdenv.mkDerivation (finalAttrs: {
|
|||
'';
|
||||
|
||||
env.NIX_CFLAGS_COMPILE = toString (
|
||||
lib.optional (stdenv.cc.libcxx != null) "-isystem ${lib.getInclude stdenv.cc.libcxx}/include/c++/v1"
|
||||
# MoltenVK does its own checks for availability by probing the version at runtime and checking the MSL version.
|
||||
[ "-Wno-error=unguarded-availability" ]
|
||||
++ lib.optional (
|
||||
stdenv.cc.libcxx != null
|
||||
) "-isystem ${lib.getInclude stdenv.cc.libcxx}/include/c++/v1"
|
||||
++ [
|
||||
"-I${lib.getDev spirv-cross}/include/spirv_cross"
|
||||
"-I${lib.getDev spirv-headers}/include/spirv/unified1"
|
||||
|
|
|
|||
Loading…
Reference in a new issue