may the flake do it's job
This commit is contained in:
parent
7e1aaf7eee
commit
7b506195cc
6 changed files with 248 additions and 70 deletions
129
flake.nix
129
flake.nix
|
|
@ -1,27 +1,118 @@
|
|||
{
|
||||
# Build Pyo3 package
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
systems.url = "github:nix-systems/default";
|
||||
fix-py.url = "github:GuillaumeDesforges/fix-python";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
crane.url = "github:ipetkov/crane";
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ nixpkgs, fix-py, ... }:
|
||||
let
|
||||
eachSystem =
|
||||
f:
|
||||
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
|
||||
in
|
||||
{
|
||||
devShells = eachSystem (pkgs: {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgs.cargo
|
||||
pkgs.rustc
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
fix-py.packages.${pkgs.system}.default
|
||||
inputs:
|
||||
inputs.flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import inputs.nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ inputs.rust-overlay.overlays.default ];
|
||||
};
|
||||
lib = pkgs.lib;
|
||||
|
||||
python_version = pkgs.python313;
|
||||
wheel_tail = "cp313-cp313-linux_x86_64"; # Change if python_version changes
|
||||
|
||||
# Get a custom rust toolchain
|
||||
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
|
||||
p: inputs.fenix.packages.${system}.complete.toolchain
|
||||
);
|
||||
|
||||
project_name = (craneLib.crateNameFromCargoToml { cargoToml = ./game/Cargo.toml; }).pname;
|
||||
project_version = (craneLib.crateNameFromCargoToml { cargoToml = ./game/Cargo.toml; }).version;
|
||||
|
||||
crate_cfg = {
|
||||
src =
|
||||
let
|
||||
fs = lib.fileset;
|
||||
in
|
||||
fs.toSource {
|
||||
root = ./game;
|
||||
fileset = fs.unions [
|
||||
./game/src/lib.rs
|
||||
./game/Cargo.lock
|
||||
./game/Cargo.toml
|
||||
./game/pyproject.toml
|
||||
];
|
||||
};
|
||||
nativeBuildInputs = [ python_version ];
|
||||
# doCheck = true;
|
||||
# buildInputs = [];
|
||||
};
|
||||
|
||||
crate_artifacts = craneLib.buildDepsOnly (
|
||||
crate_cfg
|
||||
// {
|
||||
pname = "${project_name}-artifacts";
|
||||
version = project_version;
|
||||
}
|
||||
);
|
||||
|
||||
# Build the library, then re-use the target dir to generate the wheel file with maturin
|
||||
crate_wheel =
|
||||
(craneLib.buildPackage (
|
||||
crate_cfg
|
||||
// {
|
||||
pname = project_name;
|
||||
version = project_version;
|
||||
cargoArtifacts = crate_artifacts;
|
||||
}
|
||||
)).overrideAttrs
|
||||
(old: {
|
||||
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.maturin ];
|
||||
buildPhase = old.buildPhase + ''
|
||||
maturin build --offline --target-dir ./target
|
||||
'';
|
||||
installPhase = old.installPhase + ''
|
||||
cp target/wheels/${project_name}-${project_version}-${wheel_tail}.whl $out/
|
||||
'';
|
||||
});
|
||||
in
|
||||
rec {
|
||||
packages = {
|
||||
default = crate_wheel; # The wheel itself
|
||||
|
||||
# A python version with the library installed
|
||||
pythonpkg = python_version.withPackages (ps: [
|
||||
(lib.python_package ps)
|
||||
]);
|
||||
};
|
||||
devShells.default = craneLib.devShell {
|
||||
packages = [
|
||||
(pkgs.python3.withPackages (ppkgs: [
|
||||
ppkgs.torch
|
||||
(lib.python_package ppkgs)
|
||||
]))
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
lib = {
|
||||
# To use in other builds with the "withPackages" call
|
||||
python_package =
|
||||
ps:
|
||||
ps.buildPythonPackage rec {
|
||||
pname = project_name;
|
||||
format = "wheel";
|
||||
version = project_version;
|
||||
src = "${crate_wheel}/${project_name}-${project_version}-${wheel_tail}.whl";
|
||||
doCheck = false;
|
||||
pythonImportsCheck = [ project_name ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue