Browse Source

RustSBI version and platform version

luojia65 4 years ago
parent
commit
313bda2a71
4 changed files with 14 additions and 7 deletions
  1. 2 2
      platform/k210/src/main.rs
  2. 2 2
      platform/qemu/src/main.rs
  3. 1 1
      rustsbi/Cargo.toml
  4. 9 2
      rustsbi/src/lib.rs

+ 2 - 2
platform/k210/src/main.rs

@@ -231,9 +231,9 @@ fn main() -> ! {
     }
 
     if mhartid::read() == 0 {
-        println!("[rustsbi] Version 0.1.0");
+        println!("[rustsbi] RustSBI version {}", rustsbi::VERSION);
         println!("{}", rustsbi::LOGO);
-        println!("[rustsbi] Platform: K210");
+        println!("[rustsbi] Platform: K210 (Version {})", env!("CARGO_PKG_VERSION"));
         let isa = misa::read();
         if let Some(isa) = isa {
             let mxl_str = match isa.mxl() {

+ 2 - 2
platform/qemu/src/main.rs

@@ -179,9 +179,9 @@ fn main() {
     }
 
     if mhartid::read() == 0 {
-        println!("[rustsbi] Version 0.1.0");
+        println!("[rustsbi] RustSBI version {}", rustsbi::VERSION);
         println!("{}", rustsbi::LOGO);
-        println!("[rustsbi] Platform: QEMU");
+        println!("[rustsbi] Platform: QEMU (Version {})", env!("CARGO_PKG_VERSION"));
         let isa = misa::read();
         if let Some(isa) = isa {
             let mxl_str = match isa.mxl() {

+ 1 - 1
rustsbi/Cargo.toml

@@ -1,7 +1,7 @@
 [package]
 name = "rustsbi"
 description = "Minimal RISC-V's SBI implementation library in Rust"
-version = "0.1.0"
+version = "0.1.1"
 authors = ["luojia65 <[email protected]>"]
 repository = "https://github.com/luojia65/rustsbi"
 documentation = "https://docs.rs/rustsbi"

+ 9 - 2
rustsbi/src/lib.rs

@@ -38,8 +38,15 @@ const SBI_SPEC_MINOR: usize = 2;
 // RustSBI implementation ID: 4
 // Ref: https://github.com/riscv/riscv-sbi-doc/pull/61
 const IMPL_ID_RUSTSBI: usize = 4;
-// todo: read from env!("CARGO_PKG_VERSION")
-const RUSTSBI_VERSION: usize = 1; 
+// Read from env!("CARGO_PKG_VERSION")
+const RUSTSBI_VERSION_MAJOR: usize = (env!("CARGO_PKG_VERSION_MAJOR").as_bytes()[0] - b'0') as usize;
+const RUSTSBI_VERSION_MINOR: usize = (env!("CARGO_PKG_VERSION_MINOR").as_bytes()[0] - b'0') as usize;
+const RUSTSBI_VERSION_PATCH: usize = (env!("CARGO_PKG_VERSION_PATCH").as_bytes()[0] - b'0') as usize;
+const RUSTSBI_VERSION: usize = {
+   (RUSTSBI_VERSION_MAJOR << 16) + (RUSTSBI_VERSION_MINOR << 8) + RUSTSBI_VERSION_PATCH
+};
+/// RustSBI version as string
+pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
 
 pub use ecall::handle_ecall as ecall;
 pub use ecall::SbiRet;