From 77bd639c4c92c819c1f4444a112d2bcc72c5b92f Mon Sep 17 00:00:00 2001 From: Daniel Barter Date: Wed, 26 Oct 2022 08:54:52 -0700 Subject: [PATCH] cc-wrapper: adding a cc-wrapper-hook to the cc-wrapper --- doc/stdenv/stdenv.chapter.md | 7 +++++++ pkgs/build-support/cc-wrapper/cc-wrapper.sh | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index 166587d3284c..4fad249097c6 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -1140,6 +1140,13 @@ Here are some more packages that provide a setup hook. Since the list of hooks i Many other packages provide hooks, that are not part of `stdenv`. You can find these in the [Hooks Reference](#chap-hooks). +### Compiler and Linker wrapper hooks {#compiler-linker-wrapper-hooks} + +If the file `${cc}/nix-support/cc-wrapper-hook` exists, it will be run at the end of the [compiler wrapper](#cc-wrapper). +If the file `${binutils}/nix-support/post-link-hook` exists, it will be run at the end of the linker wrapper. +These hooks allow a user to inject code into the wrappers. +As an example, these hooks can be used to extract `extraBefore`, `params` and `extraAfter` which store all the command line arguments passed to the compiler and linker respectively. + ## Purity in Nixpkgs {#sec-purity-in-nixpkgs} *Measures taken to prevent dependencies on packages outside the store, and what you can do to prevent them.* diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 78759f2cfbbc..cf9a351f3950 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -219,6 +219,12 @@ fi PATH="$path_backup" # Old bash workaround, see above. +# if a cc-wrapper-hook exists, run it. +if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then + compiler=@prog@ + source @out@/nix-support/cc-wrapper-hook +fi + if (( "${NIX_CC_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then exec @prog@ @<(printf "%q\n" \ ${extraBefore+"${extraBefore[@]}"} \