-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sail-riscv] add sail-riscv Rust binder
Disambiguation: * sail: the official sail language, library, API, headers that belongs to rem-project. * sail-riscv: the riscv spec definition describe using sail. Build step: 1. Use rust-bindgen to create Rust FFI to the sail header, so that we can always keep integrity of the sail library. 2. Extern declare all necessary C function define in generated model from sail and sail-riscv. 3. Define or override necessary functions from our Rust side. Current issues: * Implement our Rust emulator using above strategy inevitably create a programming model that functions will be called back and forth from both C and Rust side. This will also make the code hard to read. Hope this situation could be improved in upcomming rational documents. * Although sail support using different prefix for its model declaration when generating C sources, I am still afraid that these global machine state in sail-riscv model will cause problem in our future development. Signed-off-by: Avimitin <[email protected]>
- Loading branch information
Showing
8 changed files
with
463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ lib, newScope }: | ||
lib.makeScope newScope (scope: { | ||
sail-riscv-sys = scope.callPackage ./sail-riscv-sys { }; | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "sail-riscv-sys" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
||
[build-dependencies] | ||
bindgen = "0.70.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let sail_install_path = env::var("SAIL_INSTALL_PATH").expect("$SAIL_INSTALL_PATH not set"); | ||
|
||
let bindings = bindgen::Builder::default() | ||
.header("sail_include/wrapper.h") | ||
.clang_arg(format!("-I{sail_install_path}/share/sail/lib")) | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the $OUT_DIR/bindings.rs file. | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("sail_h.rs")) | ||
.expect("Couldn't write bindings!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ lib | ||
, rustPlatform | ||
, sail-riscv-c-model | ||
, rustfmt | ||
, rust-analyzer | ||
, gmp | ||
}: | ||
|
||
let | ||
finalPkg = rustPlatform.buildRustPackage { | ||
name = "sail-riscv-rs-emulator"; | ||
src = with lib.fileset; toSource { | ||
root = ./.; | ||
fileset = unions [ | ||
./src | ||
./build.rs | ||
./sail_include | ||
./Cargo.lock | ||
./Cargo.toml | ||
]; | ||
}; | ||
|
||
nativeBuildInputs = [ | ||
rustPlatform.bindgenHook | ||
]; | ||
|
||
buildInputs = [ gmp ]; | ||
|
||
env = { | ||
SAIL_INSTALL_PATH = toString sail-riscv-c-model.sail; | ||
}; | ||
|
||
cargoLock = { | ||
lockFile = ./Cargo.lock; | ||
}; | ||
|
||
passthru = { | ||
devShell = finalPkg.overrideAttrs (prev: { | ||
nativeBuildInputs = prev.nativeBuildInputs ++ [ | ||
rustfmt | ||
rust-analyzer | ||
]; | ||
}); | ||
}; | ||
}; | ||
in | ||
finalPkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include <sail.h> |
Oops, something went wrong.