From a7ecae426e40ac84bbf159a27cebae5d7c52cec1 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Tue, 26 Sep 2023 21:35:06 +0200 Subject: [PATCH] Only enable vergen on docsrs --- Cargo.toml | 5 ++++- build.rs | 12 ++++++++++++ src/lib.rs | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 35c1968e..72a28abc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,9 @@ regex = ["dep:regex-automata"] # Enable serde serialization support serde = ["dep:serde"] +# Enable dependencies only needed for generation of documentation on docs.rs +docsrs = ["dep:vergen"] + # An alias of all features that work with the stable compiler. # Do not use this feature, its removal is not considered a breaking change and its behaviour may change. # If you're working on chumsky and you're adding a feature that does not require nightly support, please add it to this list. @@ -94,7 +97,7 @@ lasso = "0.7" slotmap = "1.0" [build-dependencies] -vergen = { version = "=8.1.1", features = ["git", "gitoxide"] } +vergen = { version = "=8.1.1", optional = true, features = ["git", "gitoxide"] } [target.'cfg(unix)'.dev-dependencies] pprof = { version = "0.11", features = ["flamegraph", "criterion"] } diff --git a/build.rs b/build.rs index 35aa44a6..fecd361b 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,20 @@ use std::error::Error; +#[cfg(feature = "docsrs")] use vergen::EmitBuilder; fn main() -> Result<(), Box> { + emit_git_metadata()?; + Ok(()) +} + +#[cfg(feature = "docsrs")] +fn emit_git_metadata() -> Result<(), Box> { // Emit the instructions EmitBuilder::builder().all_git().emit()?; Ok(()) } + +#[cfg(not(feature = "docsrs"))] +fn emit_git_metadata() -> Result<(), Box> { + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index c5fd11b0..0c718e9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ extern crate alloc; extern crate core; +#[cfg(feature = "docsrs")] macro_rules! blob_url_prefix { () => { concat!( @@ -34,6 +35,16 @@ macro_rules! blob_url_prefix { }; } +#[cfg(not(feature = "docsrs"))] +macro_rules! blob_url_prefix { + () => { + concat!( + "https://github.com/zesterer/chumsky/blob/", + env!("CARGO_PKG_VERSION") + ) + }; +} + macro_rules! go_extra { ( $O :ty ) => { #[inline(always)]