1
0
Fork 0
forked from auxolotl/templates

refactor(rust): try to better compose cross toolchains

This commit is contained in:
Florian Warzecha 2024-05-10 23:29:17 +02:00
parent 8142658f81
commit 6c25032fcd
Signed by untrusted user: liketechnik
GPG key ID: 4BE8C7D97F910C60

View file

@ -35,8 +35,10 @@
overlays = [ (final: prev: { ${packageName} = self.packages.${system}.${packageName}; }) ];
};
fenix-pkgs = fenix.packages.${system};
fenix-channel = fenix-pkgs.toolchainOf {
fenixPkgsFor = pkgs: fenix.packages.${pkgs.system};
fenixChannelFor =
pkgs:
(fenixPkgsFor pkgs).toolchainOf {
channel = "nightly";
date =
builtins.replaceStrings [ "nightly-" ] [ "" ]
@ -44,31 +46,39 @@
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
{
"${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
targets.${pkgs.rust.lib.toRustTarget pkgs.stdenv.targetPlatform}.latest.rust-std
];
rustPlatformFor =
pkgs:
let
toolchain = toolchainFor pkgs;
in
pkgsCross.callPackage (./. + "/nix/packages/${packageName}.nix") {
inherit cargoMeta;
flake-self = self;
rustPlatform = pkgsCross.makeRustPlatform {
pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
crossPackageFor =
pkgs:
let
rustPlatform = rustPlatformFor pkgs;
in
{
"${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
@ -76,9 +86,11 @@
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"