alejandra (#9)

* alejandra
* update GH workflow
This commit is contained in:
Jens K. 2024-12-04 13:41:09 +01:00 committed by GitHub
parent 634884d483
commit 6e6217bd21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 76 additions and 59 deletions

View File

@ -17,8 +17,8 @@ jobs:
run: nix develop --command cargo fmt --all -- --check run: nix develop --command cargo fmt --all -- --check
- name: Run clippy - name: Run clippy
run: nix develop --command cargo clippy -- -D warnings run: nix develop --command cargo clippy -- -D warnings
- name: Run tests - name: Run alejandra
run: nix develop --command cargo test run: nix develop --command alejandra --check flake.nix
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -13,5 +13,18 @@
} }
} }
} }
},
"languages": {
"Nix": {
"formatter": {
"external": {
"command": "alejandra",
"arguments": [
"-q"
]
}
},
"format_on_save": "on"
}
} }
} }

118
flake.nix
View File

@ -11,77 +11,81 @@
}; };
}; };
outputs = { nixpkgs, flake-utils, fenix, crane, ... }: outputs = {
flake-utils.lib.eachDefaultSystem (system: nixpkgs,
let flake-utils,
pkgs = nixpkgs.legacyPackages.${system}; fenix,
# Using stable toolchain as base crane,
toolchain = with fenix.packages.${system}; ...
combine [ }:
minimal.rustc flake-utils.lib.eachDefaultSystem (system: let
minimal.cargo pkgs = nixpkgs.legacyPackages.${system};
targets.x86_64-pc-windows-gnu.latest.rust-std # Using stable toolchain as base
toolchain = with fenix.packages.${system};
combine [
minimal.rustc
minimal.cargo
targets.x86_64-pc-windows-gnu.latest.rust-std
]; ];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
# Common build inputs for both native and cross compilation # Common build inputs for both native and cross compilation
commonArgs = { commonArgs = {
src = craneLib.cleanCargoSource ./.;
cargoArtifacts = craneLib.buildDepsOnly {
src = craneLib.cleanCargoSource ./.; src = craneLib.cleanCargoSource ./.;
cargoArtifacts = craneLib.buildDepsOnly {
src = craneLib.cleanCargoSource ./.;
};
doCheck = false; # skip tests during nix build
}; };
doCheck = false; # skip tests during nix build
};
# Native build # Native build
timr = craneLib.buildPackage commonArgs; timr = craneLib.buildPackage commonArgs;
# Windows cross-compilation build # Windows cross-compilation build
# @see https://crane.dev/examples/cross-windows.html # @see https://crane.dev/examples/cross-windows.html
crossBuild = craneLib.buildPackage { crossBuild = craneLib.buildPackage {
src = craneLib.cleanCargoSource ./.; src = craneLib.cleanCargoSource ./.;
strictDeps = true; strictDeps = true;
doCheck = false; doCheck = false;
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
# fixes issues related to libring # fixes issues related to libring
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc"; TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
#fixes issues related to openssl #fixes issues related to openssl
OPENSSL_DIR = "${pkgs.openssl.dev}"; OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib"; OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include/"; OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include/";
depsBuildBuild = with pkgs; [ depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads pkgsCross.mingwW64.windows.pthreads
];
};
in {
packages = {
inherit timr;
default = timr;
windows = crossBuild;
};
# Development shell with all necessary tools
devShell = with nixpkgs.legacyPackages.${system};
mkShell {
buildInputs = with fenix.packages.${system}.stable; [
rust-analyzer
clippy
rustfmt
toolchain
pkgs.just
pkgs.nixd
pkgs.alejandra
]; ];
};
in
{
packages = {
inherit timr;
default = timr;
windows = crossBuild;
};
# Development shell with all necessary tools
devShell = with nixpkgs.legacyPackages.${system}; mkShell {
buildInputs = with fenix.packages.${system}.stable; [
rust-analyzer
clippy
rustfmt
toolchain
pkgs.just
];
inherit (commonArgs) src; inherit (commonArgs) src;
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
}; };
}); });
} }