nac3/flake.nix

104 lines
3.9 KiB
Nix
Raw Normal View History

2021-10-07 21:49:13 +08:00
{
description = "The third-generation ARTIQ compiler";
inputs.nixpkgs.url = github:NixOS/nixpkgs/0f4b4b85d959200f52c16bbb74036994e7db5f74;
2021-10-07 21:49:13 +08:00
outputs = { self, nixpkgs }:
let
# We can't use overlays because llvm dependencies are handled internally in llvmPackages_xx
pkgs-orig = import nixpkgs { system = "x86_64-linux"; };
nixpkgs-patched = pkgs-orig.applyPatches {
name = "nixpkgs";
src = nixpkgs;
patches = [ ./llvm-future-riscv-abi.diff ./llvm-restrict-targets.diff ./llvm-mingw-crosscompile.diff ];
};
pkgs = import nixpkgs-patched { system = "x86_64-linux"; };
2021-11-26 17:26:18 +08:00
pkgs-mingw = import nixpkgs-patched { system = "x86_64-linux"; crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; }; };
cargoSha256 = "sha256-otKLhr58HYMjVXAof6AdObNpggPnvK6qOl7I+4LWIP8=";
msys2-python-tar = pkgs.fetchurl {
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.9.7-4-any.pkg.tar.zst";
sha256 = "0iwlgbk4b457yn9djwqswid55xhyyi35qymz1lfh42xwdpxdm47c";
};
msys2-python = pkgs.runCommand "msys2-python" { buildInputs = [ pkgs.gnutar pkgs.zstd ]; }
''
mkdir $out
tar xvf ${msys2-python-tar} -C $out
'';
2021-10-08 08:18:42 +08:00
in rec {
2021-11-12 14:57:46 +08:00
inherit nixpkgs-patched;
2021-10-07 21:49:13 +08:00
packages.x86_64-linux = {
nac3artiq = pkgs.python3Packages.toPythonModule (
pkgs.rustPlatform.buildRustPackage {
name = "nac3artiq";
src = self;
2021-11-26 17:26:18 +08:00
inherit cargoSha256;
2021-11-02 14:00:20 +08:00
nativeBuildInputs = [ pkgs.python3 pkgs.llvm_12 ];
buildInputs = [ pkgs.python3 pkgs.libffi pkgs.libxml2 pkgs.llvm_12 ];
2021-10-07 21:49:13 +08:00
cargoBuildFlags = [ "--package" "nac3artiq" ];
2021-11-03 17:39:48 +08:00
cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ];
2021-10-07 21:49:13 +08:00
installPhase =
''
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}
mkdir -p $TARGET_DIR
cp target/x86_64-unknown-linux-gnu/release/libnac3artiq.so $TARGET_DIR/nac3artiq.so
'';
}
);
};
2021-11-26 17:26:18 +08:00
packages.x86_64-w64-mingw32 = {
nac3artiq = pkgs-mingw.python3Packages.toPythonModule (
pkgs-mingw.rustPlatform.buildRustPackage {
name = "nac3artiq";
src = self;
inherit cargoSha256;
nativeBuildInputs = [ pkgs-mingw.llvm_12 ];
buildInputs = [ pkgs-mingw.libffi pkgs-mingw.libxml2 pkgs-mingw.llvm_12 ];
configurePhase =
''
export PYO3_CROSS_PYTHON_VERSION=3.9
export PYO3_CROSS_LIB_DIR=${msys2-python}/mingw64/lib
echo Using Python $PYO3_CROSS_PYTHON_VERSION in $PYO3_CROSS_LIB_DIR
'';
cargoBuildFlags = [ "--package" "nac3artiq" ];
doCheck = false;
installPhase =
''
TARGET_DIR=$out/${pkgs.python3Packages.python.sitePackages}
mkdir -p $TARGET_DIR
#cp target/x86_64-unknown-linux-gnu/release/libnac3artiq.so $TARGET_DIR/nac3artiq.so
ls target
'';
meta.platforms = ["x86_64-windows"];
}
);
};
2021-10-07 21:49:13 +08:00
devShell.x86_64-linux = pkgs.mkShell {
name = "nac3-dev-shell";
buildInputs = with pkgs; [
2021-11-02 14:00:20 +08:00
llvm_12
clang_12
lld_12
2021-10-07 21:49:13 +08:00
cargo
2021-11-02 18:13:59 +08:00
cargo-insta
2021-10-07 21:49:13 +08:00
rustc
libffi
libxml2
clippy
(python3.withPackages(ps: [ ps.numpy ]))
];
};
2021-10-08 08:18:42 +08:00
hydraJobs = {
inherit (packages.x86_64-linux) nac3artiq;
2021-11-12 15:47:21 +08:00
} // (pkgs.lib.foldr (a: b: {"${pkgs.lib.strings.getName a}" = a;} // b) {} devShell.x86_64-linux.buildInputs);
2021-10-07 21:49:13 +08:00
};
nixConfig = {
binaryCachePublicKeys = ["nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc="];
binaryCaches = ["https://nixbld.m-labs.hk" "https://cache.nixos.org"];
};
2021-10-07 21:49:13 +08:00
}