From c8127fc287c344b9578458e69c760e36d4284749 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 30 Jan 2025 16:04:08 +0100 Subject: [PATCH] build-support/rust/sysroot: remove MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sysroot derivation used by buildRustPackage hasn't built since c263e0b33b77 ("cargo,clippy,rustc,rustfmt: 1.81.0 -> 1.82.0"). That means that it's never built on 24.11, so there can't be anybody relying on it working on any supported version Nixpkgs. In the meantime, it's causing maintenance friction — I've spent a lot of time trying to figure out how to build it as part of the transition away from fetchCargoTarball, before realising that it doesn't work anyway and must be unused. It can come back in the future if somebody wants to maintain it. --- .../rust/build-rust-package/default.nix | 24 +-------- .../build-rust-package/sysroot/default.nix | 52 ------------------- pkgs/build-support/rust/sysroot/Cargo.lock | 44 ---------------- pkgs/build-support/rust/sysroot/cargo.py | 47 ----------------- pkgs/build-support/rust/sysroot/src.nix | 31 ----------- .../rust/sysroot/update-lockfile.sh | 27 ---------- 6 files changed, 1 insertion(+), 224 deletions(-) delete mode 100644 pkgs/build-support/rust/build-rust-package/sysroot/default.nix delete mode 100644 pkgs/build-support/rust/sysroot/Cargo.lock delete mode 100644 pkgs/build-support/rust/sysroot/cargo.py delete mode 100644 pkgs/build-support/rust/sysroot/src.nix delete mode 100755 pkgs/build-support/rust/sysroot/update-lockfile.sh diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 909ec8f4c05f8..058d5a674f26f 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -54,9 +54,6 @@ depsExtraArgs ? { }, - # Toggles whether a custom sysroot is created when the target is a .json file. - __internal_dontAddSysroot ? false, - # Needed to `pushd`/`popd` into a subdir of a tarball if this subdir # contains a Cargo.toml, but isn't part of a workspace (which is e.g. the # case for `rustfmt`/etc from the `rust-sources). @@ -125,21 +122,8 @@ let target = stdenv.hostPlatform.rust.rustcTargetSpec; targetIsJSON = lib.hasSuffix ".json" target; - useSysroot = targetIsJSON && !__internal_dontAddSysroot; - - sysroot = callPackage ./sysroot { } { - inherit target; - shortTarget = stdenv.hostPlatform.rust.cargoShortTarget; - RUSTFLAGS = args.RUSTFLAGS or ""; - originalCargoToml = src + /Cargo.toml; # profile info is later extracted - }; - in -# Tests don't currently work for `no_std`, and all custom sysroots are currently built without `std`. -# See https://os.phil-opp.com/testing/ for more information. -assert useSysroot -> !(args.doCheck or true); - stdenv.mkDerivation ( (removeAttrs args [ "depsExtraArgs" @@ -147,14 +131,8 @@ stdenv.mkDerivation ( "cargoDeps" "cargoLock" ]) - // lib.optionalAttrs useSysroot { - RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); - } // lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") { - RUSTFLAGS = - "-C split-debuginfo=packed " - + lib.optionalString useSysroot "--sysroot ${sysroot} " - + (args.RUSTFLAGS or ""); + RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or ""); } // { cargoDeps = cargoDeps'; diff --git a/pkgs/build-support/rust/build-rust-package/sysroot/default.nix b/pkgs/build-support/rust/build-rust-package/sysroot/default.nix deleted file mode 100644 index d9d071df06ccc..0000000000000 --- a/pkgs/build-support/rust/build-rust-package/sysroot/default.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ - lib, - stdenv, - rustPlatform, - buildPackages, -}: - -{ - shortTarget, - originalCargoToml, - target, - RUSTFLAGS, -}: - -let - cargoSrc = import ../../sysroot/src.nix { - inherit - lib - stdenv - rustPlatform - buildPackages - originalCargoToml - ; - }; -in -rustPlatform.buildRustPackage { - inherit target RUSTFLAGS; - - name = "custom-sysroot"; - src = cargoSrc; - - RUSTC_BOOTSTRAP = 1; - __internal_dontAddSysroot = true; - cargoHash = "sha256-zgkwevitxsu1C4OgGTsqNSc0gDxaNXYK1WPbfER48d0="; - - doCheck = false; - - installPhase = '' - export LIBS_DIR=$out/lib/rustlib/${shortTarget}/lib - mkdir -p $LIBS_DIR - for f in target/${shortTarget}/release/deps/*.{rlib,rmeta}; do - cp $f $LIBS_DIR - done - - export RUST_SYSROOT=$(rustc --print=sysroot) - host=${stdenv.buildPlatform.rust.rustcTarget} - cp -r $RUST_SYSROOT/lib/rustlib/$host $out - ''; - - # allows support for cross-compilation - meta.platforms = lib.platforms.all; -} diff --git a/pkgs/build-support/rust/sysroot/Cargo.lock b/pkgs/build-support/rust/sysroot/Cargo.lock deleted file mode 100644 index d9b0c25d02f2b..0000000000000 --- a/pkgs/build-support/rust/sysroot/Cargo.lock +++ /dev/null @@ -1,44 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "alloc" -version = "0.0.0" -dependencies = [ - "compiler_builtins", - "core", -] - -[[package]] -name = "compiler_builtins" -version = "0.1.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f867ce54c09855ccd135ad4a50c777182a0c7af5ff20a8f537617bd648b10d50" -dependencies = [ - "rustc-std-workspace-core", -] - -[[package]] -name = "core" -version = "0.0.0" - -[[package]] -name = "nixpkgs-sysroot-stub-crate" -version = "0.0.0" -dependencies = [ - "alloc", - "compiler_builtins", - "core", -] - -[[package]] -name = "rustc-std-workspace-core" -version = "1.99.0" -dependencies = [ - "core", -] - -[[patch.unused]] -name = "rustc-std-workspace-alloc" -version = "1.99.0" diff --git a/pkgs/build-support/rust/sysroot/cargo.py b/pkgs/build-support/rust/sysroot/cargo.py deleted file mode 100644 index 9d970eff79e88..0000000000000 --- a/pkgs/build-support/rust/sysroot/cargo.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import toml - -rust_src = os.environ['RUSTC_SRC'] -orig_cargo = os.environ['ORIG_CARGO'] if 'ORIG_CARGO' in os.environ else None - -base = { - 'package': { - 'name': 'nixpkgs-sysroot-stub-crate', - 'version': '0.0.0', - 'authors': ['The Rust Project Developers'], - 'edition': '2018', - }, - 'dependencies': { - 'compiler_builtins': { - 'version': '0.1.0', - 'features': ['rustc-dep-of-std', 'mem'], - }, - 'core': { - 'path': os.path.join(rust_src, 'core'), - }, - 'alloc': { - 'path': os.path.join(rust_src, 'alloc'), - }, - }, - 'patch': { - 'crates-io': { - 'rustc-std-workspace-core': { - 'path': os.path.join(rust_src, 'rustc-std-workspace-core'), - }, - 'rustc-std-workspace-alloc': { - 'path': os.path.join(rust_src, 'rustc-std-workspace-alloc'), - }, - }, - }, -} - -if orig_cargo is not None: - with open(orig_cargo, 'r') as f: - src = toml.loads(f.read()) - if 'profile' in src: - base['profile'] = src['profile'] - -out = toml.dumps(base) - -with open('Cargo.toml', 'x') as f: - f.write(out) diff --git a/pkgs/build-support/rust/sysroot/src.nix b/pkgs/build-support/rust/sysroot/src.nix deleted file mode 100644 index d41cbf55fcdcf..0000000000000 --- a/pkgs/build-support/rust/sysroot/src.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ - lib, - stdenv, - rustPlatform, - buildPackages, - originalCargoToml ? null, -}: - -stdenv.mkDerivation { - name = "cargo-src"; - preferLocalBuild = true; - - unpackPhase = "true"; - dontConfigure = true; - dontBuild = true; - - installPhase = - '' - export RUSTC_SRC=${rustPlatform.rustLibSrc.override { }} - '' - + lib.optionalString (originalCargoToml != null) '' - export ORIG_CARGO=${originalCargoToml} - '' - + '' - ${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py} - mkdir -p $out/src - echo '#![no_std]' > $out/src/lib.rs - cp Cargo.toml $out/Cargo.toml - cp ${./Cargo.lock} $out/Cargo.lock - ''; -} diff --git a/pkgs/build-support/rust/sysroot/update-lockfile.sh b/pkgs/build-support/rust/sysroot/update-lockfile.sh deleted file mode 100755 index d0596d1e5a623..0000000000000 --- a/pkgs/build-support/rust/sysroot/update-lockfile.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p python3 python3.pkgs.toml cargo - -set -eu pipefile - -HERE=$(readlink -e $(dirname "${BASH_SOURCE[0]}")) -NIXPKGS_ROOT="$HERE/../../../.." - -# https://unix.stackexchange.com/a/84980/390173 -tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile') -cd "$tempdir" -mkdir -p src -touch src/lib.rs - -RUSTC_SRC=$(nix-build "${NIXPKGS_ROOT}" -A pkgs.rustPlatform.rustLibSrc --no-out-link) - -ln -s $RUSTC_SRC/{core,alloc} ./ - -export RUSTC_SRC -python3 "$HERE/cargo.py" - -export RUSTC_BOOTSTRAP=1 -cargo generate-lockfile - -cp Cargo.lock "$HERE" - -rm -rf "$tempdir"