2021-10-07 21:49:13 +08:00
|
|
|
{
|
|
|
|
description = "The third-generation ARTIQ compiler";
|
|
|
|
|
2021-12-08 21:21:37 +08:00
|
|
|
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
|
2021-10-07 21:49:13 +08:00
|
|
|
|
|
|
|
outputs = { self, nixpkgs }:
|
|
|
|
let
|
2021-12-08 16:55:25 +08:00
|
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
2021-12-08 21:21:37 +08:00
|
|
|
pkgs-mingw = import nixpkgs {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; };
|
|
|
|
# work around https://github.com/NixOS/nixpkgs/issues/149593
|
|
|
|
overlays = [
|
|
|
|
(self: super: {
|
|
|
|
openssh = super.openssh.overrideAttrs(oa: { doCheck = false; });
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
2021-11-26 17:26:18 +08:00
|
|
|
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";
|
|
|
|
};
|
2021-12-02 22:37:32 +08:00
|
|
|
msys2-python = pkgs.stdenvNoCC.mkDerivation {
|
|
|
|
name = "msys2-python";
|
|
|
|
src = msys2-python-tar;
|
|
|
|
buildInputs = [ pkgs.gnutar pkgs.zstd ];
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
tar xf $src -C $out
|
|
|
|
'';
|
|
|
|
};
|
2021-12-01 18:30:26 +08:00
|
|
|
pyo3-mingw-config = pkgs.writeTextFile {
|
|
|
|
name = "pyo3-mingw-config";
|
|
|
|
text =
|
|
|
|
''
|
|
|
|
implementation=CPython
|
|
|
|
version=3.9
|
|
|
|
shared=true
|
|
|
|
abi3=false
|
|
|
|
lib_name=python3.9
|
|
|
|
lib_dir=${msys2-python}/mingw64/lib
|
|
|
|
pointer_width=64
|
|
|
|
build_flags=WITH_THREAD
|
|
|
|
suppress_build_script_link_lines=false
|
|
|
|
'';
|
|
|
|
};
|
2021-10-08 08:18:42 +08:00
|
|
|
in rec {
|
2021-12-08 16:55:25 +08:00
|
|
|
packages.x86_64-linux = rec {
|
|
|
|
llvm-nac3 = pkgs.callPackage "${self}/llvm" {};
|
2021-10-07 21:49:13 +08:00
|
|
|
nac3artiq = pkgs.python3Packages.toPythonModule (
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq";
|
|
|
|
src = self;
|
2021-12-26 18:57:02 +08:00
|
|
|
cargoLock = { lockFile = ./Cargo.lock; };
|
2021-12-08 16:55:25 +08:00
|
|
|
nativeBuildInputs = [ pkgs.python3 llvm-nac3 ];
|
2021-12-08 17:41:34 +08:00
|
|
|
buildInputs = [ pkgs.python3 llvm-nac3 ];
|
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
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
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
|
|
|
|
llvm-nac3-instrumented = pkgs.callPackage "${self}/llvm" {
|
|
|
|
stdenv = pkgs.llvmPackages_13.stdenv;
|
|
|
|
extraCmakeFlags = [ "-DLLVM_BUILD_INSTRUMENTED=IR" ];
|
|
|
|
};
|
|
|
|
nac3artiq-instrumented = pkgs.python3Packages.toPythonModule (
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq-instrumented";
|
|
|
|
src = self;
|
|
|
|
cargoLock = { lockFile = ./Cargo.lock; };
|
|
|
|
nativeBuildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
|
|
|
|
buildInputs = [ pkgs.python3 llvm-nac3-instrumented ];
|
|
|
|
cargoBuildFlags = [ "--package" "nac3artiq" "--features" "init-llvm-profile" ];
|
|
|
|
doCheck = false;
|
|
|
|
configurePhase =
|
|
|
|
''
|
|
|
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=-L${pkgs.llvmPackages_13.compiler-rt}/lib/linux -C link-arg=-lclang_rt.profile-x86_64"
|
|
|
|
'';
|
|
|
|
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";
|
|
|
|
src = self;
|
2022-01-04 21:52:26 +08:00
|
|
|
buildInputs = [ (python3-mimalloc.withPackages(ps: [ ps.numpy nac3artiq-instrumented ])) pkgs.lld_13 pkgs.llvmPackages_13.libllvm ];
|
2021-12-26 21:11:14 +08:00
|
|
|
phases = [ "buildPhase" "installPhase" ];
|
|
|
|
# TODO: get more representative code.
|
|
|
|
buildPhase = "python $src/nac3artiq/demo/demo.py";
|
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
llvm-profdata merge -o $out/llvm.profdata /build/llvm/build/profiles/*
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
llvm-nac3-pgo = pkgs.callPackage "${self}/llvm" {
|
|
|
|
stdenv = pkgs.llvmPackages_13.stdenv;
|
|
|
|
extraCmakeFlags = [ "-DLLVM_PROFDATA_FILE=${nac3artiq-profile}/llvm.profdata" ];
|
|
|
|
};
|
|
|
|
nac3artiq-pgo = pkgs.python3Packages.toPythonModule (
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq-pgo";
|
|
|
|
src = self;
|
|
|
|
cargoLock = { lockFile = ./Cargo.lock; };
|
|
|
|
nativeBuildInputs = [ pkgs.python3 llvm-nac3-pgo ];
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-12-08 16:55:25 +08:00
|
|
|
packages.x86_64-w64-mingw32 = rec {
|
2021-12-25 22:49:47 +08:00
|
|
|
llvm-nac3 = pkgs-mingw.callPackage "${self}/llvm" { inherit (pkgs) llvmPackages_13; };
|
2021-11-26 17:26:18 +08:00
|
|
|
nac3artiq = pkgs-mingw.python3Packages.toPythonModule (
|
|
|
|
pkgs-mingw.rustPlatform.buildRustPackage {
|
|
|
|
name = "nac3artiq";
|
|
|
|
src = self;
|
2021-12-26 18:57:02 +08:00
|
|
|
cargoLock = { lockFile = ./Cargo.lock; };
|
2021-12-02 22:47:31 +08:00
|
|
|
nativeBuildInputs = [ pkgs.zip ];
|
2021-12-08 17:41:34 +08:00
|
|
|
buildInputs = [ pkgs-mingw.zlib ];
|
2021-11-26 17:26:18 +08:00
|
|
|
configurePhase =
|
|
|
|
''
|
2021-12-01 18:30:26 +08:00
|
|
|
export PYO3_CONFIG_FILE=${pyo3-mingw-config}
|
2021-12-02 20:00:45 +08:00
|
|
|
|
2021-12-01 18:30:26 +08:00
|
|
|
mkdir llvm-cfg
|
2021-12-02 20:00:45 +08:00
|
|
|
cat << EOF > llvm-cfg/llvm-config
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
set -e
|
2021-12-02 21:02:48 +08:00
|
|
|
# Gross hack to work around llvm-config asking for the wrong system libraries.
|
2021-12-08 16:55:25 +08:00
|
|
|
exec ${llvm-nac3.dev}/bin/llvm-config-native \$@ | ${pkgs.gnused}/bin/sed s/-lrt\ -ldl\ -lpthread\ -lm//
|
2021-12-02 20:00:45 +08:00
|
|
|
EOF
|
|
|
|
chmod +x llvm-cfg/llvm-config
|
2021-12-01 18:30:26 +08:00
|
|
|
export PATH=$PATH:`pwd`/llvm-cfg
|
2021-12-02 22:01:19 +08:00
|
|
|
|
|
|
|
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS="-C link-arg=-lz -C link-arg=-luuid -C link-arg=-lole32 -C link-arg=-lmcfgthread"
|
2021-11-26 17:26:18 +08:00
|
|
|
'';
|
|
|
|
cargoBuildFlags = [ "--package" "nac3artiq" ];
|
|
|
|
doCheck = false;
|
|
|
|
installPhase =
|
|
|
|
''
|
2021-12-02 22:47:31 +08:00
|
|
|
mkdir -p $out $out/nix-support
|
|
|
|
ln -s target/x86_64-pc-windows-gnu/release/nac3artiq.dll nac3artiq.pyd
|
|
|
|
zip $out/nac3artiq.zip nac3artiq.pyd
|
|
|
|
echo file binary-dist $out/nac3artiq.zip >> $out/nix-support/hydra-build-products
|
2021-11-26 17:26:18 +08:00
|
|
|
'';
|
2021-12-05 14:40:10 +08:00
|
|
|
dontFixup = true;
|
2021-11-26 17:26:18 +08:00
|
|
|
meta.platforms = ["x86_64-windows"];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-05 14:35:27 +08:00
|
|
|
devShell.x86_64-linux = 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; [
|
2021-12-08 16:55:25 +08:00
|
|
|
packages.x86_64-linux.llvm-nac3
|
2022-01-09 10:53:58 +08:00
|
|
|
llvmPackages_13.clang-unwrapped # for IRRT
|
2021-12-26 18:56:23 +08:00
|
|
|
lld_13
|
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
|
|
|
|
clippy
|
2022-01-04 21:52:26 +08:00
|
|
|
(packages.x86_64-linux.python3-mimalloc.withPackages(ps: [ ps.numpy ]))
|
2021-10-07 21:49:13 +08:00
|
|
|
];
|
|
|
|
};
|
2021-10-08 08:18:42 +08:00
|
|
|
|
|
|
|
hydraJobs = {
|
2021-12-08 17:43:05 +08:00
|
|
|
inherit (packages.x86_64-linux) llvm-nac3 nac3artiq;
|
|
|
|
llvm-nac3-mingw = packages.x86_64-w64-mingw32.llvm-nac3;
|
2021-12-02 22:37:41 +08:00
|
|
|
nac3artiq-mingw = packages.x86_64-w64-mingw32.nac3artiq;
|
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 = {
|
|
|
|
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
|
|
|
}
|