Cheng Shao pushed to branch wip/fix-darwin-toolchain-cruft at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • .gitlab/darwin/nix/sources.json
    1 1
     {
    
    2
    -    "niv": {
    
    3
    -        "branch": "master",
    
    4
    -        "description": "Easy dependency management for Nix projects",
    
    5
    -        "homepage": "https://github.com/nmattia/niv",
    
    6
    -        "owner": "nmattia",
    
    7
    -        "repo": "niv",
    
    8
    -        "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070",
    
    9
    -        "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx",
    
    10
    -        "type": "tarball",
    
    11
    -        "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz",
    
    12
    -        "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
    
    13
    -    },
    
    14 2
         "nixpkgs": {
    
    15
    -        "branch": "nixos-unstable",
    
    3
    +        "branch": "nixpkgs-25.05-darwin",
    
    16 4
             "description": "Nix Packages collection",
    
    17 5
             "homepage": "",
    
    18 6
             "owner": "nixos",
    
    19 7
             "repo": "nixpkgs",
    
    20
    -        "rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60",
    
    21
    -        "sha256": "1anwxmjpm21msnnlrjdz19w31bxnbpn4kgf93sn3npihi7wf4a8h",
    
    8
    +        "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
    
    9
    +        "sha256": "0v6bd1xk8a2aal83karlvc853x44dg1n4nk08jg3dajqyy0s98np",
    
    22 10
             "type": "tarball",
    
    23
    -        "url": "https://github.com/nixos/nixpkgs/archive/2893f56de08021cffd9b6b6dfc70fd9ccd51eb60.tar.gz",
    
    11
    +        "url": "https://github.com/nixos/nixpkgs/archive/ac62194c3917d5f474c1a844b6fd6da2db95077d.tar.gz",
    
    24 12
             "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
    
    25 13
         }
    
    26 14
     }

  • .gitlab/darwin/nix/sources.nix
    ... ... @@ -10,29 +10,50 @@ let
    10 10
         let
    
    11 11
           name' = sanitizeName name + "-src";
    
    12 12
         in
    
    13
    -      if spec.builtin or true then
    
    14
    -        builtins_fetchurl { inherit (spec) url sha256; name = name'; }
    
    15
    -      else
    
    16
    -        pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
    
    13
    +    if spec.builtin or true then
    
    14
    +      builtins_fetchurl { inherit (spec) url sha256; name = name'; }
    
    15
    +    else
    
    16
    +      pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
    
    17 17
     
    
    18 18
       fetch_tarball = pkgs: name: spec:
    
    19 19
         let
    
    20 20
           name' = sanitizeName name + "-src";
    
    21 21
         in
    
    22
    -      if spec.builtin or true then
    
    23
    -        builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
    
    24
    -      else
    
    25
    -        pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
    
    22
    +    if spec.builtin or true then
    
    23
    +      builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
    
    24
    +    else
    
    25
    +      pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
    
    26 26
     
    
    27 27
       fetch_git = name: spec:
    
    28 28
         let
    
    29 29
           ref =
    
    30
    -        if spec ? ref then spec.ref else
    
    30
    +        spec.ref or (
    
    31 31
               if spec ? branch then "refs/heads/${spec.branch}" else
    
    32
    -            if spec ? tag then "refs/tags/${spec.tag}" else
    
    33
    -              abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
    
    32
    +          if spec ? tag then "refs/tags/${spec.tag}" else
    
    33
    +          abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
    
    34
    +        );
    
    35
    +      submodules = spec.submodules or false;
    
    36
    +      submoduleArg =
    
    37
    +        let
    
    38
    +          nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
    
    39
    +          emptyArgWithWarning =
    
    40
    +            if submodules
    
    41
    +            then
    
    42
    +              builtins.trace
    
    43
    +                (
    
    44
    +                  "The niv input \"${name}\" uses submodules "
    
    45
    +                  + "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
    
    46
    +                  + "does not support them"
    
    47
    +                )
    
    48
    +                { }
    
    49
    +            else { };
    
    50
    +        in
    
    51
    +        if nixSupportsSubmodules
    
    52
    +        then { inherit submodules; }
    
    53
    +        else emptyArgWithWarning;
    
    34 54
         in
    
    35
    -      builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
    
    55
    +    builtins.fetchGit
    
    56
    +      ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
    
    36 57
     
    
    37 58
       fetch_local = spec: spec.path;
    
    38 59
     
    
    ... ... @@ -66,16 +87,16 @@ let
    66 87
           hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
    
    67 88
           hasThisAsNixpkgsPath = <nixpkgs> == ./.;
    
    68 89
         in
    
    69
    -      if builtins.hasAttr "nixpkgs" sources
    
    70
    -      then sourcesNixpkgs
    
    71
    -      else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
    
    72
    -        import <nixpkgs> {}
    
    73
    -      else
    
    74
    -        abort
    
    75
    -          ''
    
    76
    -            Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
    
    77
    -            add a package called "nixpkgs" to your sources.json.
    
    78
    -          '';
    
    90
    +    if builtins.hasAttr "nixpkgs" sources
    
    91
    +    then sourcesNixpkgs
    
    92
    +    else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
    
    93
    +      import <nixpkgs> { }
    
    94
    +    else
    
    95
    +      abort
    
    96
    +        ''
    
    97
    +          Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
    
    98
    +          add a package called "nixpkgs" to your sources.json.
    
    99
    +        '';
    
    79 100
     
    
    80 101
       # The actual fetching function.
    
    81 102
       fetch = pkgs: name: spec:
    
    ... ... @@ -95,13 +116,13 @@ let
    95 116
       # the path directly as opposed to the fetched source.
    
    96 117
       replace = name: drv:
    
    97 118
         let
    
    98
    -      saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
    
    119
    +      saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
    
    99 120
           ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
    
    100 121
         in
    
    101
    -      if ersatz == "" then drv else
    
    102
    -        # this turns the string into an actual Nix path (for both absolute and
    
    103
    -        # relative paths)
    
    104
    -        if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
    
    122
    +    if ersatz == "" then drv else
    
    123
    +      # this turns the string into an actual Nix path (for both absolute and
    
    124
    +      # relative paths)
    
    125
    +    if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
    
    105 126
     
    
    106 127
       # Ports of functions for older nix versions
    
    107 128
     
    
    ... ... @@ -112,7 +133,7 @@ let
    112 133
       );
    
    113 134
     
    
    114 135
       # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
    
    115
    -  range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
    
    136
    +  range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
    
    116 137
     
    
    117 138
       # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
    
    118 139
       stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
    
    ... ... @@ -123,43 +144,46 @@ let
    123 144
       concatStrings = builtins.concatStringsSep "";
    
    124 145
     
    
    125 146
       # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
    
    126
    -  optionalAttrs = cond: as: if cond then as else {};
    
    147
    +  optionalAttrs = cond: as: if cond then as else { };
    
    127 148
     
    
    128 149
       # fetchTarball version that is compatible between all the versions of Nix
    
    129 150
       builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
    
    130 151
         let
    
    131 152
           inherit (builtins) lessThan nixVersion fetchTarball;
    
    132 153
         in
    
    133
    -      if lessThan nixVersion "1.12" then
    
    134
    -        fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
    
    135
    -      else
    
    136
    -        fetchTarball attrs;
    
    154
    +    if lessThan nixVersion "1.12" then
    
    155
    +      fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
    
    156
    +    else
    
    157
    +      fetchTarball attrs;
    
    137 158
     
    
    138 159
       # fetchurl version that is compatible between all the versions of Nix
    
    139 160
       builtins_fetchurl = { url, name ? null, sha256 }@attrs:
    
    140 161
         let
    
    141 162
           inherit (builtins) lessThan nixVersion fetchurl;
    
    142 163
         in
    
    143
    -      if lessThan nixVersion "1.12" then
    
    144
    -        fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
    
    145
    -      else
    
    146
    -        fetchurl attrs;
    
    164
    +    if lessThan nixVersion "1.12" then
    
    165
    +      fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
    
    166
    +    else
    
    167
    +      fetchurl attrs;
    
    147 168
     
    
    148 169
       # Create the final "sources" from the config
    
    149 170
       mkSources = config:
    
    150
    -    mapAttrs (
    
    151
    -      name: spec:
    
    152
    -        if builtins.hasAttr "outPath" spec
    
    153
    -        then abort
    
    154
    -          "The values in sources.json should not have an 'outPath' attribute"
    
    155
    -        else
    
    156
    -          spec // { outPath = replace name (fetch config.pkgs name spec); }
    
    157
    -    ) config.sources;
    
    171
    +    mapAttrs
    
    172
    +      (
    
    173
    +        name: spec:
    
    174
    +          if builtins.hasAttr "outPath" spec
    
    175
    +          then
    
    176
    +            abort
    
    177
    +              "The values in sources.json should not have an 'outPath' attribute"
    
    178
    +          else
    
    179
    +            spec // { outPath = replace name (fetch config.pkgs name spec); }
    
    180
    +      )
    
    181
    +      config.sources;
    
    158 182
     
    
    159 183
       # The "config" used by the fetchers
    
    160 184
       mkConfig =
    
    161 185
         { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
    
    162
    -    , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
    
    186
    +    , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
    
    163 187
         , system ? builtins.currentSystem
    
    164 188
         , pkgs ? mkPkgs sources system
    
    165 189
         }: rec {
    
    ... ... @@ -171,4 +195,4 @@ let
    171 195
         };
    
    172 196
     
    
    173 197
     in
    
    174
    -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
    198
    +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

  • .gitlab/darwin/toolchain.nix
    ... ... @@ -11,69 +11,67 @@ let
    11 11
       hsPkgs = pkgs.haskellPackages;
    
    12 12
       alex = hsPkgs.alex;
    
    13 13
       happy = hsPkgs.happy;
    
    14
    -  targetTriple = pkgs.stdenv.targetPlatform.config;
    
    14
    +  targetTriple = pkgs.stdenvNoCC.targetPlatform.config;
    
    15 15
     
    
    16 16
       ghcBindists = let version = ghc.version; in {
    
    17
    -    aarch64-darwin = hostPkgs.fetchurl {
    
    17
    +    aarch64-darwin = hostPkgs.fetchzip {
    
    18 18
           url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-apple-darwin.tar.xz";
    
    19
    -      sha256 = "sha256-/6+DtdeossBJIMbjkJwL4h3eJ7rzgNCV+ifoQKOi6AQ=";
    
    19
    +      hash = "sha512-xUlt7zc/OT3a1SR0BxmFFgrabPkWUENATdw4NbQwEi5+nH5yPau+HSrGI5UUoKdO4gdpgZlPaxtI7eSk0fx1+g==";
    
    20 20
         };
    
    21
    -    x86_64-darwin = hostPkgs.fetchurl {
    
    21
    +    x86_64-darwin = hostPkgs.fetchzip {
    
    22 22
           url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-x86_64-apple-darwin.tar.xz";
    
    23
    -      sha256 = "sha256-jPIhiJMOENesUnDUJeIaPatgavc6ZVSTY5NFIAxlC+k=";
    
    23
    +      hash = "sha512-4/INeJwPPGbOj9MepwnIvIg2lvFkqS8w/3U/I8f6gCsoNlgwPr78iyY9vd6vfMONR1GxNQU3L/lxE07F3P0Qag==";
    
    24 24
         };
    
    25
    -
    
    26 25
       };
    
    27 26
     
    
    28
    -  ghc = pkgs.stdenv.mkDerivation rec {
    
    29
    -    version = "9.10.1";
    
    27
    +  ghc = pkgs.stdenvNoCC.mkDerivation rec {
    
    28
    +    version = "9.10.3";
    
    30 29
         name = "ghc";
    
    31
    -    src = ghcBindists.${pkgs.stdenv.hostPlatform.system};
    
    30
    +    src = ghcBindists.${pkgs.stdenvNoCC.hostPlatform.system};
    
    31
    +
    
    32
    +    dontUpdateAutotoolsGnuConfigScripts = true;
    
    33
    +
    
    32 34
         configureFlags = [
    
    33
    -      "CC=/usr/bin/clang"
    
    34
    -      "CLANG=/usr/bin/clang"
    
    35 35
           "AR=/usr/bin/ar"
    
    36
    -      "LLC=${llvm}/bin/llc"
    
    37
    -      "OPT=${llvm}/bin/opt"
    
    38
    -      "LLVMAS=${llvm_clang}/bin/clang"
    
    39
    -      "CONF_CC_OPTS_STAGE2=--target=${targetTriple}"
    
    40
    -      "CONF_CXX_OPTS_STAGE2=--target=${targetTriple}"
    
    41
    -      "CONF_GCC_LINKER_OPTS_STAGE2=--target=${targetTriple}"
    
    36
    +      "CC=/usr/bin/clang"
    
    37
    +      "CXX=/usr/bin/clang++"
    
    38
    +      "INSTALL=/usr/bin/install"
    
    39
    +      "INSTALL_NAME_TOOL=/usr/bin/install_name_tool"
    
    40
    +      "MergeObjsCmd=/usr/bin/ld"
    
    41
    +      "NM=/usr/bin/nm"
    
    42
    +      "OTOOL=/usr/bin/otool"
    
    43
    +      "RANLIB=/usr/bin/ranlib"
    
    42 44
         ];
    
    43
    -    buildPhase = "true";
    
    44
    -
    
    45
    -    # This is a horrible hack because the configure script invokes /usr/bin/clang
    
    46
    -    # without a `--target` flag. Then depending on whether the `nix` binary itself is
    
    47
    -    # a native x86 or arm64 binary means that /usr/bin/clang thinks it needs to run in
    
    48
    -    # x86 or arm64 mode.
    
    49
    -
    
    50
    -    # The correct answer for the check in question is the first one we try, so by replacing
    
    51
    -    # the condition to true; we select the right C++ standard library still.
    
    52
    -    preConfigure = ''
    
    53
    -      sed "s/\"\$CC\" -o actest actest.o \''${1} 2>\/dev\/null/true/i" configure > configure.new
    
    54
    -      mv configure.new configure
    
    55
    -      chmod +x configure
    
    56
    -      cat configure
    
    57 45
     
    
    46
    +    # Use the arch command to explicitly specify architecture, so that
    
    47
    +    # configure and its subprocesses would pick up the architecture we
    
    48
    +    # choose via the system argument.
    
    49
    +    preConfigure = pkgs.lib.optionalString (system == "aarch64-darwin") ''
    
    50
    +      substituteInPlace configure \
    
    51
    +        --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -arm64 /bin/sh"
    
    52
    +    '' + pkgs.lib.optionalString (system == "x86_64-darwin") ''
    
    53
    +      substituteInPlace configure \
    
    54
    +        --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -x86_64 /bin/sh"
    
    55
    +    '' + ''
    
    56
    +      unset DEVELOPER_DIR SDKROOT
    
    57
    +      export DEVELOPER_DIR="$(/usr/bin/xcode-select --print-path)"
    
    58
    +      export SDKROOT="$(/usr/bin/xcrun --sdk macosx --show-sdk-path)"
    
    58 59
         '';
    
    59 60
     
    
    61
    +    dontPatchShebangsInConfigure = true;
    
    62
    +
    
    60 63
         # N.B. Work around #20253.
    
    61 64
         nativeBuildInputs = [ pkgs.gnused ];
    
    62
    -    postInstallPhase = ''
    
    63
    -      settings="$out/lib/ghc-${version}/settings"
    
    64
    -      sed -i -e "s%\"llc\"%\"${llvm}/bin/llc\"%" $settings
    
    65
    -      sed -i -e "s%\"opt\"%\"${llvm}/bin/opt\"%" $settings
    
    66
    -      sed -i -e "s%\"clang\"%\"/usr/bin/clang\"%" $settings
    
    67
    -      sed -i -e 's%("C compiler command", "")%("C compiler command", "/usr/bin/clang")%' $settings
    
    68
    -      sed -i -e 's%("C compiler flags", "")%("C compiler flags", "--target=${targetTriple}")%' $settings
    
    69
    -      sed -i -e 's%("C++ compiler flags", "")%("C++ compiler flags", "--target=${targetTriple}")%' $settings
    
    70
    -      sed -i -e 's%("C compiler link flags", "")%("C compiler link flags", "--target=${targetTriple}")%' $settings
    
    71
    -    '';
    
    65
    +
    
    66
    +    dontBuild = true;
    
    67
    +
    
    68
    +    enableParallelInstalling = true;
    
    69
    +
    
    70
    +    dontFixup = true;
    
    72 71
     
    
    73 72
         # Sanity check: verify that we can compile hello world.
    
    74 73
         doInstallCheck = true;
    
    75 74
         installCheckPhase = ''
    
    76
    -      unset DYLD_LIBRARY_PATH
    
    77 75
           $out/bin/ghc --info
    
    78 76
           cd $TMP
    
    79 77
           mkdir test-ghc; cd test-ghc
    
    ... ... @@ -96,8 +94,8 @@ let
    96 94
         };
    
    97 95
       fonts = with pkgs; makeFontsConf { fontDirectories = [ dejavu_fonts ]; };
    
    98 96
     
    
    99
    -  llvm = pkgs.llvm_15;
    
    100
    -  llvm_clang = pkgs.llvmPackages_15.clang-unwrapped;
    
    97
    +  llvm = pkgs.llvm_21;
    
    98
    +  llvm_clang = pkgs.llvmPackages_21.clang-unwrapped;
    
    101 99
     in
    
    102 100
     pkgs.writeTextFile {
    
    103 101
       name = "toolchain";