Skip to content

Commit

Permalink
Nix for sail c emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
b-paul committed Nov 17, 2024
1 parent 806b1ba commit 90bca94
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
13 changes: 13 additions & 0 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Build legacy Nix package on Ubuntu"

on:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v26
- name: Building package
run: nix build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.direnv
7 changes: 7 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).defaultNix
95 changes: 95 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
inputs = {
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils, naersk }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { };
sail_csim = pkgs.callPackage ./nix/sail-riscv.nix { arch = "RV64"; };
in
{
packages.default = naersk-lib.buildPackage ./.;
devShells.default = with pkgs; mkShell {
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy python311Packages.riscof sail_csim ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
}
);
}
76 changes: 76 additions & 0 deletions nix/sail-riscv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Modified from https://github.com/NixOS/nixpkgs/blob/e0464e47880a69896f0fb1810f00e0de469f770a/pkgs/applications/virtualization/sail-riscv/default.nix

{ stdenv
, fetchFromGitHub
, fetchpatch
, lib
, arch
, pkgs
, ocamlPackages
, ocaml
, zlib
, z3
}:


stdenv.mkDerivation rec {
pname = "sail-riscv";
version = "8a2e0f565808e6f1ee02c6369005cd153b8205a0";

src = fetchFromGitHub {
owner = "riscv";
repo = pname;
rev = version;
hash = "sha256-0dI/M6u/wSa41Xg0uWoJIN4BkAZ//WXommknA+JFPK4=";
};

nativeBuildInputs = with ocamlPackages; [ ocamlbuild findlib ocaml z3 pkgs.pkg-config
(sail.overrideAttrs (previousAttrs: {
version = "0.18";

src = fetchFromGitHub {
owner = "rems-project";
repo = "sail";
rev = "0.18";
hash = "sha256-QvVK7KeAvJ/RfJXXYo6xEGEk5iOmVsZbvzW28MHRFic=";
};

propagatedBuildInputs = previousAttrs.propagatedBuildInputs ++ [ ocamlPackages.menhirLib ];
}))];
buildInputs = with ocamlPackages; [ zlib linksem ];
strictDeps = true;

postPatch = ''
rm -r prover_snapshots
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace Makefile --replace "-flto" ""
'';

makeFlags = [
"SAIL=sail"
"ARCH=${arch}"
"SAIL_DIR=${ocamlPackages.sail}/share/sail"
"LEM_DIR=${ocamlPackages.sail}/share/lem"
];

installPhase = ''
sail -version
runHook preInstall
mkdir -p $out/bin
cp c_emulator/riscv_sim_${arch} $out/bin
#mkdir $out/share/
#cp -r generated_definitions/{coq,hol4,isabelle} $out/share/
runHook postInstall
'';


meta = with lib; {
homepage = "https://github.com/riscv/sail-riscv";
description = "Formal specification of the RISC-V architecture, written in Sail";
# maintainers = with maintainers; [ genericnerdyusername ];
broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64;
license = licenses.bsd2;
};
}
7 changes: 7 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix

0 comments on commit 90bca94

Please sign in to comment.