mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
feat: cross compile as much as possible
This commit is contained in:
parent
31fe742025
commit
446a7b01a7
3 changed files with 105 additions and 143 deletions
178
flake.nix
178
flake.nix
|
@ -1,99 +1,105 @@
|
|||
{
|
||||
description = "The Uncompromising Nix Code Formatter.";
|
||||
description = "The Uncompromising Nix Code Formatter";
|
||||
inputs = {
|
||||
fenix.url = "github:nix-community/fenix";
|
||||
fenix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
fenix.inputs.rust-analyzer-src.follows = "rustAnalyzer";
|
||||
|
||||
flakeCompat.url = github:edolstra/flake-compat;
|
||||
flakeCompat.flake = false;
|
||||
|
||||
flakeUtils.url = "github:numtide/flake-utils";
|
||||
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
rustAnalyzer.url = "github:rust-analyzer/rust-analyzer";
|
||||
rustAnalyzer.flake = false;
|
||||
|
||||
treefmt.url = "github:numtide/treefmt";
|
||||
treefmt.inputs.flake-utils.follows = "flakeUtils";
|
||||
treefmt.inputs.nixpkgs.follows = "nixpkgs";
|
||||
nixpkgs.url = "github:nixos/nixpkgs";
|
||||
};
|
||||
outputs = inputs:
|
||||
inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
|
||||
system: let
|
||||
nixpkgs = import inputs.nixpkgs { inherit system; };
|
||||
nixpkgsMusl = import inputs.nixpkgs {
|
||||
inherit system;
|
||||
crossSystem =
|
||||
nixpkgs.lib.systems.examples.musl64
|
||||
// {
|
||||
rustc.config = "x86_64-unknown-linux-musl";
|
||||
};
|
||||
outputs = inputs: let
|
||||
build = host: target: let
|
||||
nixpkgs = import inputs.nixpkgs {
|
||||
system = host;
|
||||
crossSystem = builtins.getAttr target {
|
||||
"aarch64-apple-darwin" = inputs.nixpkgs.lib.systems.examples.aarch64-darwin;
|
||||
"aarch64-unknown-linux-musl".config = "aarch64-unknown-linux-musl";
|
||||
"x86_64-apple-darwin" = null;
|
||||
"x86_64-unknown-linux-gnu".config = "x86_64-unknown-linux-gnu";
|
||||
"x86_64-unknown-linux-musl".config = "x86_64-unknown-linux-musl";
|
||||
};
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
treefmt = inputs.treefmt.defaultPackage.${system};
|
||||
fenix = inputs.fenix.packages.${system};
|
||||
fenixPlatform = nixpkgs.makeRustPlatform { inherit (fenix.latest) cargo rustc; };
|
||||
fenixPlatformMusl = nixpkgsMusl.makeRustPlatform {
|
||||
cargo = muslToolchain;
|
||||
rustc = muslToolchain;
|
||||
};
|
||||
muslToolchain = with inputs.fenix.packages.${system}; combine [
|
||||
minimal.rustc
|
||||
minimal.cargo
|
||||
targets.x86_64-unknown-linux-musl.latest.rust-std
|
||||
};
|
||||
|
||||
fenix = inputs.fenix.packages.${host};
|
||||
rustPlatform = nixpkgs.makeRustPlatform {
|
||||
cargo = fenix.latest.cargo;
|
||||
rustc = fenix.combine [
|
||||
fenix.latest.rustc
|
||||
fenix.targets.${target}.latest.rust-std
|
||||
];
|
||||
packageWith = platform: target:
|
||||
platform.buildRustPackage {
|
||||
pname = cargoToml.package.name;
|
||||
version =
|
||||
let
|
||||
commit = inputs.self.shortRev or "dirty";
|
||||
date =
|
||||
inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
|
||||
in
|
||||
"${builtins.substring 0 8 date}_${commit}";
|
||||
src = inputs.self.sourceInfo;
|
||||
inherit target;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
meta = {
|
||||
description = cargoToml.package.description;
|
||||
homepage = "https://github.com/kamadorueda/alejandra";
|
||||
license = nixpkgs.lib.licenses.unlicense;
|
||||
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
bin = rustPlatform.buildRustPackage {
|
||||
pname = "alejandra";
|
||||
version =
|
||||
let
|
||||
commit = inputs.self.shortRev or "dirty";
|
||||
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
|
||||
in
|
||||
"${builtins.substring 0 8 date}_${commit}";
|
||||
src = ./.;
|
||||
inherit target;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
meta = {
|
||||
description = "The Uncompromising Nix Code Formatter.";
|
||||
homepage = "https://github.com/kamadorueda/alejandra";
|
||||
license = nixpkgs.lib.licenses.unlicense;
|
||||
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
||||
};
|
||||
in
|
||||
{
|
||||
checks.defaultPackage = inputs.self.defaultPackage.${system};
|
||||
defaultApp = {
|
||||
type = "app";
|
||||
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
|
||||
};
|
||||
defaultPackage = packageWith fenixPlatform system;
|
||||
devShell = nixpkgs.mkShell {
|
||||
name = "Alejandra";
|
||||
packages = [
|
||||
fenix.rust-analyzer
|
||||
fenix.latest.toolchain
|
||||
nixpkgs.cargo-tarpaulin
|
||||
nixpkgs.jq
|
||||
nixpkgs.nodejs
|
||||
nixpkgs.nodePackages.prettier
|
||||
nixpkgs.nodePackages.prettier-plugin-toml
|
||||
nixpkgs.shfmt
|
||||
treefmt
|
||||
];
|
||||
};
|
||||
}
|
||||
// (
|
||||
if system == "x86_64-linux"
|
||||
then
|
||||
{
|
||||
packages.musl = packageWith fenixPlatformMusl "x86_64-unknown-linux-musl";
|
||||
}
|
||||
else { }
|
||||
)
|
||||
);
|
||||
};
|
||||
shell = nixpkgs.mkShell {
|
||||
name = "alejandra";
|
||||
packages = [
|
||||
fenix.latest.toolchain
|
||||
nixpkgs.cargo-tarpaulin
|
||||
nixpkgs.jq
|
||||
nixpkgs.nodejs
|
||||
nixpkgs.nodePackages.prettier
|
||||
nixpkgs.nodePackages.prettier-plugin-toml
|
||||
nixpkgs.shfmt
|
||||
nixpkgs.treefmt
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
rec {
|
||||
checks."aarch64-darwin" = packages."aarch64-darwin";
|
||||
checks."x86_64-darwin" = packages."x86_64-darwin";
|
||||
checks."aarch64-linux" = packages."aarch64-linux";
|
||||
checks."x86_64-linux" = packages."x86_64-linux";
|
||||
|
||||
defaultPackage."aarch64-darwin" =
|
||||
packages."aarch64-darwin"."aarch64-apple-darwin";
|
||||
|
||||
defaultPackage."aarch64-linux" =
|
||||
packages."aarch64-linux"."aarch64-unknown-linux-musl";
|
||||
|
||||
defaultPackage."x86_64-darwin" =
|
||||
packages."x86_64-darwin"."x86_64-apple-darwin";
|
||||
|
||||
defaultPackage."x86_64-linux" =
|
||||
packages."x86_64-linux"."x86_64-unknown-linux-gnu";
|
||||
|
||||
devShell."x86_64-linux" =
|
||||
(build "x86_64-linux" "x86_64-unknown-linux-gnu").shell;
|
||||
|
||||
packages."aarch64-darwin"."aarch64-apple-darwin" =
|
||||
(build "aarch64-darwin" "aarch64-apple-darwin").bin;
|
||||
|
||||
packages."aarch64-linux"."aarch64-unknown-linux-musl" =
|
||||
(build "aarch64-linux" "aarch64-unknown-linux-musl").bin;
|
||||
|
||||
packages."x86_64-darwin"."x86_64-apple-darwin" =
|
||||
(build "x86_64-darwin" "x86_64-apple-darwin").bin;
|
||||
|
||||
packages."x86_64-linux"."aarch64-unknown-linux-musl" =
|
||||
(build "x86_64-linux" "aarch64-unknown-linux-musl").bin;
|
||||
packages."x86_64-linux"."x86_64-unknown-linux-gnu" =
|
||||
(build "x86_64-linux" "x86_64-unknown-linux-gnu").bin;
|
||||
packages."x86_64-linux"."x86_64-unknown-linux-musl" =
|
||||
(build "x86_64-linux" "x86_64-unknown-linux-musl").bin;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue