How to upgrade llvm_git
-
Run
update-git.py. This will set the github revision and sha256 forllvmPackages_git.llvmto whatever the latest chromium build is using. For a more recent, commit runnix-prefetch-githuband change the rev and sha256 accordingly. -
That was the easy part. The hard part is updating the patch files.
The general process is:
-
Try to build
llvmPackages_git.llvmand associated packages such asclangandcompiler-rt. You can use the-Land--keep-failedflags to make debugging patch errors easy, e.g.,nix build .#llvmPackages_git.clang -L --keep-failed -
The build will error out with something similar to this:
... clang-unstable> patching sources clang-unstable> applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch clang-unstable> patching file lib/Driver/ToolChains/Gnu.cpp clang-unstable> Hunk #1 FAILED at 487. clang-unstable> 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej note: keeping build directory '/tmp/nix-build-clang-unstable-2022-25-07.drv-17' error: builder for '/nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv' failed with exit code 1; last 8 log lines: > unpacking sources > unpacking source archive /nix/store/mrxadx11wv1ckjr2208qgxp472pmmg6g-clang-src-unstable-2022-25-07 > source root is clang-src-unstable-2022-25-07/clang > patching sources > applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch > patching file lib/Driver/ToolChains/Gnu.cpp > Hunk #1 FAILED at 487. > 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej For full logs, run 'nix log /nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv'. note: keeping build directory '/tmp/nix-build-compiler-rt-libc-unstable-2022-25-07.drv-20' error: 1 dependencies of derivation '/nix/store/ndbbh3wrl0l39b22azf46f1n7zlqwmag-clang-wrapper-unstable-2022-25-07.drv' failed to buildNotice the
Hunk #1 Failed at 487line. The lines above show us that thepurity.patchfailed onlib/Driver/ToolChains/Gnu.cppwhen compilingclang.
-
-
The task now is to cross reference the hunks in the purity patch with
lib/Driver/ToolCahins/Gnu.cpp.origto see why the patch failed. The.origfile will be in the build directory referenced in the linenote: keeping build directory ...; this message results from the--keep-failedflag. -
Now you should be able to open whichever patch failed, and the
foo.origfile that it failed on. Correct the patch by adapting it to the new code and be mindful of whitespace; which can be an easily missed reason for failures. For cases where the hunk is no longer needed you can simply remove it from the patch.
This is fine for small corrections, but when more serious changes are needed its better to use git.
-
Clone the LLVM monorepo at https://github.com/llvm/llvm-project/
-
Check out the revision we were using before.
-
Use
patch -p1 < path/to-pathin the project subdirectories to apply the patches and commit. -
Use
git rebase HEAD^ --onto <dest>to rebase the patches onto the new revision we are trying to build, and fix all conflicts. -
Use
git diff HEAD^:<project> HEAD:<project>to get subdir diff to write back to Nixpkgs.
Information on our current patch sets
"GNU Install Dirs" patches
Use CMake's GNUInstallDirs to support multiple outputs.
Previously, LLVM Just hard-coded bin, include, and lib${LLVM_TARGET_PREFIX}.
We are making it use these variables.
For the older LLVM versions, these patches live in https://github.com/Ericson2314/llvm-project branches split-prefix.
Instead of applying the patches to the worktree per the above instructions, one can checkout those directly and rebase those instead.
For newer LLVM versions, enough has has been upstreamed, (see https://reviews.llvm.org/differential/query/5UAfpj_9zHwY/ for my progress upstreaming), that I have just assembled new gnu-install-dirs patches from the remaining unmerged patches instead of rebasing from the prior LLVM's gnu install dirs patch.
Adding a patch
To add an LLVM patch in the Nixpkgs tree,
-
Put the patch in the corresponding directory (
<VERSION>/<PACKAGE>).Example: If you want your patch to apply to clang version 12 (and, optionally, later versions), put it in
./12/clang. -
Add the patch to the
patchesargument of the corresponding package in./common, guarded by alib.optionalswith the desired version constraints, passed through thegetVersionFilefunction.Example: If you want the patch
./12/llvm/fix-llvm-issue-49955.patchto apply to LLVM 12, addlib.optional (lib.versions.major release_version == "12") (getVersionFile "llvm/fix-llvm-issue-49955.patch")to./common/llvm/default.nix. -
If you wish for this single patch to apply to multiple versions of the package, extend the conditions in the
lib.optionalguard and add the corresponding constraints to./common/patches.nix; note thatafteris inclusive andbeforeis exclusive.Example: If you want the patch
./12/clang/purity.patchto apply to versions 12, 13 and 14, you have to- Modify the guard in
./common/clang/default.nixas follows:lib.optional (lib.versionAtLeast release_version "12" && lib.versionOlder release_version "15") - Add
{ "clang/purity.patch" = [ { after = 12; before = 15; path = ../12; } ]; }tocommon/patches.nix. You may have multiple different patches with the same name that would apply to different versions; in that case, add the necessary constraints tocommon/patches.nix.
- Modify the guard in