Skip to content

Commit

Permalink
[nix] refactor the rocketv subattr
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin authored and Clo91eaf committed Aug 8, 2024
1 parent 7666efe commit c9f7b91
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 62 deletions.
4 changes: 0 additions & 4 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ lib.makeScope newScope
configgen = _millOutput.configgen // { meta.mainProgram = "configgen"; };
t1package = _millOutput.t1package;

# FIXME: move all the rocketv file to an individual directory and put all attribute into one scope.
rocketv-mlirbc = self.callPackage ./rocketv-mlirbc.nix { };
rocketv-rtl = self.callPackage ./rocketv-rtl.nix { };
rocketv-verilated-csrc = self.callPackage ./rocketv-verilated-csrc.nix { };
rocketv = self.callPackage ../../rocketemu { };

omreader-unwrapped = self.callPackage ./omreader.nix { };
Expand Down
116 changes: 67 additions & 49 deletions rocketemu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,74 @@
, rustPlatform
, libspike
, zlib
, rocketv-verilated-csrc
}:
lib.makeScope newScope (scope: rec {
c-dpi-lib = scope.callPackage ./dpi { };

# FIXME: merge with difftest and put it under the nix/pkgs
spike_interfaces = scope.callPackage ../difftest/spike_interfaces { };

emu = rustPlatform.buildRustPackage {
name = "rocketemu";

src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./driver
./offline
./spike_rs
./test_common
./Cargo.lock
./Cargo.toml
];
};

buildInputs = [
zlib
spike_interfaces
];

# FIXME: can we hack this into derivations, so that we don't need to specify library dir explicitly?
env =
let
toLib = drv: "${drv}/lib";
in
{
ROCKET_DPI_DIR = toLib c-dpi-lib;
TESTBENCH_LIB_DIR = toLib rocketv-verilated-csrc;
SPIKE_LIB_DIR = toLib libspike;
SPIKE_INTERFACES_LIB_DIR = toLib spike_interfaces;
};
let
configsDirectory = ../rocketv/configs;
# allConfigs is a (configName -> configJsonPath) map
allConfigs = lib.mapAttrs'
(fileName: fileType:
assert fileType == "regular" && lib.hasSuffix ".json" fileName;
lib.nameValuePair
(lib.removeSuffix ".json" fileName)
(lib.path.append configsDirectory fileName))
(builtins.readDir configsDirectory);
in
lib.mapAttrs
(configName: configPath: (
lib.makeScope newScope (scope: rec {
rocket-config = configPath;
mlirbc = scope.callPackage ./nix/mlirbc.nix { };
rtl = scope.callPackage ./nix/rtl.nix { };
verilated-csrc = scope.callPackage ./nix/verilated-csrc.nix { };

c-dpi-lib = scope.callPackage ./dpi { };

# FIXME: merge with difftest and put it under the nix/pkgs
spike_interfaces = scope.callPackage ../difftest/spike_interfaces { };

emu = rustPlatform.buildRustPackage {
name = "rocketemu";

cargoLock = {
lockFile = ./Cargo.lock;
};
src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./driver
./offline
./spike_rs
./test_common
./Cargo.lock
./Cargo.toml
];
};

outputs = [ "out" "driver" "offline" ];
buildInputs = [
zlib
spike_interfaces
];

postInstall = ''
mkdir -p $driver/bin $offline/bin
ln -s $out/bin/driver $driver/bin/driver
ln -s $out/bin/offline $driver/bin/offline
'';
};
})
env =
let
toLib = drv: "${drv}/lib";
in
{
ROCKET_DPI_DIR = toLib c-dpi-lib;
TESTBENCH_LIB_DIR = toLib verilated-csrc;
SPIKE_LIB_DIR = toLib libspike;
SPIKE_INTERFACES_LIB_DIR = toLib spike_interfaces;
};

cargoLock = {
lockFile = ./Cargo.lock;
};

outputs = [ "out" "driver" "offline" ];

postInstall = ''
mkdir -p $driver/bin $offline/bin
ln -s $out/bin/driver $driver/bin/driver
ln -s $out/bin/offline $driver/bin/offline
'';
};
})
)) # end of mapAttr
allConfigs
8 changes: 4 additions & 4 deletions rocketemu/dpi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, stdenv
, cmake
, ninja
, rocketv-verilated-csrc
, verilated-csrc
}:
stdenv.mkDerivation {
name = "rocketv-emulator";
Expand All @@ -16,12 +16,12 @@ stdenv.mkDerivation {
verilator
];

cmakeFlags = lib.optionals rocketv-verilated-csrc.enable-trace [
cmakeFlags = lib.optionals verilated-csrc.enable-trace [
"-DVM_TRACE=ON"
];

env = {
VERILATED_INC_DIR = "${rocketv-verilated-csrc}/include";
VERILATED_LIB_DIR = "${rocketv-verilated-csrc}/lib";
VERILATED_INC_DIR = "${verilated-csrc}/include";
VERILATED_LIB_DIR = "${verilated-csrc}/lib";
};
}
3 changes: 2 additions & 1 deletion nix/t1/rocketv-mlirbc.nix → rocketemu/nix/mlirbc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
, circt

, elaborator
, rocket-config
}:
stdenvNoCC.mkDerivation {
name = "t1-rocketv-elaborated.mlirbc";
Expand All @@ -12,7 +13,7 @@ stdenvNoCC.mkDerivation {

buildCommand = ''
mkdir elaborate
elaborator rocketemu --target-dir elaborate --rocket-config ${../../rocketv/configs/RocketTile.json}
elaborator rocketemu --target-dir elaborate --rocket-config ${rocket-config}
firtool elaborate/*.fir \
--annotation-file elaborate/*.anno.json \
--emit-bytecode \
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/rocketv-rtl.nix → rocketemu/nix/rtl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, lib

, circt
, rocketv-mlirbc
, mlirbc
}:

let
Expand All @@ -21,6 +21,6 @@ stdenvNoCC.mkDerivation {
buildCommand = ''
mkdir -p $out
firtool ${rocketv-mlirbc} ${mfcArgs} -o $out
firtool ${mlirbc} ${mfcArgs} -o $out
'';
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, fetchgit
, stdenv
, rocketv-rtl
, rtl
, verilator
, enable-trace ? true
, zlib
Expand All @@ -21,7 +21,7 @@ in
stdenv.mkDerivation {
name = "t1-rocketv-verilated";

src = rocketv-rtl;
src = rtl;

nativeBuildInputs = [ verilator ];

Expand Down
File renamed without changes.

0 comments on commit c9f7b91

Please sign in to comment.