191 lines
5.9 KiB
Nix
191 lines
5.9 KiB
Nix
{
|
|
description = "A Bevy engine flake for building and testing Rust projects with Bevy on Linux and MacOS.";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
crane.url = "github:ipetkov/crane";
|
|
nix-github-actions = {
|
|
url = "github:nix-community/nix-github-actions";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
advisory-db = {
|
|
url = "github:rustsec/advisory-db";
|
|
flake = false;
|
|
};
|
|
crates-io-index = {
|
|
url = "git+https://github.com/rust-lang/crates.io-index?shallow=1";
|
|
flake = false;
|
|
};
|
|
crates-nix = {
|
|
url = "github:uttarayan21/crates.nix";
|
|
inputs.crates-io-index.follows = "crates-io-index";
|
|
};
|
|
};
|
|
|
|
outputs = {
|
|
self,
|
|
crane,
|
|
flake-utils,
|
|
nixpkgs,
|
|
rust-overlay,
|
|
advisory-db,
|
|
nix-github-actions,
|
|
crates-nix,
|
|
...
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system: let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [
|
|
rust-overlay.overlays.default
|
|
];
|
|
};
|
|
inherit (pkgs) lib;
|
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
|
name = cargoToml.package.name;
|
|
|
|
toolchain = pkgs.rust-bin.stable.latest.default.override {
|
|
targets = ["wasm32-unknown-unknown"];
|
|
};
|
|
toolchainWithLLvmTools = toolchain.override {
|
|
extensions = ["rust-src" "llvm-tools"];
|
|
};
|
|
toolchainWithRustAnalyzer = toolchain.override {
|
|
extensions = ["rust-src" "rust-analyzer"];
|
|
};
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
|
craneLibLLvmTools = (crane.mkLib pkgs).overrideToolchain toolchainWithLLvmTools;
|
|
|
|
crates = crates-nix.mkLib {inherit pkgs;};
|
|
lockedCrateVersion = crateName: lockFile: ((builtins.elemAt (builtins.filter (item: item.name == crateName) (builtins.fromTOML (builtins.readFile lockFile)).package)) 0).version;
|
|
|
|
src = let
|
|
filterBySuffix = path: exts: lib.any (ext: lib.hasSuffix ext path) exts;
|
|
sourceFilters = path: type:
|
|
(craneLib.filterCargoSources path type)
|
|
|| filterBySuffix path [".html"];
|
|
in
|
|
lib.cleanSourceWith {
|
|
filter = sourceFilters;
|
|
src = ./.;
|
|
};
|
|
commonArgs = rec {
|
|
inherit src;
|
|
pname = name;
|
|
stdenv = p: p.clangStdenv;
|
|
doCheck = false;
|
|
nativeBuildInputs = with pkgs; [
|
|
pkg-config
|
|
];
|
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
|
|
|
buildInputs = with pkgs;
|
|
[
|
|
vulkan-loader
|
|
]
|
|
++ (lib.optionals pkgs.stdenv.isLinux [
|
|
alsa-lib-with-plugins
|
|
libxkbcommon
|
|
udev
|
|
wayland
|
|
])
|
|
++ (lib.optionals pkgs.stdenv.isDarwin [
|
|
libiconv
|
|
apple-sdk_26
|
|
]);
|
|
wasm-bindgen-cli = crates.buildCrate "wasm-bindgen-cli" {
|
|
version = lockedCrateVersion "wasm-bindgen" ./Cargo.lock;
|
|
};
|
|
};
|
|
cargoArtifacts = craneLib.buildTrunkPackage commonArgs;
|
|
in {
|
|
checks =
|
|
{
|
|
"${name}-clippy" = craneLib.cargoClippy (commonArgs
|
|
// {
|
|
inherit cargoArtifacts;
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
});
|
|
"${name}-docs" = craneLib.cargoDoc (commonArgs // {inherit cargoArtifacts;});
|
|
"${name}-fmt" = craneLib.cargoFmt {inherit src;};
|
|
"${name}-toml-fmt" = craneLib.taploFmt {
|
|
src = pkgs.lib.sources.sourceFilesBySuffices src [".toml"];
|
|
};
|
|
# Audit dependencies
|
|
"${name}-audit" = craneLib.cargoAudit {
|
|
inherit src advisory-db;
|
|
};
|
|
|
|
# Audit licenses
|
|
"${name}-deny" = craneLib.cargoDeny {
|
|
inherit src;
|
|
};
|
|
"${name}-nextest" = craneLib.cargoNextest (commonArgs
|
|
// {
|
|
inherit cargoArtifacts;
|
|
partitions = 1;
|
|
partitionType = "count";
|
|
});
|
|
}
|
|
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
|
|
"${name}-llvm-cov" = craneLibLLvmTools.cargoLlvmCov (commonArgs // {inherit cargoArtifacts;});
|
|
};
|
|
|
|
packages = let
|
|
pkg = craneLib.buildTrunkPackage (
|
|
commonArgs
|
|
// {inherit cargoArtifacts;}
|
|
);
|
|
in {
|
|
"${name}" = pkg;
|
|
default = pkg;
|
|
};
|
|
|
|
devShells = {
|
|
default =
|
|
pkgs.mkShell.override {
|
|
stdenv = pkgs.clangStdenv;
|
|
# stdenv =
|
|
# if pkgs.stdenv.isLinux
|
|
# then (pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv)
|
|
# else pkgs.clangStdenv;
|
|
} (commonArgs
|
|
// {
|
|
packages = with pkgs;
|
|
[
|
|
toolchainWithRustAnalyzer
|
|
cargo-nextest
|
|
cargo-deny
|
|
cargo-expand
|
|
bacon
|
|
cargo-make
|
|
cargo-hack
|
|
cargo-outdated
|
|
lld
|
|
trunk
|
|
binaryen
|
|
neocities
|
|
]
|
|
++ (lib.optionals pkgs.stdenv.isDarwin [
|
|
apple-sdk_26
|
|
])
|
|
++ (lib.optionals pkgs.stdenv.isLinux [
|
|
mold
|
|
]);
|
|
});
|
|
};
|
|
}
|
|
)
|
|
// {
|
|
githubActions = nix-github-actions.lib.mkGithubMatrix {
|
|
checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.checks;
|
|
};
|
|
};
|
|
}
|