diff --git a/Cargo.lock b/Cargo.lock index 42eefde457..66d3f1891d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,12 +131,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - [[package]] name = "arrayref" version = "0.3.7" @@ -447,7 +441,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.10.0", + "strsim", ] [[package]] @@ -707,41 +701,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.11.1", - "syn 2.0.38", -] - -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core", - "quote", - "syn 2.0.38", -] - [[package]] name = "dashmap" version = "5.5.3" @@ -764,37 +723,6 @@ dependencies = [ "powerfmt", ] -[[package]] -name = "derive_builder" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "derive_builder_macro" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" -dependencies = [ - "derive_builder_core", - "syn 2.0.38", -] - [[package]] name = "diff" version = "0.1.13" @@ -1132,18 +1060,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "getset" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "gimli" version = "0.28.0" @@ -1325,12 +1241,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "idna" version = "0.4.0" @@ -1772,15 +1682,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -2470,6 +2371,7 @@ name = "roc_cli" version = "0.0.1" dependencies = [ "bumpalo", + "chrono", "clap 4.4.6", "cli_utils", "const_format", @@ -2515,7 +2417,6 @@ dependencies = [ "target-lexicon", "tempfile", "ven_pretty", - "vergen-gitcl", ] [[package]] @@ -3754,12 +3655,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "strum" version = "0.24.1" @@ -4064,9 +3959,7 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", - "libc", "num-conv", - "num_threads", "powerfmt", "serde", "time-core", @@ -4477,44 +4370,6 @@ dependencies = [ "typed-arena", ] -[[package]] -name = "vergen" -version = "9.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c32e7318e93a9ac53693b6caccfb05ff22e04a44c7cf8a279051f24c09da286f" -dependencies = [ - "anyhow", - "derive_builder", - "rustversion", - "vergen-lib", -] - -[[package]] -name = "vergen-gitcl" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbdc9746577cb4767f218d320ee0b623d415e8130332f8f562b910b61cc2c4e" -dependencies = [ - "anyhow", - "derive_builder", - "rustversion", - "time", - "vergen", - "vergen-lib", -] - -[[package]] -name = "vergen-lib" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06bee42361e43b60f363bad49d63798d0f42fb1768091812270eca00c784720" -dependencies = [ - "anyhow", - "derive_builder", - "getset", - "rustversion", -] - [[package]] name = "version_check" version = "0.9.4" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index f38214b8b5..73827b5afc 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -101,7 +101,7 @@ pretty_assertions.workspace = true serial_test.workspace = true [build-dependencies] -vergen-gitcl = { version = "1.0.0", features = ["emit_and_set"] } +chrono = "0.4.26" [[bench]] name = "time_bench" diff --git a/crates/cli/build.rs b/crates/cli/build.rs index 3e41c0d339..ac2c95ea08 100644 --- a/crates/cli/build.rs +++ b/crates/cli/build.rs @@ -1,45 +1,59 @@ +use chrono::prelude::*; use std::fs; -use vergen_gitcl::{Emitter, GitclBuilder}; +use std::process::Command; +use std::str; fn main() { - // Emit git information - let git_instructions = GitclBuilder::default() - .commit_timestamp(true) - .sha(true) // Use shorter commit hash - .dirty(true) // Count untracked files as dirty - .build() - .unwrap(); - Emitter::default() - .add_instructions(&git_instructions) - .unwrap() - .emit_and_set() - .unwrap(); + // Rebuild if this build.rs file changes + println!("cargo:rerun-if-changed=build.rs"); - // Read the version file + // The version file is located at the root of the repository let version_file_path = "../../version.txt"; + + // Rebuild if version file changes + println!("cargo:rerun-if-changed={}", version_file_path); + + // Read the version file let version_file_contents = fs::read_to_string(version_file_path).unwrap(); // If the version is "built-from-source", replace it with the git commit information let version = match version_file_contents.trim() { "built-from-source" => { - let commit_hash = std::env::var("VERGEN_GIT_SHA").unwrap(); - let git_dirty_message = match std::env::var("VERGEN_GIT_DIRTY") { - Ok(s) => match s.as_str() { - "true" => " with additional changes", - _ => "", - }, - _ => "", + // Rebuild if a new Git commit is made + println!("cargo:rerun-if-changed=.git/HEAD"); + + // Get the hash of the current commit + let git_describe_output = Command::new("git") + .arg("describe") + .arg("--always") + .arg("--dirty= with changes") // Add a suffix if the working directory is dirty + .output() + .expect("Failed to execute git describe command"); + let git_commit_hash = str::from_utf8(&git_describe_output.stdout) + .expect("Failed to parse git describe output") + .trim(); + + // Get the datetime of the last commit + let git_show_output = Command::new("git") + .arg("show") + .arg("--no-patch") + .arg("--format=%ct") // Outputting a UNIX timestamp is the only way to always use UTC + .output() + .expect("Failed to execute git show command"); + let git_commit_timestamp = { + let timestamp = str::from_utf8(&git_show_output.stdout) + .expect("Failed to parse git show output as a string") + .trim() + .parse::() + .expect("Failed to parse timestamp as an integer"); + DateTime::from_timestamp(timestamp, 0) + .expect("Failed to parse timestamp") + .format("%Y-%m-%d %H:%M:%S") }; - let git_commit_timestamp = std::env::var("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap(); - format!( - "built from commit {}{}, committed at {}", - commit_hash, git_dirty_message, git_commit_timestamp - ) + format!("built from commit {git_commit_hash}, committed at {git_commit_timestamp}") } _ => version_file_contents.trim().to_string(), }; // Emit the version to a build-time environment variable println!("cargo:rustc-env=ROC_VERSION={}", version); - // Rebuild if version.txt changes - println!("cargo:rerun-if-changed={}", version_file_path); }