-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use workspace version in packages
- Loading branch information
Showing
13 changed files
with
271 additions
and
20 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
[package] | ||
name = "tycho-cli" | ||
description = "Node CLI." | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
|
||
[[bin]] | ||
name = "tycho" | ||
path = "./src/main.rs" | ||
|
||
[dependencies] | ||
# crates.io deps | ||
anyhow = "1" | ||
clap = { version = "4.5", features = ["derive"] } | ||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] } | ||
tikv-jemallocator = { version = "0.5", features = [ | ||
"unprefixed_malloc_on_supported_platforms", | ||
"background_threads", | ||
], optional = true } | ||
|
||
# local deps | ||
|
||
[build-dependencies] | ||
anyhow = "1" | ||
rustc_version = "0.4" | ||
|
||
[features] | ||
default = ["jemalloc"] | ||
jemalloc = ["dep:tikv-jemallocator"] | ||
|
||
[lints] | ||
workspace = true |
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,87 @@ | ||
use std::os::unix::ffi::OsStringExt; | ||
|
||
use anyhow::Result; | ||
|
||
fn main() -> Result<()> { | ||
let app_version = env("CARGO_PKG_VERSION")?; | ||
let app_version = match app_version.to_string_lossy() { | ||
std::borrow::Cow::Borrowed(version) => version, | ||
std::borrow::Cow::Owned(version) => { | ||
anyhow::bail!("invalid CARGO_PKG_VERSION: {version}") | ||
} | ||
}; | ||
let git_version = get_git_version()?; | ||
let rustc_version = rustc_version::version()?; | ||
|
||
println!("cargo:rustc-env=TYCHO_VERSION={app_version}"); | ||
println!("cargo:rustc-env=TYCHO_BUILD={git_version}"); | ||
println!("cargo:rustc-env=TYCHO_RUSTC_VERSION={rustc_version}"); | ||
Ok(()) | ||
} | ||
|
||
fn get_git_version() -> Result<String> { | ||
let pkg_dir = std::path::PathBuf::from(env("CARGO_MANIFEST_DIR")?); | ||
let git_dir = command("git", &["rev-parse", "--git-dir"], Some(pkg_dir)); | ||
let git_dir = match git_dir { | ||
Ok(git_dir) => std::path::PathBuf::from(std::ffi::OsString::from_vec(git_dir)), | ||
Err(msg) => { | ||
println!("cargo:warning=unable to determine git version (not in git repository?)"); | ||
println!("cargo:warning={msg}"); | ||
return Ok("unknown".to_owned()); | ||
} | ||
}; | ||
|
||
for subpath in ["HEAD", "logs/HEAD", "index"] { | ||
let path = git_dir.join(subpath).canonicalize()?; | ||
println!("cargo:rerun-if-changed={}", path.display()); | ||
} | ||
|
||
// * --always -> if there is no matching tag, use commit hash | ||
// * --dirty=-modified -> append '-modified' if there are local changes | ||
// * --tags -> consider tags even if they are unnanotated | ||
// * --match=v[0-9]* -> only consider tags starting with a v+digit | ||
let args = &[ | ||
"describe", | ||
"--always", | ||
"--dirty=-modified", | ||
"--tags", | ||
"--match=v[0-9]*", | ||
]; | ||
let out = command("git", args, None)?; | ||
match String::from_utf8_lossy(&out) { | ||
std::borrow::Cow::Borrowed(version) => Ok(version.trim().to_string()), | ||
std::borrow::Cow::Owned(version) => { | ||
anyhow::bail!("git: invalid output: {version}") | ||
} | ||
} | ||
} | ||
|
||
fn command(prog: &str, args: &[&str], cwd: Option<std::path::PathBuf>) -> Result<Vec<u8>> { | ||
println!("cargo:rerun-if-env-changed=PATH"); | ||
let mut cmd = std::process::Command::new(prog); | ||
cmd.args(args); | ||
cmd.stderr(std::process::Stdio::inherit()); | ||
if let Some(cwd) = cwd { | ||
cmd.current_dir(cwd); | ||
} | ||
let out = cmd.output()?; | ||
if out.status.success() { | ||
let mut stdout = out.stdout; | ||
if let Some(b'\n') = stdout.last() { | ||
stdout.pop(); | ||
if let Some(b'\r') = stdout.last() { | ||
stdout.pop(); | ||
} | ||
} | ||
Ok(stdout) | ||
} else if let Some(code) = out.status.code() { | ||
anyhow::bail!("{prog}: terminated with {code}"); | ||
} else { | ||
anyhow::bail!("{prog}: killed by signal") | ||
} | ||
} | ||
|
||
fn env(key: &str) -> Result<std::ffi::OsString> { | ||
println!("cargo:rerun-if-env-changed={}", key); | ||
std::env::var_os(key).ok_or_else(|| anyhow::anyhow!("missing '{}' environment variable", key)) | ||
} |
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,55 @@ | ||
use std::sync::OnceLock; | ||
|
||
use clap::{Parser, Subcommand}; | ||
|
||
#[cfg(feature = "jemalloc")] | ||
#[global_allocator] | ||
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | ||
|
||
fn main() { | ||
if std::env::var("RUST_BACKTRACE").is_err() { | ||
// Enable backtraces on panics by default. | ||
std::env::set_var("RUST_BACKTRACE", "1"); | ||
} | ||
|
||
App::parse().run() | ||
} | ||
|
||
/// Tycho Node | ||
#[derive(Parser)] | ||
#[clap(name = "tycho")] | ||
#[clap(version = version_string())] | ||
#[clap(subcommand_required = true, arg_required_else_help = true)] | ||
struct App { | ||
#[clap(subcommand)] | ||
cmd: Cmd, | ||
} | ||
|
||
impl App { | ||
fn run(self) {} | ||
} | ||
|
||
#[derive(Subcommand)] | ||
enum Cmd { | ||
Init(InitCmd), | ||
Run(RunCmd), | ||
} | ||
|
||
/// Initialize a node environment | ||
#[derive(Parser)] | ||
struct InitCmd {} | ||
|
||
/// Run a node | ||
#[derive(Parser)] | ||
struct RunCmd {} | ||
|
||
fn version_string() -> &'static str { | ||
static STRING: OnceLock<String> = OnceLock::new(); | ||
STRING.get_or_init(|| { | ||
format!("(release {TYCHO_VERSION}) (build {TYCHO_BUILD}) (rustc {RUSTC_VERSION})") | ||
}) | ||
} | ||
|
||
static TYCHO_VERSION: &str = env!("TYCHO_VERSION"); | ||
static TYCHO_BUILD: &str = env!("TYCHO_BUILD"); | ||
static RUSTC_VERSION: &str = env!("TYCHO_RUSTC_VERSION"); |
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
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
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
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