|
37 | 37 | ''; |
38 | 38 | }; |
39 | 39 |
|
| 40 | + # The Nix cc-wrapper knows nothing about the FHS tree. buildFHSEnv teaches it |
| 41 | + # by exporting `NIX_CFLAGS_COMPILE=-idirafter /usr/include` and |
| 42 | + # `NIX_LDFLAGS=-L/usr/lib ...` from the profile, so any build that sanitises |
| 43 | + # the environment before invoking the compiler loses /usr/include and |
| 44 | + # /usr/lib. Bazel is the case in point: with `--incompatible_strict_action_env` |
| 45 | + # and an explicit action `env`, the compiler is handed nothing but PATH and |
| 46 | + # HOME, and a Bazel-driven Verilator build fails on `#include <libelf.h>` even |
| 47 | + # though libelf is right there in the sandbox. |
| 48 | + # |
| 49 | + # Bake the FHS search paths into the wrapper instead, so the compiler behaves |
| 50 | + # like a system compiler no matter what environment it is invoked from. The |
| 51 | + # wrapper's add-flags.sh reads `nix-support/cc-cflags` and `cc-ldflags` |
| 52 | + # unconditionally — unlike the generic `NIX_*` variables, which it only |
| 53 | + # consumes when the matching `NIX_{CC,BINTOOLS}_WRAPPER_TARGET_HOST_<salt>` |
| 54 | + # role variable is also set. `-idirafter` keeps /usr/include last in the |
| 55 | + # search order, after the wrapper's own libc headers and any package's -I. |
| 56 | + # Same intent as the pkg-config and aclocal wrappers below. |
| 57 | + cc-fhs = pkgs.stdenv.cc.override (old: { |
| 58 | + extraBuildCommands = |
| 59 | + (old.extraBuildCommands or "") |
| 60 | + + '' |
| 61 | + echo "-idirafter /usr/include" >> $out/nix-support/cc-cflags |
| 62 | + echo "-L/usr/lib -L/usr/lib32" >> $out/nix-support/cc-ldflags |
| 63 | + ''; |
| 64 | + }); |
| 65 | + |
40 | 66 | # Bazel filters out all environment including PKG_CONFIG_PATH. Append this inside wrapper. |
41 | 67 | pkg-config-patched = pkgs.pkg-config.override { |
42 | 68 | extraBuildCommands = '' |
|
82 | 108 | lsb-release # some tools probe the host OS even when unsupported |
83 | 109 |
|
84 | 110 | # Toolchain (tools invoke a compiler/linker for DPI, cosim models, etc.). |
85 | | - stdenv.cc |
| 111 | + # Wrapped above so it finds /usr/include and /usr/lib without relying on |
| 112 | + # the profile's NIX_CFLAGS_COMPILE / NIX_LDFLAGS reaching the compiler. |
| 113 | + cc-fhs |
86 | 114 | # A modern, *unwrapped* binutils so /usr/bin/{ld,as,ar,objdump,...} are |
87 | 115 | # plain system-style tools. stdenv.cc alone provides a wrapped `ld` that |
88 | 116 | # injects Nix-specific dynamic-linker/rpath flags — unwanted by vendor |
|
0 commit comments