-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rework build and some dependencies
Signed-off-by: tison <[email protected]>
- Loading branch information
Showing
22 changed files
with
839 additions
and
590 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ members = [ | |
resolver = "2" | ||
|
||
[workspace.package] | ||
version = "5.7.0" | ||
version = "5.8.0" | ||
edition = "2021" | ||
authors = ["tison <[email protected]>"] | ||
readme = "README.md" | ||
|
@@ -32,10 +32,14 @@ repository = "https://github.com/korandoru/hawkeye/" | |
rust-version = "1.76.0" | ||
|
||
[workspace.dependencies] | ||
anyhow = "1.0" | ||
build-data = "0.2" | ||
clap = { version = "4.5", features = ["derive", "string", "cargo"] } | ||
const_format = { version = "0.2" } | ||
hawkeye-fmt = { version = "5.7.0", path = "fmt" } | ||
snafu = "0.8.2" | ||
toml = "0.8.12" | ||
tracing = "0.1.40" | ||
log = { version = "0.4", features = ["kv_unstable_serde", "serde"] } | ||
shadow-rs = "0.32" | ||
toml = "0.8" | ||
|
||
[workspace.metadata.release] | ||
sign-tag = 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
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 |
---|---|---|
|
@@ -15,69 +15,36 @@ | |
// Copyright 2024 - 2024, tison <[email protected]> and the HawkEye contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::{borrow::Cow, sync::OnceLock}; | ||
use std::collections::BTreeSet; | ||
use std::env; | ||
|
||
const UNKNOWN: &str = "unknown"; | ||
use build_data::format_timestamp; | ||
use build_data::get_source_time; | ||
use shadow_rs::CARGO_METADATA; | ||
use shadow_rs::CARGO_TREE; | ||
|
||
pub struct BuildInfo { | ||
pub branch: Cow<'static, str>, | ||
pub commit: Cow<'static, str>, | ||
pub commit_short: Cow<'static, str>, | ||
pub dirty: Cow<'static, str>, | ||
pub timestamp: Cow<'static, str>, | ||
|
||
/// Rustc Version | ||
pub rustc: Cow<'static, str>, | ||
/// GreptimeDB Version | ||
pub version: Cow<'static, str>, | ||
} | ||
|
||
static BUILD: OnceLock<BuildInfo> = OnceLock::new(); | ||
|
||
pub fn build_info() -> &'static BuildInfo { | ||
BUILD.get_or_init(|| { | ||
let branch = build_data::get_git_branch() | ||
.map(Cow::Owned) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let commit = build_data::get_git_commit() | ||
.map(Cow::Owned) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let commit_short = build_data::get_git_commit_short() | ||
.map(Cow::Owned) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let dirty = build_data::get_git_dirty() | ||
.map(|b| Cow::Owned(b.to_string())) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let timestamp = build_data::get_source_time() | ||
.map(|ts| Cow::Owned(build_data::format_timestamp(ts))) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let rustc = build_data::get_rustc_version() | ||
.map(Cow::Owned) | ||
.unwrap_or(Cow::Borrowed(UNKNOWN)); | ||
let version = Cow::Borrowed(env!("CARGO_PKG_VERSION")); | ||
|
||
BuildInfo { | ||
branch, | ||
commit, | ||
commit_short, | ||
dirty, | ||
timestamp, | ||
rustc, | ||
version, | ||
} | ||
}) | ||
} | ||
|
||
fn main() { | ||
let build_info = build_info(); | ||
println!("cargo:rustc-env=GIT_COMMIT={}", build_info.commit); | ||
fn main() -> shadow_rs::SdResult<()> { | ||
println!("cargo:rerun-if-changed=.git/refs/heads"); | ||
println!( | ||
"cargo:rustc-env=GIT_COMMIT_SHORT={}", | ||
build_info.commit_short | ||
"cargo:rustc-env=SOURCE_TIMESTAMP={}", | ||
if let Ok(t) = get_source_time() { | ||
format_timestamp(t) | ||
} else { | ||
"".to_string() | ||
} | ||
); | ||
println!("cargo:rustc-env=GIT_BRANCH={}", build_info.branch); | ||
println!("cargo:rustc-env=GIT_DIRTY={}", build_info.dirty); | ||
println!("cargo:rustc-env=GIT_DIRTY={}", build_info.dirty); | ||
println!("cargo:rustc-env=RUSTC_VERSION={}", build_info.rustc); | ||
println!("cargo:rustc-env=SOURCE_TIMESTAMP={}", build_info.timestamp); | ||
build_data::set_BUILD_TIMESTAMP(); | ||
|
||
// The "CARGO_WORKSPACE_DIR" is set manually (not by Rust itself) in Cargo config file, to | ||
// solve the problem where the "CARGO_MANIFEST_DIR" is not what we want when this repo is | ||
// made as a submodule in another repo. | ||
let src_path = env::var("CARGO_WORKSPACE_DIR").or_else(|_| env::var("CARGO_MANIFEST_DIR"))?; | ||
let out_path = env::var("OUT_DIR")?; | ||
let _ = shadow_rs::Shadow::build_with( | ||
src_path, | ||
out_path, | ||
// exclude these two large constants that we don't need | ||
BTreeSet::from([CARGO_METADATA, CARGO_TREE]), | ||
)?; | ||
Ok(()) | ||
} |
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 |
---|---|---|
|
@@ -15,47 +15,25 @@ | |
// Copyright 2024 - 2024, tison <[email protected]> and the HawkEye contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use clap::{crate_description, FromArgMatches, Subcommand}; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; | ||
use clap::crate_description; | ||
use clap::FromArgMatches; | ||
use clap::Subcommand; | ||
use env_logger::Env; | ||
|
||
use crate::cli::SubCommand; | ||
use crate::subcommand::SubCommand; | ||
|
||
pub mod cli; | ||
pub mod subcommand; | ||
pub mod version; | ||
|
||
fn version() -> &'static str { | ||
concat!( | ||
"\nbranch: ", | ||
env!("GIT_BRANCH"), | ||
"\ncommit: ", | ||
env!("GIT_COMMIT"), | ||
"\ndirty: ", | ||
env!("GIT_DIRTY"), | ||
"\nversion: v", | ||
env!("CARGO_PKG_VERSION"), | ||
"\ntoolchain: ", | ||
env!("RUSTC_VERSION"), | ||
"\nbuild: ", | ||
env!("SOURCE_TIMESTAMP"), | ||
) | ||
} | ||
|
||
fn main() -> hawkeye_fmt::Result<()> { | ||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with( | ||
EnvFilter::builder() | ||
.with_default_directive(LevelFilter::INFO.into()) | ||
.from_env_lossy(), | ||
) | ||
.init(); | ||
fn main() { | ||
env_logger::init_from_env(Env::new().default_filter_or("info")); | ||
|
||
let cli = clap::Command::new("hawkeye") | ||
let command = clap::Command::new("hawkeye") | ||
.subcommand_required(true) | ||
.version(version()) | ||
.version(version::version()) | ||
.about(crate_description!()); | ||
let cli = SubCommand::augment_subcommands(cli); | ||
let args = cli.get_matches(); | ||
let command = SubCommand::augment_subcommands(command); | ||
let args = command.get_matches(); | ||
match SubCommand::from_arg_matches(&args) { | ||
Ok(cmd) => cmd.run(), | ||
Err(e) => e.exit(), | ||
|
Oops, something went wrong.