From 6065d768e145ca5782e961774b5f06f0a0520729 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Thu, 24 Nov 2022 16:14:43 -0800 Subject: [PATCH] sapling: fix on macOS There were two factors here: our cargo hook was messing up the cargo config, which broke the build, and also an upstream bug where Sapling didn't work on Python 3.10. The upstream issue was filed as https://github.com/facebook/sapling/issues/279 We can get rid of the python 3.8 override as soon as this patch gets into a released version. --- .../version-management/sapling/default.nix | 56 +++++++++++++++++-- pkgs/top-level/all-packages.nix | 4 +- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/version-management/sapling/default.nix b/pkgs/applications/version-management/sapling/default.nix index 93c67d10bcbc..4598c86fb75b 100644 --- a/pkgs/applications/version-management/sapling/default.nix +++ b/pkgs/applications/version-management/sapling/default.nix @@ -1,7 +1,41 @@ -{ lib, stdenv, python3Packages, fetchFromGitHub, fetchurl, sd, curl, pkg-config, openssl, rustPlatform, fetchYarnDeps, yarn, nodejs, fixup_yarn_lock, glibcLocales }: +{ lib +, stdenv +, python38Packages +, fetchFromGitHub +, fetchurl +, sd +, curl +, pkg-config +, openssl +, rustPlatform +, fetchYarnDeps +, yarn +, nodejs +, fixup_yarn_lock +, glibcLocales +, libiconv +, CoreFoundation +, CoreServices +, Security +}: let inherit (lib.importJSON ./deps.json) links version versionHash; + # Sapling sets a Cargo config containing lines like so: + # [target.aarch64-apple-darwin] + # rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"] + # + # The default cargo config that's set by the build hook will set + # unstable.host-config and unstable.target-applies-to-host which seems to + # result in the link arguments above being ignored and thus link failures. + # All it is there to do anyway is just to do stuff with musl and cross + # compilation, which doesn't work on macOS anyway so we can just stub it + # on macOS. + # + # See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295 + myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: { + cargoConfig = if stdenv.isDarwin then "" else old.cargoConfig; + }); src = fetchFromGitHub { owner = "facebook"; @@ -54,7 +88,11 @@ let }; # Builds the main `sl` binary and its Python extensions - sapling = python3Packages.buildPythonPackage { + # + # FIXME(lf-): when next updating this package, delete the python 3.8 override + # here, since the fix for https://github.com/facebook/sapling/issues/279 that + # required it will be in the next release. + sapling = python38Packages.buildPythonPackage { pname = "sapling-main"; inherit src version; @@ -85,7 +123,7 @@ let sed -i "s|https://files.pythonhosted.org/packages/[[:alnum:]]*/[[:alnum:]]*/[[:alnum:]]*/|file://$NIX_BUILD_TOP/$sourceRoot/hack_pydeps/|g" $sourceRoot/setup.py ''; - postFixup = '' + postFixup = lib.optionalString stdenv.isLinux '' wrapProgram $out/bin/sl \ --set LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive" ''; @@ -94,13 +132,19 @@ let curl pkg-config ] ++ (with rustPlatform; [ - cargoSetupHook + myCargoSetupHook rust.cargo rust.rustc ]); buildInputs = [ + curl openssl + ] ++ lib.optionals stdenv.isDarwin [ + libiconv + CoreFoundation + CoreServices + Security ]; doCheck = false; @@ -124,7 +168,7 @@ stdenv.mkDerivation { cp -r ${sapling}/* $out - sitepackages=$out/lib/${python3Packages.python.libPrefix}/site-packages + sitepackages=$out/lib/${python38Packages.python.libPrefix}/site-packages chmod +w $sitepackages cp -r ${isl} $sitepackages/edenscm-isl @@ -145,7 +189,7 @@ stdenv.mkDerivation { homepage = "https://sapling-scm.com"; license = licenses.gpl2Only; maintainers = with maintainers; [ pbar thoughtpolice ]; - platforms = platforms.linux; + platforms = platforms.unix; mainProgram = "sl"; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6338c5b0a5ea..dd2356a81471 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -30435,7 +30435,9 @@ with pkgs; inherit (darwin.apple_sdk.frameworks) ApplicationServices; }; - sapling = callPackage ../applications/version-management/sapling { }; + sapling = callPackage ../applications/version-management/sapling { + inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Security; + }; mercurialFull = mercurial.override { fullBuild = true; };