build: fix rust-toolchain

This commit is contained in:
Jonas Röger 2024-11-19 22:03:26 +01:00
parent b458b99c82
commit 587471f36a
Signed by: jonas
GPG Key ID: 4000EB35E1AE0F07
6 changed files with 100 additions and 173 deletions

12
Cargo.lock generated
View File

@ -125,9 +125,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.19.0" version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -490,9 +490,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.161" version = "0.2.164"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
[[package]] [[package]]
name = "libfuzzer-sys" name = "libfuzzer-sys"
@ -1188,9 +1188,9 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]] [[package]]
name = "wide" name = "wide"
version = "0.7.28" version = "0.7.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b828f995bf1e9622031f8009f8481a85406ce1f4d4588ff746d872043e855690" checksum = "58e6db2670d2be78525979e9a5f9c69d296fd7d670549fe9ebf70f8708cb5019"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"safe_arch", "safe_arch",

117
flake.lock generated
View File

@ -101,15 +101,17 @@
"flake-compat": "flake-compat_3", "flake-compat": "flake-compat_3",
"flake-parts": "flake-parts_3", "flake-parts": "flake-parts_3",
"nix-test-runner": "nix-test-runner_3", "nix-test-runner": "nix-test-runner_3",
"nixpkgs": "nixpkgs_6", "nixpkgs": [
"nixpkgs"
],
"pre-commit-hooks": "pre-commit-hooks_3" "pre-commit-hooks": "pre-commit-hooks_3"
}, },
"locked": { "locked": {
"lastModified": 1730277369, "lastModified": 1732039290,
"narHash": "sha256-yvQbeJbnnwCB68yv7uZXdGb+P7NMn5JMGBw0aBHymDI=", "narHash": "sha256-LQKY7bShf2H9kJouxa9ZspfdrulnZF9o4kLTqGqCDYM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "crate2nix", "repo": "crate2nix",
"rev": "151122427d030874ebef3517cda766a6984e6ed6", "rev": "9ff208ce7f5a482272b1bcefbe363c772d7ff914",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -258,26 +260,6 @@
"type": "github" "type": "github"
} }
}, },
"devshell_4": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1728330715,
"narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=",
"owner": "numtide",
"repo": "devshell",
"rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"locked": { "locked": {
"lastModified": 1696426674, "lastModified": 1696426674,
@ -386,26 +368,6 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_4": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1730504689,
"narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "506278e768c2a08bec68eb62932193e341f55c90",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -496,6 +458,24 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_6": {
"inputs": {
"systems": "systems_6"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": { "gitignore": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -689,30 +669,16 @@
}, },
"nixpkgs_6": { "nixpkgs_6": {
"locked": { "locked": {
"lastModified": 1712026416, "lastModified": 1717179513,
"narHash": "sha256-N/3VR/9e1NlN49p7kCiATiEY6Tzdo+CbrAG8kqCQKcI=", "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "080a4a27f206d07724b88da096e27ef63401a504", "rev": "63dacb46bf939521bdc93981b4cbb7ecb58427a0",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_7": {
"locked": {
"lastModified": 1731763621,
"narHash": "sha256-ddcX4lQL0X05AYkrkV2LMFgGdRvgap7Ho8kgon3iWZk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c69a9bffbecde46b4b939465422ddc59493d3e4d",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixpkgs-unstable", "ref": "24.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -820,9 +786,8 @@
"root": { "root": {
"inputs": { "inputs": {
"crate2nix": "crate2nix", "crate2nix": "crate2nix",
"devshell": "devshell_4", "flake-utils": "flake-utils_6",
"flake-parts": "flake-parts_4", "nixpkgs": "nixpkgs_6",
"nixpkgs": "nixpkgs_7",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
}, },
@ -833,17 +798,16 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1725575741, "lastModified": 1731983527,
"narHash": "sha256-LaW4WaeNIaju+bo7F7/+TK073JqcuoUvhcxzWp/9OrE=", "narHash": "sha256-JECaBgC0pQ91Hq3W4unH6K9to8s2Zl2sPNu7bLOv4ek=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "6bf986d20552384209907fa0d5f3fa9a34d00995", "rev": "71287228d96e9568e1e70c6bbfa3f992d145947b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "6bf986d20552384209907fa0d5f3fa9a34d00995",
"type": "github" "type": "github"
} }
}, },
@ -921,6 +885,21 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"systems_6": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -2,21 +2,14 @@
description = "Rust-Nix"; description = "Rust-Nix";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/24.05";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay/6bf986d20552384209907fa0d5f3fa9a34d00995"; url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
crate2nix.url = "github:nix-community/crate2nix"; flake-utils.url = "github:numtide/flake-utils";
crate2nix = {
# Development url = "github:nix-community/crate2nix";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
@ -28,44 +21,47 @@
}; };
outputs = inputs @ { outputs = inputs @ {
self,
nixpkgs,
flake-parts,
rust-overlay,
crate2nix, crate2nix,
flake-utils,
nixpkgs,
rust-overlay,
... ...
}: }:
flake-parts.lib.mkFlake {inherit inputs;} { flake-utils.lib.eachDefaultSystem (
systems = [ system: let
"x86_64-linux" # Overlay pkgs with rust-bin
"aarch64-linux" overlays = [(import rust-overlay)];
"x86_64-darwin" pkgs = import nixpkgs {
"aarch64-darwin" inherit system overlays;
]; };
imports = [ # Use rust-bin to generate the toolchain from rust-toolchain.toml
./nix/rust-overlay/flake-module.nix rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
./nix/devshell/flake-module.nix
];
perSystem = { buildRustCrateForPkgs = pkgs:
system, pkgs.buildRustCrate.override {
pkgs, rustc = rust-toolchain; # Use rustc from toolchain
lib, cargo = rust-toolchain; # Use cargo from toolchain
inputs', defaultCrateOverrides =
... pkgs.defaultCrateOverrides
}: let // {
cargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix { # Fix rav1e build.rs:278 error when no CARGO_ENCODED_RUSTFLAGS is set
rav1e = attrs: {
CARGO_ENCODED_RUSTFLAGS = "";
};
};
};
# Cargo.nix for IFD
generatedCargoNix = crate2nix.tools.${system}.generatedCargoNix {
name = "rustnix"; name = "rustnix";
src = ./.; src = ./.;
}; };
in rec {
checks = {
rustnix = cargoNix.rootCrate.build.override {
runTests = true;
};
};
cargoNix = import generatedCargoNix {
inherit pkgs buildRustCrateForPkgs;
};
in rec {
apps = rec { apps = rec {
demo = { demo = {
type = "app"; type = "app";
@ -81,18 +77,13 @@
}; };
default = demo; default = demo;
}; };
packages = rec {
packages = { lispers = cargoNix.rootCrate.build;
rustnix = cargoNix.rootCrate.build; default = lispers;
default = packages.rustnix;
inherit (pkgs) rust-toolchain;
rust-toolchain-versions = pkgs.writeScriptBin "rust-toolchain-versions" ''
${pkgs.rust-toolchain}/bin/cargo --version
${pkgs.rust-toolchain}/bin/rustc --version
'';
};
}; };
devShell = pkgs.mkShell {
buildInputs = [rust-toolchain];
}; };
}
);
} }

View File

@ -1,25 +0,0 @@
{ inputs, lib, ... }: {
imports = [
inputs.devshell.flakeModule
];
config.perSystem =
{ pkgs
, ...
}: {
config.devshells.default = {
imports = [
"${inputs.devshell}/extra/language/c.nix"
# "${inputs.devshell}/extra/language/rust.nix"
];
commands = with pkgs; [
{ package = rust-toolchain; category = "rust"; }
];
language.c = {
libraries = lib.optional pkgs.stdenv.isDarwin pkgs.libiconv;
};
};
};
}

View File

@ -1,18 +0,0 @@
{ inputs, ... }:
let
overlays = [
(import inputs.rust-overlay)
(self: super: assert !(super ? rust-toolchain); rec {
rust-toolchain = super.rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
# buildRustCrate/crate2nix depend on this.
rustc = rust-toolchain;
cargo = rust-toolchain;
})
];
in
{
perSystem = { system, ... }: {
_module.args.pkgs = import inputs.nixpkgs { inherit system overlays; config = { }; };
};
}

View File

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "stable" channel = "nightly"
components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"] components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"]