riscv support in beta version (WIP)

This commit is contained in:
Sebastien Bourdeauducq 2021-09-12 18:17:47 +08:00
parent 4e00857fe1
commit 54157028c9
25 changed files with 139 additions and 49 deletions

View File

@ -2,25 +2,27 @@
# nix.sandboxPaths = ["/opt"];
{ pkgs
, rustPlatform
, vivado ? import ./vivado.nix { inherit pkgs; }
}:
let
artiqSrc = import ./pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
artiqpkgs = import ./default.nix { inherit pkgs; };
fetchcargo = import ./fetchcargo.nix {
fetchcargo-legacy = import ./fetchcargo-legacy.nix {
inherit (pkgs) stdenv lib cacert git;
inherit (artiqpkgs) cargo cargo-vendor;
cargo = artiqpkgs.cargo-legacy;
cargo-vendor = artiqpkgs.cargo-vendor-legacy;
};
cargoDeps = fetchcargo rec {
cargoDeps-legacy = fetchcargo-legacy rec {
name = "artiq-firmware-cargo-deps";
src = "${artiqSrc}/artiq/firmware";
sha256 = (import "${artiqSrc}/artiq/firmware/cargosha256.nix");
};
cargoVendored = pkgs.stdenv.mkDerivation {
cargoVendored-legacy = pkgs.stdenv.mkDerivation {
name = "artiq-firmware-cargo-vendored";
src = cargoDeps;
src = cargoDeps-legacy;
phases = [ "unpackPhase" "installPhase" ];
installPhase =
''
@ -42,6 +44,26 @@ let
'';
};
cargoDeps = rustPlatform.fetchCargoTarball {
name = "artiq-firmware-cargo-deps";
src = "${artiqSrc}/artiq/firmware";
sha256 = "0hh9x34gs81a8g15abka6a0z1wlankra13rbap5j7ba2r8cz4962";
};
cargo-xbuild = rustPlatform.buildRustPackage rec {
pname = "cargo-xbuild";
version = "0.6.5";
src = pkgs.fetchFromGitHub {
owner = "rust-osdev";
repo = pname;
rev = "v${version}";
sha256 = "18djvygq9v8rmfchvi2hfj0i6fhn36m716vqndqnj56fiqviwxvf";
};
cargoSha256 = "13sj9j9kl6js75h9xq0yidxy63vixxm9q3f8jil6ymarml5wkhx8";
};
artiq7 = pkgs.lib.strings.versionAtLeast artiqpkgs.artiq.version "7.0";
in
{ target
, variant
@ -55,26 +77,44 @@ in
pkgs.python3Packages.toPythonModule (pkgs.stdenv.mkDerivation rec {
name = "artiq-board-${target}-${variant}-${version}";
version = import ./pkgs/artiq-version.nix (with pkgs; { inherit stdenv fetchgit git; });
inherit src;
phases = [ "buildPhase" "installCheckPhase" "installPhase" "checkPhase" ];
nativeBuildInputs = [
vivado
pkgs.gnumake
artiqpkgs.cargo
artiqpkgs.rustc
phases = [ "buildPhase" "checkPhase" "installPhase" ];
nativeBuildInputs = [ vivado pkgs.gnumake ]
++ (if artiq7
then [
rustPlatform.rust.rustc
rustPlatform.rust.cargo
pkgs.llvmPackages_11.clang-unwrapped
pkgs.llvm_11
pkgs.lld_11
rustPlatform.cargoSetupHook
cargo-xbuild
] else [
artiqpkgs.cargo-legacy
artiqpkgs.rustc-legacy
artiqpkgs.binutils-or1k
artiqpkgs.llvm-or1k
];
]);
buildInputs = [ (pkgs.python3.withPackages(ps: with ps; [ jinja2 numpy artiqpkgs.migen artiqpkgs.microscope artiqpkgs.misoc artiqpkgs.jesd204b artiqpkgs.artiq ])) ];
buildPhase =
buildPhase = if artiq7
then
''
export CARGO_HOME=${cargoVendored}
ARTIQ_PATH=`python -c "import artiq; print(artiq.__path__[0])"`
ln -s $ARTIQ_PATH/firmware/Cargo.lock .
cargoDeps=${cargoDeps}
cargoSetupPostUnpackHook
cargoSetupPostPatchHook
export TARGET_AR=llvm-ar
${buildCommand}
''
else
''
export CARGO_HOME=${cargoVendored-legacy}
export TARGET_AR=or1k-linux-ar
${buildCommand}
'';
# temporarily disabled because there is currently always at least one Kasli bitstream
# that fails timing and blocks the conda channel.
doCheck = false;
doCheck = artiq7;
checkPhase = ''
# Search for PCREs in the Vivado output to check for errors
check_log() {

View File

@ -7,8 +7,8 @@ let
inherit version;
src = import ../pkgs/artiq-src.nix { fetchgit = pkgs.fetchgit; };
dependencies = [
"llvmlite-artiq"
"binutils-or1k-linux"
(if (pkgs.lib.strings.versionAtLeast version "7.0") then "llvmlite" else "llvmlite-artiq")
(if (pkgs.lib.strings.versionAtLeast version "7.0") then "llvm-tools" else "binutils-or1k-linux")
"pythonparser"
"scipy"
"numpy"

View File

@ -4,6 +4,24 @@ let
artiq6 = pkgs.lib.strings.versionAtLeast mainPackages.artiq.version "6.0";
artiq7 = pkgs.lib.strings.versionAtLeast mainPackages.artiq.version "7.0";
pythonDeps = import ./pkgs/python-deps.nix { inherit (pkgs) lib fetchgit fetchFromGitHub python3Packages; misoc-new = artiq7; };
rustManifest = pkgs.fetchurl {
url = "https://static.rust-lang.org/dist/2021-01-29/channel-rust-nightly.toml";
sha256 = "sha256-EZKgw89AH4vxaJpUHmIMzMW/80wAFQlfcxRoBD9nz0c=";
};
targets = [];
rustChannelOfTargets = _channel: _date: targets:
(pkgs.lib.rustLib.fromManifestFile rustManifest {
inherit (pkgs) stdenv lib fetchurl patchelf;
}).rust.override {
inherit targets;
extensions = ["rust-src"];
};
rust = rustChannelOfTargets "nightly" null targets;
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
});
boards = [
{ target = "kasli"; variant = "tester"; }
@ -11,7 +29,7 @@ let
];
boardPackages = pkgs.lib.lists.foldr (board: start:
let
boardBinaries = import ./artiq-board.nix { inherit pkgs; } {
boardBinaries = import ./artiq-board.nix { inherit pkgs rustPlatform; } {
target = board.target;
variant = board.variant;
};
@ -25,16 +43,18 @@ let
binutils-or1k = callPackage ./pkgs/binutils.nix { platform = "or1k"; target = "or1k-linux"; };
binutils-arm = callPackage ./pkgs/binutils.nix { platform = "arm"; target = "armv7-unknown-linux-gnueabihf"; };
llvm-or1k = callPackage ./pkgs/llvm-or1k.nix {};
rustc = callPackage ./pkgs/rust/rustc-with-crates.nix
rustc-legacy = callPackage ./pkgs/rust-legacy/rustc-with-crates.nix
((lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
stdenv = overrideCC stdenv gcc6; # with gcc-7: undefined reference to `__divmoddi4'
}) //
{ inherit llvm-or1k; });
cargo = callPackage ./pkgs/rust/cargo.nix { inherit rustc; rustPlatform = rustPackages_1_45.rustPlatform; };
cargo-vendor = callPackage ./pkgs/rust/cargo-vendor.nix {};
rustc = if artiq7 then rustPlatform.rust.rustc else rustc-legacy;
cargo-legacy = callPackage ./pkgs/rust-legacy/cargo.nix { inherit rustc; rustPlatform = rustPackages_1_45.rustPlatform; };
cargo-vendor-legacy = callPackage ./pkgs/rust-legacy/cargo-vendor.nix {};
llvmlite-artiq = callPackage ./pkgs/llvmlite-artiq.nix { inherit llvm-or1k; };
llvmlite-llvm11 = callPackage ./pkgs/llvmlite-llvm11.nix { };
libartiq-support = callPackage ./pkgs/libartiq-support.nix { inherit rustc; };
artiq = callPackage ./pkgs/artiq.nix { inherit pythonDeps binutils-or1k binutils-arm llvm-or1k llvmlite-artiq libartiq-support lit outputcheck; };
artiq = callPackage ./pkgs/artiq.nix { inherit pythonDeps binutils-or1k binutils-arm llvm-or1k llvmlite-artiq llvmlite-llvm11 libartiq-support lit outputcheck; };
artiq-env = (pkgs.python3.withPackages(ps: [ artiq ])).overrideAttrs (oldAttrs: { name = "${pkgs.python3.name}-artiq-env-${artiq.version}"; });
openocd = callPackage ./pkgs/openocd.nix { };
};
@ -90,7 +110,9 @@ let
};
};
condaLinux = rec {
# ARTIQ-7 uses upstream conda-forge packages
condaLinux = lib.optionalAttrs (!artiq7) (rec {
conda-binutils-or1k = import ./conda/binutils.nix {
inherit pkgs;
inherit (mainPackages.binutils-or1k) version src;
@ -110,9 +132,9 @@ let
inherit pkgs conda-llvm-or1k;
inherit (mainPackages.llvmlite-artiq) version src;
};
};
});
condaWindowsLegacy = {
condaWindows5 = {
conda-windows-binutils-or1k = import ./conda-windows/redistribute.nix {
inherit pkgs;
name = "binutils-or1k";
@ -136,7 +158,7 @@ let
};
};
condaWindowsExperimental = rec {
condaWindows6 = rec {
conda-windows-binutils-or1k = import ./conda-windows/binutils.nix {
inherit pkgs;
inherit (mainPackages.binutils-or1k) version src;
@ -158,6 +180,6 @@ let
};
};
condaWindows = if artiq6 then condaWindowsExperimental else condaWindowsLegacy;
condaWindows = if artiq6 then (if artiq7 then {} else condaWindows6) else condaWindows5;
in
boardPackages // mainPackages // condaNoarch // condaLinux // condaWindows

View File

@ -1,4 +1,6 @@
{ stdenv, lib, pythonDeps, fetchgit, git, python3Packages, qt5, binutils-or1k, binutils-arm, llvm-or1k, llvmlite-artiq, libartiq-support, lit, outputcheck, fontconfig }:
{ stdenv, lib, pythonDeps, fetchgit, git, python3Packages, qt5, libartiq-support, lit, outputcheck, fontconfig,
binutils-or1k, binutils-arm, llvm-or1k, llvmlite-artiq,
llvm_11, lld_11, llvmlite-llvm11 }:
python3Packages.buildPythonPackage rec {
pname = "artiq";
@ -8,8 +10,10 @@ python3Packages.buildPythonPackage rec {
preBuild = "export VERSIONEER_OVERRIDE=${version}";
nativeBuildInputs = [ qt5.wrapQtAppsHook ];
propagatedBuildInputs = [ binutils-or1k llvm-or1k llvmlite-artiq ]
++ (lib.lists.optionals (lib.strings.versionAtLeast version "6.0") [ binutils-arm ])
propagatedBuildInputs = [ ]
++ (lib.lists.optionals (!lib.strings.versionAtLeast version "7.0") [ binutils-or1k llvm-or1k llvmlite-artiq ])
++ (lib.lists.optionals (lib.strings.versionAtLeast version "7.0") [ llvm_11 lld_11 llvmlite-llvm11 ])
++ (lib.lists.optionals (lib.strings.versionAtLeast version "6.0" && !lib.strings.versionAtLeast version "7.0") [ binutils-arm ])
++ (with pythonDeps; [ sipyco pythonparser ])
++ (with python3Packages; [ pygit2 numpy dateutil scipy prettytable pyserial python-Levenshtein h5py pyqt5 pyqtgraph ])
++ [(if (lib.strings.versionAtLeast version "6.0") then pythonDeps.qasync else python3Packages.quamash)];
@ -28,14 +32,14 @@ python3Packages.buildPythonPackage rec {
"--set FONTCONFIG_FILE ${fontconfig.out}/etc/fonts/fonts.conf"
];
checkInputs = [ binutils-or1k outputcheck ];
checkInputs = [ lit outputcheck ] ++ (if (lib.strings.versionAtLeast version "7.0") then [ lld_11 llvm_11 ] else [ binutils-or1k ]);
checkPhase =
''
python -m unittest discover -v artiq.test
TESTDIR=`mktemp -d`
cp --no-preserve=mode,ownership -R ${src}/artiq/test/lit $TESTDIR
LIBARTIQ_SUPPORT=${libartiq-support}/libartiq_support.so ${lit}/bin/lit -v $TESTDIR/lit
cp --no-preserve=mode,ownership -R $src/artiq/test/lit $TESTDIR
LIBARTIQ_SUPPORT=${libartiq-support}/libartiq_support.so lit -v $TESTDIR/lit
'';

View File

@ -10,6 +10,6 @@ stdenv.mkDerivation rec {
buildPhase =
''
mkdir $out
rustc ${src}/artiq/test/libartiq_support/lib.rs --out-dir $out -Cpanic=unwind -g
rustc $src/artiq/test/libartiq_support/lib.rs --out-dir $out -Cpanic=unwind -g
'';
}

View File

@ -0,0 +1,22 @@
{ python3Packages, llvm_11 }:
python3Packages.buildPythonPackage rec {
pname = "llvmlite";
version = "0.37.0rc2";
src = python3Packages.fetchPypi {
inherit pname version;
sha256 = "sha256-F1quz+76JOt1jaQPVzdKe7RfN6gWG2lyE82qTvgyY/c=";
};
nativeBuildInputs = [ llvm_11 ];
# Disable static linking
# https://github.com/numba/llvmlite/issues/93
postPatch = ''
substituteInPlace ffi/Makefile.linux --replace "-static-libstdc++" ""
substituteInPlace llvmlite/tests/test_binding.py --replace "test_linux" "nope"
'';
# Set directory containing llvm-config binary
preConfigure = ''
export LLVM_CONFIG=${llvm_11.dev}/bin/llvm-config
'';
doCheck = false; # FIXME
}

View File

@ -4,13 +4,14 @@ let
artiqpkgs = import ./default.nix { inherit pkgs; };
vivado = import ./vivado.nix { inherit pkgs; };
in
assert pkgs.lib.asserts.assertMsg (!pkgs.lib.strings.versionAtLeast artiqpkgs.artiq.version "7.0") "For ARTIQ 7+, use 'nix develop' on the flake instead.";
pkgs.mkShell {
buildInputs = [
vivado
pkgs.gnumake
(pkgs.python3.withPackages(ps: (with ps; [ jinja2 jsonschema numpy paramiko ]) ++ (with artiqpkgs; [ migen microscope misoc jesd204b migen-axi artiq ])))
artiqpkgs.cargo
artiqpkgs.rustc
artiqpkgs.cargo-legacy
artiqpkgs.rustc-legacy
artiqpkgs.binutils-or1k
artiqpkgs.binutils-arm
artiqpkgs.llvm-or1k

View File

@ -16,8 +16,9 @@ let
name = "conda-deps";
script = let
qt-asyncio-package = if artiq6 then artiqpkgs.conda-qasync else artiqpkgs.conda-quamash;
conda-deps-noarch = import (if artiq6 then ./conda_noarch_packages.nix else ./conda_noarch_packages-legacy.nix) { inherit pkgs; };
conda-deps-win-64 = import (if artiq6 then ./conda_win-64_packages.nix else ./conda_win-64_packages-legacy.nix) { inherit pkgs; };
vermajor = pkgs.lib.versions.major artiqpkgs.artiq.version;
conda-deps-noarch = import "./conda_noarch_packages-${vermajor}.nix" { inherit pkgs; };
conda-deps-win-64 = import "./conda_win-64_packages-${vermajor}.nix" { inherit pkgs; };
conda-packages-put = pkgs.lib.strings.concatStringsSep "\n"
( (map (package: ''win-put ${package} 'fake-channel/noarch' '') conda-deps-noarch)
++ (map (package: ''win-put ${package} 'fake-channel/win-64' '') conda-deps-win-64) );

View File

@ -144,12 +144,12 @@
}
},
"fast-riscv": {
"fast-flakes": {
"enabled": 1,
"type": 1,
"hidden": false,
"description": "Core ARTIQ packages to build fast for CI purposes (RISC-V + flakes version)",
"flake": "github:m-labs/artiq/riscv",
"description": "Core ARTIQ packages to build fast for CI purposes (Nix flakes version)",
"flake": "github:m-labs/artiq",
"checkinterval": 300,
"schedulingshares": 10,
"enableemail": false,