Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] add static build for libspike #682

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions difftest/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib
, libspike
, callPackage
, elaborateConfig

Expand Down Expand Up @@ -45,6 +46,8 @@ let
env = {
VERILATED_INC_DIR = "${verilated}/include";
VERILATED_LIB_DIR = "${verilated}/lib";
SPIKE_LIB_DIR = "${libspike}/lib";
SPIKE_INTERFACES_LIB_DIR = "${spike_interfaces}/lib";
DESIGN_VLEN = elaborateConfig.parameter.vLen;
DESIGN_DLEN = elaborateConfig.parameter.dLen;
};
Expand Down
2 changes: 1 addition & 1 deletion difftest/spike_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD 17)

find_package(libspike REQUIRED)

add_library(${CMAKE_PROJECT_NAME} SHARED spike_interfaces.cc)
add_library(${CMAKE_PROJECT_NAME} STATIC spike_interfaces.cc)

target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC libspike)

Expand Down
18 changes: 18 additions & 0 deletions difftest/spike_rs/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::env;

fn main() {
println!("cargo::rustc-link-search=native={}", env::var("SPIKE_LIB_DIR").expect("SPIKE_LIB_DIR should be set"));
println!("cargo::rustc-link-lib=static=riscv");
println!("cargo::rustc-link-lib=static=softfloat");
println!("cargo::rustc-link-lib=static=disasm");
println!("cargo::rustc-link-lib=static=fesvr");
println!("cargo::rustc-link-lib=static=fdt");

println!("cargo::rustc-link-search=native={}", env::var("SPIKE_INTERFACES_LIB_DIR").expect("SPIKE_INTERFACES_LIB_DIR should be set"));
println!("cargo::rustc-link-lib=static=spike_interfaces");

println!("cargo::rerun-if-env-changed=SPIKE_LIB_DIR");
println!("cargo::rerun-if-env-changed=SPIKE_INTERFACES_LIB_DIR");

println!("cargo::rustc-link-lib=stdc++");
}
1 change: 0 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ rec {
espresso = final.callPackage ./pkgs/espresso.nix { };
dramsim3 = final.callPackage ./pkgs/dramsim3.nix { };
libspike = final.callPackage ./pkgs/libspike.nix { };
libspike_interfaces = final.callPackage ../difftest/libspike_interfaces { };
buddy-mlir = final.callPackage ./pkgs/buddy-mlir.nix { };
fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { };
circt-full = final.callPackage ./pkgs/circt-full.nix { };
Expand Down
3 changes: 2 additions & 1 deletion nix/pkgs/libspike.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stdenv.mkDerivation {
env.cmakeConfig = ''
add_library(libspike STATIC IMPORTED GLOBAL)
set_target_properties(libspike PROPERTIES
IMPORTED_LOCATION "${placeholder "out"}/lib/libriscv.so")
IMPORTED_LOCATION "${placeholder "out"}/lib/libriscv.a")
target_include_directories(libspike AFTER INTERFACE
"${placeholder "out"}/include"
"${placeholder "out"}/include/riscv"
Expand Down Expand Up @@ -37,6 +37,7 @@ stdenv.mkDerivation {
cp softfloat/*.h $out/include/softfloat
cp config.h $out/include
cp *.so $out/lib
cp *.a $out/lib
echo "$cmakeConfig" > $out/lib/cmake/libspike/libspike-config.cmake
runHook postInstall
'';
Expand Down