Skip to content

Commit

Permalink
[nix] fix vcs environment
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jul 25, 2024
1 parent c03364f commit bb4d022
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 37 deletions.
1 change: 1 addition & 0 deletions difftest/online_vcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version.workspace = true

[lib]
crate-type = ["staticlib"]
name = "dpi"

[dependencies]
online_dpi = { path = "../online_dpi", features = ["svvpi"] }
Expand Down
4 changes: 2 additions & 2 deletions difftest/online_vcs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
, rustPlatform
, libspike
, spike_interfaces
, vcStaticInstallPath
, enable-trace ? false
, vcStaticHome
}:

rustPlatform.buildRustPackage {
Expand All @@ -26,7 +26,7 @@ rustPlatform.buildRustPackage {
buildAndTestSubdir = "./online_vcs";

env = {
VCS_LIB_DIR = "${vcStaticInstallPath}/vcs-mx/linux64/lib";
VCS_LIB_DIR = "${vcStaticHome}/vcs-mx/linux64/lib";
SPIKE_LIB_DIR = "${libspike}/lib";
SPIKE_INTERFACES_LIB_DIR = "${spike_interfaces}/lib";
};
Expand Down
7 changes: 3 additions & 4 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ rec {
rvv-codegen = final.callPackage ./pkgs/rvv-codegen.nix { };
add-determinism = final.callPackage ./pkgs/add-determinism { }; # faster strip-undetereminism
# Using VCS need to set VC_STATIC_HOME and SNPSLMD_LICENSE_FILE to impure env, and add sandbox dir to VC_STATIC_HOME
vcs-fhs-env = final.callPackage ./pkgs/vcs-fhs-env.nix {
vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME";
snpsLicenseFile = builtins.getEnv "SNPSLMD_LICENSE_FILE";
};
vcStaticHome = builtins.getEnv "VC_STATIC_HOME";
snpslmdLicenseFile = builtins.getEnv "SNPSLMD_LICENSE_FILE";
vcs-fhs-env = final.callPackage ./pkgs/vcs-fhs-env.nix { };

mill = let jre = final.jdk21; in
(prev.mill.override { inherit jre; }).overrideAttrs (_: {
Expand Down
41 changes: 25 additions & 16 deletions nix/pkgs/vcs-fhs-env.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
{ buildFHSEnv
# e.g. /opt/synopsys/vc_static/V-2023.12
, vcStaticInstallPath
# e.g. port@addr
, snpsLicenseFile
, vcStaticHome
, snpslmdLicenseFile
}:
buildFHSEnv {
name = "vcs-fhs-env";

profile = ''
[ ! -d "${vcStaticHome}" ] && echo "VC HOME not set" && exit 1
[ -z "${snpslmdLicenseFile}" ] && echo "SNPS LICENSE not set" && exit 1
export VC_STATIC_HOME=${vcStaticHome}
export TCL_TZ=UTC
export VC_STATIC_HOME=${vcStaticInstallPath}
export VCS_HOME=${vcStaticInstallPath}/vcs-mx
export VC_STATIC_HOME=$VC_STATIC_HOME
export VCS_HOME=$VC_STATIC_HOME/vcs-mx
export VCS_TARGET_ARCH=amd64
export VCS_ARCH_OVERRIDE=linux
export VERDI_HOME=${vcStaticInstallPath}/verdi
export NOVAS_HOME=${vcStaticInstallPath}/verdi
export SPYGLASS_HOME=${vcStaticInstallPath}/SG_COMPAT/SPYGLASS_HOME
export VERDI_HOME=$VC_STATIC_HOME/verdi
export NOVAS_HOME=$VC_STATIC_HOME/verdi
export SPYGLASS_HOME=$VC_STATIC_HOME/SG_COMPAT/SPYGLASS_HOME
export SNPS_VERDI_CBUG_LCA=1
export SNPSLMD_LICENSE_FILE=${snpsLicenseFile}
export SNPSLMD_LICENSE_FILE=${snpslmdLicenseFile}
export PATH=${vcStaticInstallPath}/bin:$PATH
export PATH=${vcStaticInstallPath}/verdi/bin:$PATH
export PATH=${vcStaticInstallPath}/vcs-mx/bin:$PATH
export PATH=${vcStaticInstallPath}/SG_COMPAT/SPYGLASS_HOME/bin:$PATH
export PATH=$VC_STATIC_HOME/bin:$PATH
export PATH=$VC_STATIC_HOME/verdi/bin:$PATH
export PATH=$VC_STATIC_HOME/vcs-mx/bin:$PATH
export PATH=$VC_STATIC_HOME/SG_COMPAT/SPYGLASS_HOME/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib64/
export LD_LIBRARY_PATH=${vcStaticInstallPath}/verdi/share/PLI/lib/LINUX64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${vcStaticInstallPath}/verdi/share/NPI/lib/LINUX64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$VC_STATIC_HOME/verdi/share/PLI/lib/LINUX64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$VC_STATIC_HOME/verdi/share/NPI/lib/LINUX64:$LD_LIBRARY_PATH
export _oldVcsEnvPath="$PATH"
preHook() {
PATH="$PATH:$_oldVcsEnvPath"
}
export -f preHook
'';
targetPkgs = (ps: with ps; [
libGL
Expand Down
6 changes: 3 additions & 3 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ lib.makeScope newScope
"--strip-debug-info"
];
};
vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; };
vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; enable-trace = true; };
vcs-dpi-lib = innerSelf.callPackage ../../difftest/online_vcs { vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME"; };
vcs-dpi-lib = innerSelf.callPackage ../../difftest/online_vcs { };
vcs-dpi-lib-trace = vcs-dpi-lib.override { enable-trace = true; };
vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { inherit vcs-dpi-lib; rtl = vcs-emu-rtl; };
vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { vcs-dpi-lib = vcs-dpi-lib-trace; rtl = vcs-emu-rtl; };
};

subsystem = rec {
Expand Down
33 changes: 21 additions & 12 deletions nix/t1/vcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
, configName
, makeWrapper
, rtl
, dpi-lib
, vcs-dpi-lib
, vcs-fhs-env
, enable-trace ? false
}:

stdenv.mkDerivation {
name = "${configName}-vcs";

Expand All @@ -16,42 +16,51 @@ stdenv.mkDerivation {
src = rtl;

nativeBuildInputs = [
vcs-fhs-env
makeWrapper
];

buildPhase = ''
runHook preBuild
echo "[nix] running VCS"
${vcs-fhs-env}/bin/vcs-fhs-env vcs \
fhsBash=${vcs-fhs-env}/bin/vcs-fhs-env
VERDI_HOME=$("$fhsBash" -c "printenv VERDI_HOME")
"$fhsBash" vcs \
-sverilog \
-full64 \
-timescale=1ns/1ps \
${lib.optionalString enable-trace ''
${lib.optionalString vcs-dpi-lib.enable-trace ''
--trace-fst \
-P $VERDI_HOME/share/PLI/VCS/LINUX64/novas.tab $VERDI_HOME/share/PLI/VCS/LINUX64/pli.a \
-debug_access+pp+dmptf+thread \
-kdb=common_elab,hgldd_all \
''}
-kdb=common_elab,hgldd_all''} \
-file filelist.f \
${dpi-lib}/lib/libdpi.a \
${vcs-dpi-lib}/lib/libdpi.a \
-o t1-vcs-simulator
runHook postBuild
'';

passthru = {
inherit enable-trace;
inherit (vcs-dpi-lib) enable-trace;
};

shellHook = ''
echo "[nix] entering fhs env"
${vcs-fhs-env}/bin/vcs-fhs-env
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/lib $out/share/daidir
mkdir -p $out/bin $out/lib
cp t1-vcs-simulator $out/lib
cp -r ./t1-vcs-simulator.daidir/* $out/share/daidir
cp -r t1-vcs-simulator.daidir $out/lib
makeWrapper "${vcs-fhs-env}/bin/vcs-fhs-env" $out/bin/t1-vcs-simulator \
--add-flags "-c $out/bin/t1-vcs-simulator" \
--prefix LD_LIBRARY_PATH : $out/lib/t1-vcs-simulator.daidir
makeWrapper $out/bin/t1-vcs-simulator --add-flags "$out/lib/t1-vcs-simulator -daidir=$out/share/daidir"
runHook postInstall
'';
}

0 comments on commit bb4d022

Please sign in to comment.