use fromToolchainFile

I *think* this will make it easier to pull in extra rustc targets.
This commit is contained in:
Charles Hall 2024-01-22 22:48:58 -08:00
parent 692a31620d
commit 52954f7a11
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
4 changed files with 31 additions and 30 deletions

View file

@ -62,6 +62,7 @@ oci-image:x86_64-unknown-linux-gnu:
debian:x86_64-unknown-linux-gnu: debian:x86_64-unknown-linux-gnu:
stage: artifacts stage: artifacts
# See also `rust-toolchain.toml`
image: rust:1.70.0 image: rust:1.70.0
script: script:
- apt-get update && apt-get install -y --no-install-recommends libclang-dev - apt-get update && apt-get install -y --no-install-recommends libclang-dev

View file

@ -9,12 +9,7 @@ readme = "README.md"
version = "0.7.0-alpha" version = "0.7.0-alpha"
edition = "2021" edition = "2021"
# When changing this, make sure to update the hash near the text "THE # See also `rust-toolchain.toml`
# rust-version HASH" in `flake.nix`. If you don't have Nix installed or
# otherwise don't know how to do this, ping `@charles:computer.surgery` or
# `@dusk:gaze.systems` in the matrix room.
#
# Also make sure to update the docker image tags in `.gitlab-ci.yml`.
rust-version = "1.70.0" rust-version = "1.70.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -32,33 +32,15 @@
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
# The Rust toolchain to use # The Rust toolchain to use
toolchain = fenix.packages.${system}.toolchainOf { toolchain = fenix.packages.${system}.fromToolchainFile {
# Use the Rust version defined in `Cargo.toml` file = ./rust-toolchain.toml;
channel = cargoToml.package.rust-version;
# THE rust-version HASH # See also `rust-toolchain.toml`
sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc="; sha256 = "sha256-gdYqng0y9iHYzYPAdkC/ka3DRny3La/S5G8ASj0Ayyc=";
}; };
mkToolchain = fenix.packages.${system}.combine;
buildToolchain = mkToolchain (with toolchain; [
cargo
rustc
]);
devToolchain = mkToolchain (with toolchain; [
cargo
clippy
rust-src
rustc
# Always use nightly rustfmt because most of its options are unstable
fenix.packages.${system}.latest.rustfmt
]);
builder = pkgs: builder = pkgs:
((crane.mkLib pkgs).overrideToolchain buildToolchain).buildPackage; ((crane.mkLib pkgs).overrideToolchain toolchain).buildPackage;
nativeBuildInputs = pkgs: [ nativeBuildInputs = pkgs: [
pkgs.rustPlatform.bindgenHook pkgs.rustPlatform.bindgenHook
@ -114,12 +96,18 @@
# Rust Analyzer needs to be able to find the path to default crate # Rust Analyzer needs to be able to find the path to default crate
# sources, and it can read this environment variable to do so. The # sources, and it can read this environment variable to do so. The
# `rust-src` component is required in order for this to work. # `rust-src` component is required in order for this to work.
RUST_SRC_PATH = "${devToolchain}/lib/rustlib/src/rust/library"; RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
}; };
# Development tools # Development tools
nativeBuildInputs = nativeBuildInputs pkgsHost ++ [ nativeBuildInputs = nativeBuildInputs pkgsHost ++ [
devToolchain # Always use nightly rustfmt because most of its options are unstable
#
# This needs to come before `toolchain` in this list, otherwise
# `$PATH` will have stable rustfmt instead.
fenix.packages.${system}.latest.rustfmt
toolchain
] ++ (with pkgsHost; [ ] ++ (with pkgsHost; [
engage engage
]); ]);

17
rust-toolchain.toml Normal file
View file

@ -0,0 +1,17 @@
# This is the authoritiative configuration of this project's Rust toolchain.
#
# Other files that need upkeep when this changes:
#
# * `.gitlab-ci.yml`
# * `Cargo.toml`
# * `flake.nix`
#
# Search in those files for `rust-toolchain.toml` to find the relevant places.
# If you're having trouble making the relevant changes, bug a maintainer.
[toolchain]
channel = "1.70.0"
components = [
# For rust-analyzer
"rust-src",
]