Skip to content

Commit

Permalink
fix(cli): automatically determine version
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadiSave committed Sep 16, 2023
1 parent d8427ca commit ae95f42
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.vscode
.idea
Cargo.lock

# build script artifacts
cli/LIBRARY_VERSION
3 changes: 3 additions & 0 deletions cli/Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ features = ["compile"]
[dependencies.clap]
version = "3"
features = ["derive"]

[build-dependencies]
cargo_toml = "0.15.2"
20 changes: 20 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::path::PathBuf;

use cargo_toml::Manifest;

const ROOT: &str = env!("CARGO_MANIFEST_DIR");

fn main() {
let manifest = Manifest::from_path(PathBuf::from_iter([ROOT, "Cargo.toml"])).unwrap();
let version = manifest
.dependencies
.get("cambridge-asm")
.unwrap()
.detail()
.unwrap()
.version
.as_ref()
.unwrap();

std::fs::write(PathBuf::from_iter([ROOT, "LIBRARY_VERSION"]), version).unwrap();
}
2 changes: 1 addition & 1 deletion cli/src/main.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::ffi::OsString;

#[derive(Parser)]
#[clap(name = "Cambridge Pseudoassembly Interpreter")]
#[clap(version = concat!(env!("CARGO_PKG_VERSION"), "\n", "Library version 0.18.0"))]
#[clap(version = concat!("v", env!("CARGO_PKG_VERSION"), "\nCambridge Pseudoassembly v", include_str!("../LIBRARY_VERSION")))]
#[clap(author = "Saadi Save <github.com/SaadiSave>")]
#[clap(about = "Run pseudoassembly from Cambridge International syllabus 9618 (2021)")]
enum Commands {
Expand Down

0 comments on commit ae95f42

Please sign in to comment.