refactor(rust): try to better compose cross toolchains
This commit is contained in:
parent
8142658f81
commit
6c25032fcd
105
rust/flake.nix
105
rust/flake.nix
|
@ -35,50 +35,62 @@
|
|||
overlays = [ (final: prev: { ${packageName} = self.packages.${system}.${packageName}; }) ];
|
||||
};
|
||||
|
||||
fenix-pkgs = fenix.packages.${system};
|
||||
fenix-channel = fenix-pkgs.toolchainOf {
|
||||
channel = "nightly";
|
||||
date =
|
||||
builtins.replaceStrings [ "nightly-" ] [ "" ]
|
||||
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
|
||||
sha256 = "sha256-SzEeSoO54GiBQ2kfANPhWrt0EDRxqEvhIbTt2uJt/TQ=";
|
||||
};
|
||||
fenixPkgsFor = pkgs: fenix.packages.${pkgs.system};
|
||||
fenixChannelFor =
|
||||
pkgs:
|
||||
(fenixPkgsFor pkgs).toolchainOf {
|
||||
channel = "nightly";
|
||||
date =
|
||||
builtins.replaceStrings [ "nightly-" ] [ "" ]
|
||||
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
|
||||
sha256 = "sha256-SzEeSoO54GiBQ2kfANPhWrt0EDRxqEvhIbTt2uJt/TQ=";
|
||||
};
|
||||
|
||||
makeCrossPackage =
|
||||
packageName: pkgsCross:
|
||||
toolchainFor =
|
||||
pkgs:
|
||||
let
|
||||
pkgs = builtins.throw "defining cross pkg, accessing pkgs is a bug";
|
||||
fenix-pkgs = fenixPkgsFor pkgs;
|
||||
in
|
||||
with fenix-pkgs;
|
||||
combine [
|
||||
minimal.cargo
|
||||
minimal.rustc
|
||||
targets.${pkgs.rust.lib.toRustTarget pkgs.stdenv.targetPlatform}.latest.rust-std
|
||||
];
|
||||
|
||||
rustPlatformFor =
|
||||
pkgs:
|
||||
let
|
||||
toolchain = toolchainFor pkgs;
|
||||
in
|
||||
pkgs.makeRustPlatform {
|
||||
cargo = toolchain;
|
||||
rustc = toolchain;
|
||||
};
|
||||
|
||||
crossPackageFor =
|
||||
pkgs:
|
||||
let
|
||||
rustPlatform = rustPlatformFor pkgs;
|
||||
in
|
||||
{
|
||||
"${packageName}-cross-${pkgsCross.stdenv.hostPlatform.config}${
|
||||
if pkgsCross.stdenv.hostPlatform.isStatic then "-static" else ""
|
||||
}" =
|
||||
let
|
||||
toolchain =
|
||||
with fenix-pkgs;
|
||||
combine [
|
||||
minimal.cargo
|
||||
minimal.rustc
|
||||
targets.${pkgsCross.rust.lib.toRustTarget pkgsCross.stdenv.targetPlatform}.latest.rust-std
|
||||
];
|
||||
in
|
||||
pkgsCross.callPackage (./. + "/nix/packages/${packageName}.nix") {
|
||||
inherit cargoMeta;
|
||||
flake-self = self;
|
||||
rustPlatform = pkgsCross.makeRustPlatform {
|
||||
cargo = toolchain;
|
||||
rustc = toolchain;
|
||||
};
|
||||
};
|
||||
"${packageName}-cross-${pkgs.stdenv.hostPlatform.config}${
|
||||
if pkgs.stdenv.hostPlatform.isStatic then "-static" else ""
|
||||
}" = pkgs.callPackage (./. + "/nix/packages/${packageName}.nix") {
|
||||
inherit cargoMeta rustPlatform;
|
||||
flake-self = self;
|
||||
};
|
||||
};
|
||||
in
|
||||
function {
|
||||
inherit
|
||||
system
|
||||
pkgs
|
||||
fenix-pkgs
|
||||
fenix-channel
|
||||
makeCrossPackage
|
||||
fenixPkgsFor
|
||||
fenixChannelFor
|
||||
toolchainFor
|
||||
rustPlatformFor
|
||||
crossPackageFor
|
||||
;
|
||||
}
|
||||
);
|
||||
|
@ -89,11 +101,14 @@
|
|||
packages = forSystems (
|
||||
{
|
||||
pkgs,
|
||||
fenix-channel,
|
||||
fenixChannelFor,
|
||||
system,
|
||||
makeCrossPackage,
|
||||
crossPackageFor,
|
||||
...
|
||||
}:
|
||||
let
|
||||
fenix-channel = fenixChannelFor pkgs;
|
||||
in
|
||||
{
|
||||
${packageName} = pkgs.callPackage (./. + "/nix/packages/${packageName}.nix") {
|
||||
inherit cargoMeta;
|
||||
|
@ -105,21 +120,17 @@
|
|||
};
|
||||
default = self.packages.${system}.${packageName};
|
||||
}
|
||||
// makeCrossPackage packageName pkgs.pkgsCross.musl64.pkgsStatic
|
||||
// makeCrossPackage packageName pkgs.pkgsCross.musl32.pkgsStatic
|
||||
// makeCrossPackage packageName pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsStatic
|
||||
// makeCrossPackage packageName pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsStatic
|
||||
// makeCrossPackage packageName pkgs.pkgsCross.mingwW64.pkgsStatic
|
||||
// crossPackageFor pkgs.pkgsCross.musl64.pkgsStatic
|
||||
// crossPackageFor pkgs.pkgsCross.musl32.pkgsStatic
|
||||
// crossPackageFor pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsStatic
|
||||
// crossPackageFor pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsStatic
|
||||
// crossPackageFor pkgs.pkgsCross.mingwW64.pkgsStatic
|
||||
);
|
||||
|
||||
devShells = forSystems (
|
||||
{
|
||||
pkgs,
|
||||
fenix-pkgs,
|
||||
fenix-channel,
|
||||
...
|
||||
}:
|
||||
{ pkgs, fenixChannelFor, ... }:
|
||||
let
|
||||
fenix-channel = fenixChannelFor pkgs;
|
||||
fenixRustToolchain = fenix-channel.withComponents [
|
||||
"cargo"
|
||||
"clippy-preview"
|
||||
|
|
Loading…
Reference in a new issue