1{ lib, stdenv, fetchFromGitHub, dtc, pkgsCross }:
2
3stdenv.mkDerivation rec {
4 pname = "spike";
5 version = "1.1.0";
6
7 src = fetchFromGitHub {
8 owner = "riscv";
9 repo = "riscv-isa-sim";
10 rev = "v${version}";
11 sha256 = "sha256-4D2Fezej0ioOOupw3kgMT5VLs+/jXQjwvek6v0AVMzI=";
12 };
13
14 nativeBuildInputs = [ dtc ];
15 enableParallelBuilding = true;
16
17 postPatch = ''
18 patchShebangs scripts/*.sh
19 patchShebangs tests/ebreak.py
20 '';
21
22 doCheck = true;
23
24 # To test whether spike is working, we run the RISC-V hello applications using the RISC-V proxy
25 # kernel on the Spike emulator and see whether we get the expected output.
26 doInstallCheck = true;
27 installCheckPhase =
28 let
29 riscvPkgs = pkgsCross.riscv64-embedded;
30 in
31 ''
32 runHook preInstallCheck
33
34 echo -e "#include<stdio.h>\nint main() {printf(\"Hello, world\");return 0;}" > hello.c
35 ${riscvPkgs.stdenv.cc}/bin/riscv64-none-elf-gcc -o hello hello.c
36 $out/bin/spike -m64 ${riscvPkgs.riscv-pk}/bin/pk hello | grep -Fq "Hello, world"
37
38 runHook postInstallCheck
39 '';
40
41 meta = with lib; {
42 description = "A RISC-V ISA Simulator";
43 homepage = "https://github.com/riscv/riscv-isa-sim";
44 license = licenses.bsd3;
45 platforms = [ "x86_64-linux" "aarch64-linux" ];
46 maintainers = with maintainers; [ blitz ];
47 };
48}