Skip to content

Commit

Permalink
feat: use workspace version in packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Apr 9, 2024
1 parent 210cd5a commit 8bbbc24
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 20 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

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

20 changes: 19 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
[workspace.package]
version = "0.0.1"
edition = "2021"
authors = ["Broxus Team"]
rust-version = "1.77.1"
repository = "https://github.com/broxus/tycho"
license = "MIT OR Apache-2.0"

[workspace]
resolver = "2"
members = ["consensus", "core", "network", "simulator", "storage", "util", "collator", "block-util"]
members = [
"block-util",
"cli",
"collator",
"consensus",
"core",
"network",
"simulator",
"storage",
"util",
]

[profile.release]
debug = true
Expand Down
9 changes: 7 additions & 2 deletions block-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[package]
name = "tycho-block-util"
version = "0.0.1"
edition = "2021"
description = "Shared utilities for blockchain models."
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
Expand Down
36 changes: 36 additions & 0 deletions cli/Cargo.toml
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
87 changes: 87 additions & 0 deletions cli/build.rs
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))
}
55 changes: 55 additions & 0 deletions cli/src/main.rs
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");
8 changes: 6 additions & 2 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "tycho-collator"
version = "0.0.1"
edition = "2021"
description = "A collator node."
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
Expand Down
8 changes: 6 additions & 2 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "tycho-consensus"
version = "0.0.1"
edition = "2021"
description = "DAG-based consensus for external messages queue."
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
Expand Down
10 changes: 7 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "tycho-core"
version = "0.0.1"
edition = "2021"
description = "Basic functionality of peer."
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
Expand All @@ -13,4 +17,4 @@ tycho-storage = { path = "../storage", version = "=0.0.1" }
tycho-util = { path = "../util", version = "=0.0.1" }

[lints]
workspace= true
workspace = true
8 changes: 6 additions & 2 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[package]
name = "tycho-network"
version = "0.0.1"
edition = "2021"
description = "A peer-to-peer networking library."
include = ["src/**/*.rs", "src/**/*.tl"]
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[[example]]
name = "network-node"
Expand Down
9 changes: 7 additions & 2 deletions simulator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
[package]
name = "tycho-simulator"
version = "0.0.1"
edition = "2021"
description = "A network simulation tool."
include = ["src/**/*.rs"]
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[[bin]]
name = "simulator"
path = "src/main.rs"

[dependencies]
# crates.io deps
anyhow = "1"
clap = { version = "4.5.3", features = ["derive"] }
hex = "0.4.3"
Expand Down
12 changes: 8 additions & 4 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "tycho-storage"
version = "0.0.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
anyhow = "1.0.79"
arc-swap = "1.6.0"
bumpalo = "3.14.0"
Expand Down Expand Up @@ -33,6 +36,7 @@ tracing = "0.1"
triomphe = "0.1.11"
weedb = "0.1.1"

# local deps
tycho-block-util = { path = "../block-util" }
tycho-util = { path = "../util" }

Expand Down
8 changes: 6 additions & 2 deletions util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "tycho-util"
version = "0.0.1"
edition = "2021"
description = "Shared utilities for node components."
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
# crates.io deps
Expand Down

0 comments on commit 8bbbc24

Please sign in to comment.