diff --git a/custom/override.nix b/custom/override.nix index fc04874..a43360c 100644 --- a/custom/override.nix +++ b/custom/override.nix @@ -26,9 +26,24 @@ let toolchain, }: final.runCommand name { } '' + resolve_orig_cc_root() { + local current_root="$1" + local next_root + + while [ -r "$current_root/nix-support/orig-cc" ]; do + next_root="$(tr -d '\n' < "$current_root/nix-support/orig-cc")" + if [ -z "$next_root" ] || [ "$next_root" = "$current_root" ]; then + break + fi + current_root="$next_root" + done + + printf '%s\n' "$current_root" + } + wrapped_clang="$(readlink -f ${toolchain}/bin/clang)" wrapped_root="$(dirname "$(dirname "$wrapped_clang")")" - orig_cc_root="$(tr -d '\n' < "$wrapped_root/nix-support/orig-cc")" + orig_cc_root="$(resolve_orig_cc_root "$wrapped_root")" if [ -z "$orig_cc_root" ] || [ ! -d "$orig_cc_root/bin" ]; then echo "mkRealCompilerBasePath: invalid orig-cc root: $orig_cc_root" >&2 @@ -71,6 +86,7 @@ let sccacheCacheSize ? "100G", noDaemon ? false, passthroughWrappedCompiler ? false, + extraSetup ? "", }: let sccacheConfig = final.writeText "${name}-config" '' @@ -91,12 +107,18 @@ let } is_cmake_probe_invocation() { - local arg + local arg response_file for arg in "$@"; do case "$arg" in *CMakeFiles/*CompilerId*|*CMakeFiles/CMakeTmp/*|*CMakeScratch/*) return 0 ;; + @*) + response_file="''${arg#@}" + if [ -f "$response_file" ] && grep -Eq 'CMakeFiles/.+CompilerId|CMakeFiles/CMakeTmp|CMakeScratch' "$response_file"; then + return 0 + fi + ;; esac done @@ -112,6 +134,7 @@ let ${final.lib.optionalString (!noDaemon && sccacheServerUds != null) '' export SCCACHE_SERVER_UDS=${final.lib.escapeShellArg sccacheServerUds} ''} + ${extraSetup} if [ "$#" -eq 0 ] || [ "''${1#-}" != "$1" ]; then exec ${final.sccache}/bin/sccache "$@" fi @@ -180,9 +203,9 @@ let nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ sccacheLauncher ]; preConfigure = (old.preConfigure or "") + '' - mkdir -p ${final.lib.escapeShellArg sandboxSccacheDir} chmod 0777 ${final.lib.escapeShellArg sandboxSccacheDir} || true + export SCCACHE_WRAPPED_COMPILER_PASSTHROUGH=1 export SCCACHE_SERVER_UDS="$TMPDIR/sccache/server.sock" export SCCACHE_IDLE_TIMEOUT=0 unset SCCACHE_NO_DAEMON @@ -198,6 +221,10 @@ let fi ''; + postConfigure = (old.postConfigure or "") + '' + unset SCCACHE_WRAPPED_COMPILER_PASSTHROUGH + ''; + postBuild = (old.postBuild or "") + '' ${sccacheLauncher}/bin/cmake-sccache --show-stats --stats-format text || true @@ -268,6 +295,13 @@ in passthru = (old.passthru or { }) // { links = { unwrappedCC, extraConfig ? "" }: + let + sccacheLauncher = mkSccacheLauncher { + name = "wrapped-sccache"; + noDaemon = true; + extraSetup = extraConfig; + }; + in final.stdenv.mkDerivation { pname = "sccache-links"; inherit (old) version; @@ -296,12 +330,12 @@ in in '' mkdir -p $out/bin + mkdir -p $out/nix-support wrap() { local cname="${targetPrefix}$1" if [ -x "${unwrappedCC}/bin/$cname" ]; then - makeWrapper ${final.sccache}/bin/sccache $out/bin/$cname \ - --run ${final.lib.escapeShellArg extraConfig} \ + makeWrapper ${sccacheLauncher}/bin/wrapped-sccache $out/bin/$cname \ --add-flags ${unwrappedCC}/bin/$cname fi } @@ -321,6 +355,8 @@ in for file in $(ls ${unwrappedCC} | grep -vw bin); do ln -s ${unwrappedCC}/$file $out/$file done + + printf '%s\n' "${unwrappedCC}" > $out/nix-support/orig-cc ''; meta = final.lib.optionalAttrs (unwrappedCC.meta ? mainProgram) { inherit (unwrappedCC.meta) mainProgram; @@ -553,6 +589,9 @@ inline sycl::event submit_wait_on_events(sycl::queue q, const std::vector