Skip to content

Commit 8afa321

Browse files
committed
llvmPackages_15.llvm: add checks for the LLVM version
this is in preparation for the next commit which exposes the release information and monorepo source as overridable args (which makes it easier for users to use their own LLVM in nixpkgs) this commit only adds a check in the `llvm` package's postConfigure that makes sure the LLVM source provided matches the version we were given; the actual machinery (functionally just a cosmetic change; causes no rebuilds) is in the next commit
1 parent 386aba3 commit 8afa321

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

pkgs/development/compilers/llvm/15/llvm/default.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,38 @@ in stdenv.mkDerivation (rec {
255255
)
256256
'';
257257

258+
# Defensive check: some paths (that we make symlinks to) depend on the release
259+
# version, for example:
260+
# - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185
261+
#
262+
# So we want to sure that the version in the source matches the release
263+
# version we were given.
264+
#
265+
# We do this check here, in the LLVM build, because it happens early.
266+
postConfigure = let
267+
v = lib.versions;
268+
major = v.major release_version;
269+
minor = v.minor release_version;
270+
patch = v.patch release_version;
271+
in ''
272+
# $1: part, $2: expected
273+
check_version() {
274+
part="''${1^^}"
275+
part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)"
276+
277+
if [[ "$part" != "$2" ]]; then
278+
echo >&2 \
279+
"mismatch in the $1 version! we have version ${release_version}" \
280+
"and expected the $1 version to be '$2'; the source has '$part' instead"
281+
exit 3
282+
fi
283+
}
284+
285+
check_version major ${major}
286+
check_version minor ${minor}
287+
check_version patch ${patch}
288+
'';
289+
258290
# E.g. mesa.drivers use the build-id as a cache key (see #93946):
259291
LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1";
260292

0 commit comments

Comments
 (0)