diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support/rust/sysroot')
-rw-r--r-- | nixpkgs/pkgs/build-support/rust/sysroot/Cargo.lock | 44 | ||||
-rw-r--r-- | nixpkgs/pkgs/build-support/rust/sysroot/cargo.py | 47 | ||||
-rw-r--r-- | nixpkgs/pkgs/build-support/rust/sysroot/src.nix | 26 | ||||
-rwxr-xr-x | nixpkgs/pkgs/build-support/rust/sysroot/update-lockfile.sh | 27 |
4 files changed, 144 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/rust/sysroot/Cargo.lock b/nixpkgs/pkgs/build-support/rust/sysroot/Cargo.lock new file mode 100644 index 000000000000..d9b0c25d02f2 --- /dev/null +++ b/nixpkgs/pkgs/build-support/rust/sysroot/Cargo.lock @@ -0,0 +1,44 @@ +# 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/nixpkgs/pkgs/build-support/rust/sysroot/cargo.py b/nixpkgs/pkgs/build-support/rust/sysroot/cargo.py new file mode 100644 index 000000000000..9d970eff79e8 --- /dev/null +++ b/nixpkgs/pkgs/build-support/rust/sysroot/cargo.py @@ -0,0 +1,47 @@ +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/nixpkgs/pkgs/build-support/rust/sysroot/src.nix b/nixpkgs/pkgs/build-support/rust/sysroot/src.nix new file mode 100644 index 000000000000..664702e82c31 --- /dev/null +++ b/nixpkgs/pkgs/build-support/rust/sysroot/src.nix @@ -0,0 +1,26 @@ +{ 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/nixpkgs/pkgs/build-support/rust/sysroot/update-lockfile.sh b/nixpkgs/pkgs/build-support/rust/sysroot/update-lockfile.sh new file mode 100755 index 000000000000..d0596d1e5a62 --- /dev/null +++ b/nixpkgs/pkgs/build-support/rust/sysroot/update-lockfile.sh @@ -0,0 +1,27 @@ +#!/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" |