Cheng Shao pushed to branch wip/fix-darwin-toolchain-cruft at Glasgow Haskell Compiler / GHC Commits: 4c9d0e22 by Cheng Shao at 2026-01-07T00:51:01+01:00 ci: update darwin boot ghc to 9.10.3 This patch updates darwin boot ghc to 9.10.3, along with other related updates, and pays off some technical debt here: - Update `nixpkgs` and use the `nixpkgs-25.05-darwin` channel. - Update the `niv` template. - Update LLVM to 21. - Use `stdenvNoCC` to prevent nix packaged apple sdk from being used by boot ghc, and manually set `DEVELOPER_DIR`/`SDKROOT` to enforce the usage of system-wide command line sdk for macos. - When building nix derivation for boot ghc, run `configure` via the `arch` command so that `configure` and its subprocesses pick up the manually specified architecture. - Remove the previous horrible hack that obliterates `configure` to make every autoconf test result in true. `configure` now properly does its job. - Remove the now obsolete configure args and post install settings file patching logic. - - - - - 3 changed files: - .gitlab/darwin/nix/sources.json - .gitlab/darwin/nix/sources.nix - .gitlab/darwin/toolchain.nix Changes: ===================================== .gitlab/darwin/nix/sources.json ===================================== @@ -1,26 +1,14 @@ { - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", - "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42...", - "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" - }, "nixpkgs": { - "branch": "nixos-unstable", + "branch": "nixpkgs-25.05-darwin", "description": "Nix Packages collection", "homepage": "", "owner": "nixos", "repo": "nixpkgs", - "rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60", - "sha256": "1anwxmjpm21msnnlrjdz19w31bxnbpn4kgf93sn3npihi7wf4a8h", + "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d", + "sha256": "0v6bd1xk8a2aal83karlvc853x44dg1n4nk08jg3dajqyy0s98np", "type": "tarball", - "url": "https://github.com/nixos/nixpkgs/archive/2893f56de08021cffd9b6b6dfc70fd9ccd5...", + "url": "https://github.com/nixos/nixpkgs/archive/ac62194c3917d5f474c1a844b6fd6da2db9...", "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" } } ===================================== .gitlab/darwin/nix/sources.nix ===================================== @@ -10,29 +10,50 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -66,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = <nixpkgs> == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import <nixpkgs> {} - else - abort - '' - Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import <nixpkgs> { } + else + abort + '' + Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -95,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -112,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee... - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee... stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -123,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d1... - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -171,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } ===================================== .gitlab/darwin/toolchain.nix ===================================== @@ -11,69 +11,67 @@ let hsPkgs = pkgs.haskellPackages; alex = hsPkgs.alex; happy = hsPkgs.happy; - targetTriple = pkgs.stdenv.targetPlatform.config; + targetTriple = pkgs.stdenvNoCC.targetPlatform.config; ghcBindists = let version = ghc.version; in { - aarch64-darwin = hostPkgs.fetchurl { + aarch64-darwin = hostPkgs.fetchzip { url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-apple-darwin.tar.xz"; - sha256 = "sha256-/6+DtdeossBJIMbjkJwL4h3eJ7rzgNCV+ifoQKOi6AQ="; + hash = "sha512-xUlt7zc/OT3a1SR0BxmFFgrabPkWUENATdw4NbQwEi5+nH5yPau+HSrGI5UUoKdO4gdpgZlPaxtI7eSk0fx1+g=="; }; - x86_64-darwin = hostPkgs.fetchurl { + x86_64-darwin = hostPkgs.fetchzip { url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-x86_64-apple-darwin.tar.xz"; - sha256 = "sha256-jPIhiJMOENesUnDUJeIaPatgavc6ZVSTY5NFIAxlC+k="; + hash = "sha512-4/INeJwPPGbOj9MepwnIvIg2lvFkqS8w/3U/I8f6gCsoNlgwPr78iyY9vd6vfMONR1GxNQU3L/lxE07F3P0Qag=="; }; - }; - ghc = pkgs.stdenv.mkDerivation rec { - version = "9.10.1"; + ghc = pkgs.stdenvNoCC.mkDerivation rec { + version = "9.10.3"; name = "ghc"; - src = ghcBindists.${pkgs.stdenv.hostPlatform.system}; + src = ghcBindists.${pkgs.stdenvNoCC.hostPlatform.system}; + + dontUpdateAutotoolsGnuConfigScripts = true; + configureFlags = [ - "CC=/usr/bin/clang" - "CLANG=/usr/bin/clang" "AR=/usr/bin/ar" - "LLC=${llvm}/bin/llc" - "OPT=${llvm}/bin/opt" - "LLVMAS=${llvm_clang}/bin/clang" - "CONF_CC_OPTS_STAGE2=--target=${targetTriple}" - "CONF_CXX_OPTS_STAGE2=--target=${targetTriple}" - "CONF_GCC_LINKER_OPTS_STAGE2=--target=${targetTriple}" + "CC=/usr/bin/clang" + "CXX=/usr/bin/clang++" + "INSTALL=/usr/bin/install" + "INSTALL_NAME_TOOL=/usr/bin/install_name_tool" + "MergeObjsCmd=/usr/bin/ld" + "NM=/usr/bin/nm" + "OTOOL=/usr/bin/otool" + "RANLIB=/usr/bin/ranlib" ]; - buildPhase = "true"; - - # This is a horrible hack because the configure script invokes /usr/bin/clang - # without a `--target` flag. Then depending on whether the `nix` binary itself is - # a native x86 or arm64 binary means that /usr/bin/clang thinks it needs to run in - # x86 or arm64 mode. - - # The correct answer for the check in question is the first one we try, so by replacing - # the condition to true; we select the right C++ standard library still. - preConfigure = '' - sed "s/\"\$CC\" -o actest actest.o \''${1} 2>\/dev\/null/true/i" configure > configure.new - mv configure.new configure - chmod +x configure - cat configure + # Use the arch command to explicitly specify architecture, so that + # configure and its subprocesses would pick up the architecture we + # choose via the system argument. + preConfigure = pkgs.lib.optionalString (system == "aarch64-darwin") '' + substituteInPlace configure \ + --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -arm64 /bin/sh" + '' + pkgs.lib.optionalString (system == "x86_64-darwin") '' + substituteInPlace configure \ + --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -x86_64 /bin/sh" + '' + '' + unset DEVELOPER_DIR SDKROOT + export DEVELOPER_DIR="$(/usr/bin/xcode-select --print-path)" + export SDKROOT="$(/usr/bin/xcrun --sdk macosx --show-sdk-path)" ''; + dontPatchShebangsInConfigure = true; + # N.B. Work around #20253. nativeBuildInputs = [ pkgs.gnused ]; - postInstallPhase = '' - settings="$out/lib/ghc-${version}/settings" - sed -i -e "s%\"llc\"%\"${llvm}/bin/llc\"%" $settings - sed -i -e "s%\"opt\"%\"${llvm}/bin/opt\"%" $settings - sed -i -e "s%\"clang\"%\"/usr/bin/clang\"%" $settings - sed -i -e 's%("C compiler command", "")%("C compiler command", "/usr/bin/clang")%' $settings - sed -i -e 's%("C compiler flags", "")%("C compiler flags", "--target=${targetTriple}")%' $settings - sed -i -e 's%("C++ compiler flags", "")%("C++ compiler flags", "--target=${targetTriple}")%' $settings - sed -i -e 's%("C compiler link flags", "")%("C compiler link flags", "--target=${targetTriple}")%' $settings - ''; + + dontBuild = true; + + enableParallelInstalling = true; + + dontFixup = true; # Sanity check: verify that we can compile hello world. doInstallCheck = true; installCheckPhase = '' - unset DYLD_LIBRARY_PATH $out/bin/ghc --info cd $TMP mkdir test-ghc; cd test-ghc @@ -96,8 +94,8 @@ let }; fonts = with pkgs; makeFontsConf { fontDirectories = [ dejavu_fonts ]; }; - llvm = pkgs.llvm_15; - llvm_clang = pkgs.llvmPackages_15.clang-unwrapped; + llvm = pkgs.llvm_21; + llvm_clang = pkgs.llvmPackages_21.clang-unwrapped; in pkgs.writeTextFile { name = "toolchain"; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4c9d0e22cff41bcd77ae4216f3cbeeef... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4c9d0e22cff41bcd77ae4216f3cbeeef... You're receiving this email because of your account on gitlab.haskell.org.