Unverified Commit e44ac85d authored by Someone's avatar Someone Committed by GitHub
Browse files

Merge pull request #275921 from SomeoneSerge/fix/cuda-pkg-config

cudaPackages: replace the FHS paths in pkg-config files
parents bd80da2d 5d6136a5
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
{cudaVersion, lib}:
{cudaVersion, lib, addDriverRunpath}:
let
  inherit (lib) attrsets lists strings;
  # cudaVersionOlder : Version -> Boolean
@@ -42,6 +42,21 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
    lists.optionals (cudaVersionAtLeast "12.0") [final.libnvjitlink.lib]
  );

  cuda_cudart = prev.cuda_cudart.overrideAttrs (
    prevAttrs: {
      allowFHSReferences = false;

      # The libcuda stub's pkg-config doesn't follow the general pattern:
      postPatch = prevAttrs.postPatch or "" + ''
        while IFS= read -r -d $'\0' path ; do
          sed -i \
            -e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib/stubs|" \
            -e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \
            "$path"
        done < <(find -iname 'cuda-*.pc' -print0)
      '';
    });

  cuda_compat = prev.cuda_compat.overrideAttrs (
    prevAttrs: {
      env.autoPatchelfIgnoreMissingDeps =
@@ -115,6 +130,9 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
          moveToOutput "nvvm" "''${!outputBin}"
        '';

      # The nvcc and cicc binaries contain hard-coded references to /usr
      allowFHSReferences = true;

      meta = (oldAttrs.meta or { }) // {
        mainProgram = "nvcc";
      };
+36 −1
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ backendStdenv.mkDerivation (
    # entries are skipped if they don't exist in outputs.
    outputToPatterns = {
      bin = [ "bin" ];
      dev = [
        "share/pkg-config"
        "**/*.pc"
        "**/*.cmake"
      ];
      lib = [
        "lib"
        "lib64"
@@ -116,6 +121,22 @@ backendStdenv.mkDerivation (
      inherit (redistribRelease.${redistArch}) sha256;
    };

    postPatch = ''
      if [[ -d pkg-config ]] ; then
        mkdir -p share/pkg-config
        mv pkg-config/* share/pkg-config/
        rmdir pkg-config
      fi

      for pc in share/pkg-config/*.pc ; do
        sed -i \
          -e "s|^cudaroot\s*=.*\$|cudaroot=''${!outputDev}|" \
          -e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib|" \
          -e "s|^includedir\s*=.*/include\$|includedir=''${!outputDev}/include|" \
          "$pc"
      done
    '';

    # We do need some other phases, like configurePhase, so the multiple-output setup hook works.
    dontBuild = true;

@@ -197,6 +218,20 @@ backendStdenv.mkDerivation (
        runHook postInstall
      '';

    doInstallCheck = true;
    allowFHSReferences = true; # TODO: Default to `false`
    postInstallCheck = ''
      echo "Executing postInstallCheck"

      if [[ -z "''${allowFHSReferences-}" ]] ; then
        mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "''${!o}"; done)
        if grep --max-count=5 --recursive --exclude=LICENSE /usr/ "''${outputPaths[@]}" ; then
          echo "Detected references to /usr" >&2
          exit 1
        fi
      fi
    '';

    # libcuda needs to be resolved during runtime
    # NOTE: Due to the use of __structuredAttrs, we can't use a list for autoPatchelfIgnoreMissingDeps, since it
    # will take only the first value. Instead, we produce a string with the values separated by spaces.