Skip to content

Commit

Permalink
refactor: use shadow_rs for versions (#523)
Browse files Browse the repository at this point in the history
### Describe your change

Replaces the `common::get_version` util function with the `PKG_VERSION`
variables extracted from `shadow_rs`.

If you know of any other opportunities where we can replace things from
`shadow_rs`, we can add them in this PR as wel..

### Motivation and context

`shadow_rs` makes the old function redundant

### Checklist

- [ ] The change come with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
Yohe-Am authored Dec 12, 2023
1 parent 6dbb239 commit 7815dad
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ swc_ecma_codegen = "=0.144.1"
swc_ecma_parser = "=0.139.0"
swc_ecma_transforms_typescript = "=0.182.3"
swc_ecma_visit = "=0.95.0"
shadow-rs = "0.24"
4 changes: 0 additions & 4 deletions libs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@

pub mod archive;
pub mod typegraph;

pub fn get_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
4 changes: 2 additions & 2 deletions meta-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ actix = "0.13.1"
ctrlc = "3.4.1"
derive_more = "0.99.17"
typegate_engine = { workspace = true, optional = true }
shadow-rs = "0.24"
shadow-rs.workspace = true
env_logger.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
clap_complete.workspace = true
Expand All @@ -92,4 +92,4 @@ insta = "1.34.0"
project-root = "0.2.2"

[build-dependencies]
shadow-rs = "0.24"
shadow-rs.workspace = true
3 changes: 1 addition & 2 deletions meta-cli/src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use colored::Colorize;
use common::get_version;
use std::process::Command;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -51,7 +50,7 @@ impl Action for Doctor {
"global config",
&GlobalConfig::default_path()?.display().to_string(),
);
ui::cols(c, "meta-cli version", get_version());
ui::cols(c, "meta-cli version", crate::build::PKG_VERSION);
match shell(vec!["docker", "--version"]) {
Ok(s) => {
ui::cols(c, "docker version", &s);
Expand Down
6 changes: 3 additions & 3 deletions meta-cli/src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use crate::global_config::GlobalConfig;

use super::{Action, GenArgs};
use crate::build;
use anyhow::{Ok, Result};
use async_trait::async_trait;
use chrono::{Duration, Utc};
use clap::Parser;
use common::get_version;
use self_update::{backends::github::Update, update::UpdateStatus};
use semver::Version;

Expand All @@ -35,7 +35,7 @@ impl Action for Upgrade {
.repo_name("metatype")
.bin_name("meta")
.show_download_progress(true)
.current_version(get_version())
.current_version(build::PKG_VERSION)
.no_confirm(opts.yes);

if let Some(version) = opts.version {
Expand Down Expand Up @@ -64,7 +64,7 @@ pub async fn upgrade_check() -> Result<()> {
let mut local_config = GlobalConfig::load(&config_path).await?;

if local_config.update_check + Duration::days(1) < Utc::now() {
let current_version = get_version();
let current_version = build::PKG_VERSION;
let latest = tokio::task::spawn_blocking(move || {
let update = Update::configure()
.repo_owner("metatypedev")
Expand Down
2 changes: 1 addition & 1 deletion meta-cli/src/deploy/actors/pusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl PusherActor {
Ok(serde_json::json!({
"tg": serde_json::to_string(&tg)?,
"secrets": serde_json::to_string(secrets)?,
"cliVersion": common::get_version()
"cliVersion": crate::build::PKG_VERSION,
}))
}

Expand Down
2 changes: 1 addition & 1 deletion meta-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<()> {
};

if args.version {
println!("meta {}", common::get_version());
println!("meta {}", build::PKG_VERSION);
return Ok(());
}

Expand Down
4 changes: 4 additions & 0 deletions typegate/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ typescript.workspace = true
wasmedge-sdk.workspace = true
wasmedge-sys.workspace = true
wasmedge-types.workspace = true
shadow-rs.workspace = true

[dev-dependencies]
env_logger.workspace = true

[build-dependencies]
shadow-rs.workspace = true
9 changes: 9 additions & 0 deletions typegate/engine/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
// SPDX-License-Identifier: Elastic-2.0

// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
}
5 changes: 4 additions & 1 deletion typegate/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub use deno_core::{resolve_url, resolve_url_or_path};
pub use ext::extensions;
#[rustfmt::skip]
use deno_core as deno_core; // necessary for re-exported macros to work
use shadow_rs::shadow;

shadow!(build);

use crate::interlude::*;

Expand Down Expand Up @@ -132,7 +135,7 @@ pub async fn launch_typegate_deno(
#[deno_core::op2]
#[string]
fn op_get_version() -> &'static str {
common::get_version()
build::PKG_VERSION
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion typegate/standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ sentry = { version = "0.31.8", features = ["anyhow"] }
env_logger.workspace = true
log = "0.4.20"
typegate_engine.workspace = true
common.workspace = true
2 changes: 1 addition & 1 deletion typegate/standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn init_sentry(config: &Config) -> sentry::ClientInitGuard {
sentry::init((
config.sentry_dsn.clone(),
sentry::ClientOptions {
release: Some(Cow::from(common::get_version())),
release: Some(Cow::from(typegate_engine::build::PKG_VERSION)),
environment: Some(Cow::from(env)),
sample_rate: config.sentry_sample_rate,
traces_sample_rate: config.sentry_traces_sample_rate,
Expand Down

0 comments on commit 7815dad

Please sign in to comment.