diff --git a/difftest/online_vcs/Cargo.toml b/difftest/online_vcs/Cargo.toml index 7ddddbd49..d85b2b690 100644 --- a/difftest/online_vcs/Cargo.toml +++ b/difftest/online_vcs/Cargo.toml @@ -5,6 +5,7 @@ version.workspace = true [lib] crate-type = ["staticlib"] +name = "dpi" [dependencies] online_dpi = { path = "../online_dpi", features = ["svvpi"] } diff --git a/difftest/online_vcs/default.nix b/difftest/online_vcs/default.nix index 657bad854..b6ff3fe19 100644 --- a/difftest/online_vcs/default.nix +++ b/difftest/online_vcs/default.nix @@ -2,8 +2,8 @@ , rustPlatform , libspike , spike_interfaces -, vcStaticInstallPath , enable-trace ? false +, vcStaticHome }: rustPlatform.buildRustPackage { @@ -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"; }; diff --git a/nix/overlay.nix b/nix/overlay.nix index 80d247fbc..6f20d868a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -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 (_: { diff --git a/nix/pkgs/vcs-fhs-env.nix b/nix/pkgs/vcs-fhs-env.nix index 37baa934d..0b755983b 100644 --- a/nix/pkgs/vcs-fhs-env.nix +++ b/nix/pkgs/vcs-fhs-env.nix @@ -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 diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 421131c8f..b4a924b8f 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -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 { diff --git a/nix/t1/vcs.nix b/nix/t1/vcs.nix index 82de5d283..fd7a84348 100644 --- a/nix/t1/vcs.nix +++ b/nix/t1/vcs.nix @@ -3,10 +3,10 @@ , configName , makeWrapper , rtl -, dpi-lib +, vcs-dpi-lib , vcs-fhs-env -, enable-trace ? false }: + stdenv.mkDerivation { name = "${configName}-vcs"; @@ -16,7 +16,6 @@ stdenv.mkDerivation { src = rtl; nativeBuildInputs = [ - vcs-fhs-env makeWrapper ]; @@ -24,34 +23,44 @@ stdenv.mkDerivation { 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 ''; }