2021-10-07 21:49:13 +08:00
|
|
|
{
|
|
|
|
description = "The third-generation ARTIQ compiler";
|
|
|
|
|
2023-11-01 15:53:47 +08:00
|
|
|
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable;
|
2021-10-07 21:49:13 +08:00
|
|
|
|
2022-04-19 10:34:55 +08:00
|
|
|
outputs = { self, nixpkgs }:
|
2021-10-07 21:49:13 +08:00
|
|
|
let
|
2021-12-08 16:55:25 +08:00
|
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
2021-10-08 08:18:42 +08:00
|
|
|
in rec {
|
2021-12-08 16:55:25 +08:00
|
|
|
packages.x86_64-linux = rec {
|
2022-03-26 15:13:43 +08:00
|
|
|
llvm-nac3 = pkgs.callPackage ./nix/llvm {};
|
2023-11-25 20:15:29 +08:00
|
|
|
llvm-tools-irrt = pkgs.runCommandNoCC "llvm-tools-irrt" {}
|
|
|
|
''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${pkgs.llvmPackages_14.clang-unwrapped}/bin/clang $out/bin/clang-irrt
|
|
|
|
ln -s ${pkgs.llvmPackages_14.llvm.out}/bin/llvm-as $out/bin/llvm-as-irrt
|
|
|
|
'';
|
2021-10-07 21:49:13 +08:00
|
|
|
nac3artiq = pkgs.python3Packages.toPythonModule (
|
2022-04-18 18:47:20 +08:00
|
|
|
pkgs.rustPlatform.buildRustPackage rec {
|
2021-10-07 21:49:13 +08:00
|
|
|
name = "nac3artiq";
|
2022-01-23 11:32:32 +08:00
|
|
|
outputs = [ "out" "runkernel" "standalone" ];
|
2021-10-07 21:49:13 +08:00
|
|
|
src = self;
|
2022-04-18 18:47:20 +08:00
|
|
|
cargoLock = {
|
|
|
|
lockFile = ./Cargo.lock;
|
|
|
|
};
|
|
|
|
passthru.cargoLock = cargoLock;
|
2023-11-25 20:15:29 +08:00
|
|
|
nativeBuildInputs = [ pkgs.python3 pkgs.llvmPackages_14.clang llvm-tools-irrt pkgs.llvmPackages_14.llvm.out llvm-nac3 ];
|
2021-12-08 17:41:34 +08:00
|
|
|
buildInputs = [ pkgs.python3 llvm-nac3 ];
|
2023-10-09 16:56:33 +08:00
|
|
|
checkInputs = [ (pkgs.python3.withPackages(ps: [ ps.numpy ps.scipy ])) ];
|
2022-01-23 11:32:32 +08:00
|
|
|
checkPhase =
|
|
|
|
''
|
|
|
|
echo "Checking nac3standalone demos..."
|
|
|
|
pushd nac3standalone/demo
|
|
|
|
patchShebangs .
|
|
|
|
./check_demos.sh
|
|
|
|
popd
|
|
|
|
echo "Running Cargo tests..."
|
|
|
|
cargoCheckHook
|
|
|
|
'';
|
2021-10-07 21:49:13 +08:00
|
|
|
installPhase =
|
|
|
|
''
|
2022-01-23 11:32:32 +08:00
|
|
|
PYTHON_SITEPACKAGES=$out/${pkgs.python3Packages.python.sitePackages}
|
|
|
|
mkdir -p $PYTHON_SITEPACKAGES
|
|
|
|
cp target/x86_64-unknown-linux-gnu/release/libnac3artiq.so $PYTHON_SITEPACKAGES/nac3artiq.so
|
|
|
|
|
|
|
|
mkdir -p $runkernel/bin
|
|
|
|
cp target/x86_64-unknown-linux-gnu/release/runkernel $runkernel/bin
|
|
|
|
|
|
|
|
mkdir -p $standalone/bin
|
|
|
|
cp target/x86_64-unknown-linux-gnu/release/nac3standalone $standalone/bin
|
2021-10-07 21:49:13 +08:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
2022-01-04 21:52:26 +08:00
|
|
|
python3-mimalloc = pkgs.python3 // rec {
|
|
|
|
withMimalloc = pkgs.python3.buildEnv.override({ makeWrapperArgs = [ "--set LD_PRELOAD ${pkgs.mimalloc}/lib/libmimalloc.so" ]; });
|
|
|
|
withPackages = f: let packages = f pkgs.python3.pkgs; in withMimalloc.override { extraLibs = packages; };
|
|
|
|
};
|
2021-12-26 21:11:14 +08:00
|
|
|
|
|
|
|
# LLVM PGO support
|
2022-03-26 15:13:43 +08:00
|
|
|
llvm-nac3-instrumented = pkgs.callPackage ./nix/llvm {
|
2022-05-24 11:10:29 +08:00
|
|
|
stdenv = pkgs.llvmPackages_14.stdenv;
|
2021-12-26 21:11:14 +08:00
|
|
|
extraCmakeFlags = [ "-DLLVM_BUILD_INSTRUMENTED=IR" ];
|
|
|
|
};
|
|
|
|
nac3artiq-instrumented = pkgs.python3Packages.toPythonModule (
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq-instrumented";
|
|
|
|
src = self;
|
2022-04-18 18:47:20 +08:00
|
|
|
inherit (nac3artiq) cargoLock;
|
2023-11-25 20:15:29 +08:00
|
|
|
nativeBuildInputs = [ pkgs.python3 packages.x86_64-linux.llvm-tools-irrt llvm-nac3-instrumented ];
|
2021-12-26 21:11:14 +08:00
|
|
|
buildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
|
|
|
|
cargoBuildFlags = [ "--package" "nac3artiq" "--features" "init-llvm-profile" ];
|
|
|
|
doCheck = false;
|
|
|
|
configurePhase =
|
|
|
|
''
|
2022-05-24 11:10:29 +08:00
|
|
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=-L${pkgs.llvmPackages_14.compiler-rt}/lib/linux -C link-arg=-lclang_rt.profile-x86_64"
|
2021-12-26 21:11:14 +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
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
nac3artiq-profile = pkgs.stdenvNoCC.mkDerivation {
|
|
|
|
name = "nac3artiq-profile";
|
2022-04-19 10:34:55 +08:00
|
|
|
srcs = [
|
|
|
|
(pkgs.fetchFromGitHub {
|
|
|
|
owner = "m-labs";
|
|
|
|
repo = "sipyco";
|
|
|
|
rev = "939f84f9b5eef7efbf7423c735d1834783b6140e";
|
|
|
|
sha256 = "sha256-15Nun4EY35j+6SPZkjzZtyH/ncxLS60KuGJjFh5kSTc=";
|
|
|
|
})
|
|
|
|
(pkgs.fetchFromGitHub {
|
|
|
|
owner = "m-labs";
|
|
|
|
repo = "artiq";
|
2023-11-11 11:10:58 +08:00
|
|
|
rev = "5bbac04bef170cddb608b5dc8d9e6778cc7b31e8";
|
|
|
|
sha256 = "sha256-TnRS2NrQaDiDzUsmfjkZh69xi2XC9v+4hnkedycAo0k=";
|
2022-04-19 10:34:55 +08:00
|
|
|
})
|
|
|
|
];
|
2022-04-18 23:57:57 +08:00
|
|
|
buildInputs = [
|
2023-11-08 17:29:29 +08:00
|
|
|
(python3-mimalloc.withPackages(ps: [ ps.numpy ps.scipy ps.jsonschema ps.lmdb nac3artiq-instrumented ]))
|
2022-05-24 11:10:29 +08:00
|
|
|
pkgs.llvmPackages_14.llvm.out
|
2022-04-18 23:57:57 +08:00
|
|
|
];
|
2021-12-26 21:11:14 +08:00
|
|
|
phases = [ "buildPhase" "installPhase" ];
|
2022-04-18 23:57:57 +08:00
|
|
|
buildPhase =
|
|
|
|
''
|
2022-04-19 10:34:55 +08:00
|
|
|
srcs=($srcs)
|
|
|
|
sipyco=''${srcs[0]}
|
|
|
|
artiq=''${srcs[1]}
|
|
|
|
export PYTHONPATH=$sipyco:$artiq
|
|
|
|
python -m artiq.frontend.artiq_ddb_template $artiq/artiq/examples/nac3devices/nac3devices.json > device_db.py
|
|
|
|
cp $artiq/artiq/examples/nac3devices/nac3devices.py .
|
2022-04-18 23:57:57 +08:00
|
|
|
python -m artiq.frontend.artiq_compile nac3devices.py
|
|
|
|
'';
|
2021-12-26 21:11:14 +08:00
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
llvm-profdata merge -o $out/llvm.profdata /build/llvm/build/profiles/*
|
|
|
|
'';
|
|
|
|
};
|
2022-03-26 15:13:43 +08:00
|
|
|
llvm-nac3-pgo = pkgs.callPackage ./nix/llvm {
|
2022-05-24 11:10:29 +08:00
|
|
|
stdenv = pkgs.llvmPackages_14.stdenv;
|
2021-12-26 21:11:14 +08:00
|
|
|
extraCmakeFlags = [ "-DLLVM_PROFDATA_FILE=${nac3artiq-profile}/llvm.profdata" ];
|
|
|
|
};
|
|
|
|
nac3artiq-pgo = pkgs.python3Packages.toPythonModule (
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq-pgo";
|
|
|
|
src = self;
|
2022-04-18 18:47:20 +08:00
|
|
|
inherit (nac3artiq) cargoLock;
|
2023-11-25 20:15:29 +08:00
|
|
|
nativeBuildInputs = [ pkgs.python3 packages.x86_64-linux.llvm-tools-irrt llvm-nac3-pgo ];
|
2021-12-26 21:11:14 +08:00
|
|
|
buildInputs = [ pkgs.python3 llvm-nac3-pgo ];
|
|
|
|
cargoBuildFlags = [ "--package" "nac3artiq" ];
|
|
|
|
cargoTestFlags = [ "--package" "nac3ast" "--package" "nac3parser" "--package" "nac3core" "--package" "nac3artiq" ];
|
|
|
|
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-10-07 21:49:13 +08:00
|
|
|
};
|
|
|
|
|
2022-03-26 15:13:43 +08:00
|
|
|
packages.x86_64-w64-mingw32 = import ./nix/windows { inherit pkgs; };
|
2021-11-26 17:26:18 +08:00
|
|
|
|
2023-05-30 16:28:46 +08:00
|
|
|
devShells.x86_64-linux.default = pkgs.mkShell {
|
2021-10-07 21:49:13 +08:00
|
|
|
name = "nac3-dev-shell";
|
2021-12-05 14:35:27 +08:00
|
|
|
buildInputs = with pkgs; [
|
2022-01-09 11:30:36 +08:00
|
|
|
# build dependencies
|
2021-12-08 16:55:25 +08:00
|
|
|
packages.x86_64-linux.llvm-nac3
|
2023-09-25 15:38:33 +08:00
|
|
|
llvmPackages_14.clang # demo
|
2023-11-25 20:15:29 +08:00
|
|
|
packages.x86_64-linux.llvm-tools-irrt
|
2021-10-07 21:49:13 +08:00
|
|
|
cargo
|
|
|
|
rustc
|
2022-01-09 11:30:36 +08:00
|
|
|
# runtime dependencies
|
2022-06-06 17:50:32 +08:00
|
|
|
lld_14 # for running kernels on the host
|
2023-10-09 16:56:33 +08:00
|
|
|
(packages.x86_64-linux.python3-mimalloc.withPackages(ps: [ ps.numpy ps.scipy ]))
|
2022-01-09 11:30:36 +08:00
|
|
|
# development tools
|
|
|
|
cargo-insta
|
|
|
|
clippy
|
|
|
|
rustfmt
|
2022-03-22 22:14:46 +08:00
|
|
|
];
|
|
|
|
};
|
|
|
|
devShells.x86_64-linux.msys2 = pkgs.mkShell {
|
2022-03-26 15:15:39 +08:00
|
|
|
name = "nac3-dev-shell-msys2";
|
2022-03-22 22:14:46 +08:00
|
|
|
buildInputs = with pkgs; [
|
2022-03-22 18:03:25 +08:00
|
|
|
curl
|
|
|
|
pacman
|
|
|
|
fakeroot
|
2022-03-22 22:14:46 +08:00
|
|
|
packages.x86_64-w64-mingw32.wine-msys2
|
2021-10-07 21:49:13 +08:00
|
|
|
];
|
|
|
|
};
|
2021-10-08 08:18:42 +08:00
|
|
|
|
|
|
|
hydraJobs = {
|
2022-04-18 23:58:43 +08:00
|
|
|
inherit (packages.x86_64-linux) llvm-nac3 nac3artiq nac3artiq-pgo;
|
2022-03-22 18:03:25 +08:00
|
|
|
llvm-nac3-msys2 = packages.x86_64-w64-mingw32.llvm-nac3;
|
2022-03-22 19:19:06 +08:00
|
|
|
nac3artiq-msys2 = packages.x86_64-w64-mingw32.nac3artiq;
|
2022-04-04 14:24:47 +08:00
|
|
|
nac3artiq-msys2-pkg = packages.x86_64-w64-mingw32.nac3artiq-pkg;
|
2021-12-08 17:43:05 +08:00
|
|
|
};
|
2021-10-07 21:49:13 +08:00
|
|
|
};
|
2021-11-11 22:46:48 +08:00
|
|
|
|
|
|
|
nixConfig = {
|
2022-04-14 04:21:18 +08:00
|
|
|
extra-trusted-public-keys = "nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc=";
|
|
|
|
extra-substituters = "https://nixbld.m-labs.hk";
|
2021-11-11 22:46:48 +08:00
|
|
|
};
|
2021-10-07 21:49:13 +08:00
|
|
|
}
|