Unverified Commit c8127fc2 authored by Alyssa Ross's avatar Alyssa Ross
Browse files

build-support/rust/sysroot: remove

The sysroot derivation used by buildRustPackage hasn't built since
c263e0b3 ("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.
parent a4a6f50e
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
@@ -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';
+0 −52
Original line number Diff line number Diff line
{
  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;
}
+0 −44
Original line number Diff line number Diff line
# 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"
+0 −47
Original line number Diff line number Diff line
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)
+0 −31
Original line number Diff line number Diff line
{
  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
    '';
}
Loading