diff --git a/Cargo.lock b/Cargo.lock index f4299c78b8..42eefde457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,12 @@ 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" @@ -384,11 +390,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -441,7 +447,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.10.0", ] [[package]] @@ -701,6 +707,41 @@ 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" @@ -723,6 +764,37 @@ 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" @@ -1060,6 +1132,18 @@ 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" @@ -1241,6 +1325,12 @@ 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" @@ -1656,6 +1746,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.17" @@ -1676,6 +1772,15 @@ 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" @@ -1864,9 +1969,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1932,9 +2037,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -2410,6 +2515,7 @@ dependencies = [ "target-lexicon", "tempfile", "ven_pretty", + "vergen-gitcl", ] [[package]] @@ -3297,9 +3403,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rusty-fork" @@ -3527,6 +3633,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook" version = "0.3.17" @@ -3642,6 +3754,12 @@ 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" @@ -3940,12 +4058,15 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "libc", + "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -3960,10 +4081,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -4355,6 +4477,44 @@ 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 cd3ecedb87..f38214b8b5 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -2,6 +2,7 @@ name = "roc_cli" description = "The Roc binary that brings together all functionality in the Roc toolset." default-run = "roc" +build = "build.rs" authors.workspace = true edition.workspace = true @@ -30,7 +31,13 @@ target-wasm32 = ["roc_build/target-wasm32"] target-x86 = ["roc_build/target-x86", "roc_repl_cli/target-x86"] target-x86_64 = ["roc_build/target-x86_64", "roc_repl_cli/target-x86_64"] -target-all = ["target-aarch64", "target-arm", "target-x86", "target-x86_64", "target-wasm32"] +target-all = [ + "target-aarch64", + "target-arm", + "target-x86", + "target-x86_64", + "target-wasm32", +] sanitizers = ["roc_build/sanitizers"] @@ -93,6 +100,9 @@ parking_lot.workspace = true pretty_assertions.workspace = true serial_test.workspace = true +[build-dependencies] +vergen-gitcl = { version = "1.0.0", features = ["emit_and_set"] } + [[bench]] name = "time_bench" harness = false diff --git a/crates/cli/build.rs b/crates/cli/build.rs new file mode 100644 index 0000000000..3e41c0d339 --- /dev/null +++ b/crates/cli/build.rs @@ -0,0 +1,45 @@ +use std::fs; +use vergen_gitcl::{Emitter, GitclBuilder}; + +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(); + + // Read the version file + let version_file_path = "../../version.txt"; + 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", + _ => "", + }, + _ => "", + }; + 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 + ) + } + _ => 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); +} diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index b0b2e08e1d..b69abd4b38 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -88,7 +88,7 @@ pub const FLAG_PP_HOST: &str = "host"; pub const FLAG_PP_PLATFORM: &str = "platform"; pub const FLAG_PP_DYLIB: &str = "lib"; -const VERSION: &str = include_str!("../../../version.txt"); +pub const VERSION: &str = env!("ROC_VERSION"); const DEFAULT_GENERATED_DOCS_DIR: &str = "generated-docs"; pub fn build_app() -> Command { @@ -180,7 +180,7 @@ pub fn build_app() -> Command { PossibleValuesParser::new(Target::iter().map(Into::<&'static str>::into)); Command::new("roc") - .version(concatcp!(VERSION, "\n")) + .version(VERSION) .about("Run the given .roc file, if there are no compilation errors.\nYou can use one of the SUBCOMMANDS below to do something else!") .args_conflicts_with_subcommands(true) .subcommand(Command::new(CMD_BUILD) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index abe4319648..16fc1f76ce 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -7,7 +7,7 @@ use roc_cli::{ CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL, CMD_RUN, CMD_TEST, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, FLAG_PP_PLATFORM, FLAG_STDIN, - FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE, + FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE, VERSION, }; use roc_docs::generate_docs_html; use roc_error_macros::user_error; @@ -22,7 +22,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use target_lexicon::Triple; -#[macro_use] extern crate const_format; #[global_allocator] @@ -358,11 +357,7 @@ fn main() -> io::Result<()> { Ok(format_exit_code) } Some((CMD_VERSION, _)) => { - print!( - "{}", - concatcp!("roc ", include_str!("../../../version.txt")) - ); - + println!("roc {}", VERSION); Ok(0) } _ => unreachable!(),