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 build
```
Notice the `Hunk #1 Failed at 487` line.
The lines above show us that the `purity.patch` failed on `lib/Driver/ToolChains/Gnu.cpp` when compiling `clang`.
3. The task now is to cross reference the hunks in the purity patch with
`lib/Driver/ToolCahins/Gnu.cpp.orig` to see why the patch failed.
The `.orig` file will be in the build directory referenced in the line `note: keeping build directory ...`;
this message results from the `--keep-failed` flag.
4. Now you should be able to open whichever patch failed, and the `foo.orig` file 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, it's better to use git.
1. Clone the LLVM monorepo at https://github.com/llvm/llvm-project/
2. Check out the revision we were using before.
3. Use `patch -p1 < path/to-path` in the project subdirectories to apply the patches and commit.
4. Use `git rebase HEAD^ --onto <dest>` to rebase the patches onto the new revision we are trying to build, and fix all conflicts.
5. 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`](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) 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`.