Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

release_channel: Allow compile time overrides that don't use `include_str!` (#61731)

Cameron Mcloughlinb25d3eeeca04
diff --git a/crates/release_channel/build.rs b/crates/release_channel/build.rs
new file mode 100644
index 00000000000..d87a475f1c2
--- /dev/null
+++ b/crates/release_channel/build.rs
@@ -0,0 +1,11 @@
+fn main() {
+ println!("cargo::rustc-check-cfg=cfg(__do_not_set_zed_release_channel)");
+ println!("cargo::rerun-if-env-changed=ZED_RELEASE_CHANNEL");
+
+ // Enabling this `cfg` will cause a runtime panic if the
+ // `ZED_RELEASE_CHANNEL` env var is not also set. TLDR: don't set the `cfg`
+ // directly, just set the env var (hence the name).
+ if std::env::var("ZED_RELEASE_CHANNEL").is_ok() {
+ println!("cargo::rustc-cfg=__do_not_set_zed_release_channel");
+ }
+}
diff --git a/crates/release_channel/src/lib.rs b/crates/release_channel/src/lib.rs
index ca3aff66e1c..c79ca14b742 100644
--- a/crates/release_channel/src/lib.rs
+++ b/crates/release_channel/src/lib.rs
@@ -12,13 +12,27 @@ const ZED_DOCS_URL: &str = "https://zed.dev/docs";
/// stable | dev | nightly | preview
pub static RELEASE_CHANNEL_NAME: LazyLock<String> = LazyLock::new(|| {
if cfg!(debug_assertions) {
- env::var("ZED_RELEASE_CHANNEL")
- .unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").trim().to_string())
+ env::var("ZED_RELEASE_CHANNEL").unwrap_or_else(|_| compile_time_release_channel_name())
} else {
- include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()
+ compile_time_release_channel_name()
}
});
+/// When a crate in zed is used as a dependency that uses the `crane` nix
+/// library, it vendors each crate separately and builds it in isolation, which
+/// makes the `include_str!` fail.
+///
+/// The build script checks for `$ZED_RELEASE_CHANNEL` and emits the `cfg`
+#[cfg(__do_not_set_zed_release_channel)]
+fn compile_time_release_channel_name() -> String {
+ env!("ZED_RELEASE_CHANNEL").trim().to_string()
+}
+
+#[cfg(not(__do_not_set_zed_release_channel))]
+fn compile_time_release_channel_name() -> String {
+ include_str!("../../zed/RELEASE_CHANNEL").trim().to_string()
+}
+
#[doc(hidden)]
pub static RELEASE_CHANNEL: LazyLock<ReleaseChannel> =
LazyLock::new(|| match ReleaseChannel::from_str(&RELEASE_CHANNEL_NAME) {