From 2967a301814781649a511ac8b087e6205a49958d Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Fri, 15 Dec 2023 19:40:53 +0800 Subject: [PATCH] Read from env variables for the default web bundle This commit makes it easy to override the default web bundle through the environment variables: - `TECTONIC_WEB_BUNDLE_PREFIX` - `TECTONIC_WEB_BUNDLE_LOCKED` The PREFIX variable makes it easy for people to track a mirrored bundle, while the LOCKED variable ensures reproducible builds across all CLIs. --- build.rs | 12 +++++++++++- crates/bundles/src/lib.rs | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 11dbe8160..432bcb9c6 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,17 @@ fn main() { // Re-export $TARGET during the build so that our executable tests know // what environment variable CARGO_TARGET_@TARGET@_RUNNER to check when // they want to spawn off executables. - let target = env::var("TARGET").unwrap(); println!("cargo:rustc-env=TARGET={target}"); + + // Set the default web bundle for tectonic to use. + // The `${web_bundle_prefix}` would lead to a url in the form of + // `${web_bundle_prefix}/default_bundle.tar`, while the "locked" url, + // if specified, can be used to pin the default bundle to a specific + // version. This would be useful for reproducible builds. + let web_bundle_prefix: String = env::var("TECTONIC_WEB_BUNDLE_PREFIX") + .unwrap_or("https://relay.fullyjustified.net".to_owned()); + let web_bundle_locked: String = env::var("TECTONIC_WEB_BUNDLE_LOCKED").unwrap_or("".to_owned()); + println!("cargo:rustc-env=TECTONIC_WEB_BUNDLE_PREFIX={web_bundle_prefix}"); + println!("cargo:rustc-env=TECTONIC_WEB_BUNDLE_LOCKED={web_bundle_locked}"); } diff --git a/crates/bundles/src/lib.rs b/crates/bundles/src/lib.rs index 6ff8bd0ee..2dfd46119 100644 --- a/crates/bundles/src/lib.rs +++ b/crates/bundles/src/lib.rs @@ -112,12 +112,22 @@ impl Bundle for Box { /// low-level reliability problems and was blocked in China. We now use a custom /// webservice. pub fn get_fallback_bundle_url(format_version: u32) -> String { + // Build time environment variables declared in `build.rs`: + let web_bundle_locked = option_env!("TECTONIC_WEB_BUNDLE_LOCKED").unwrap_or(""); + let web_bundle_prefix = + option_env!("TECTONIC_WEB_BUNDLE_PREFIX").unwrap_or("https://relay.fullyjustified.net"); + + // Simply return the locked url when it is specified: + if !web_bundle_locked.is_empty() { + return web_bundle_locked.to_owned(); + } + // Format version 32 (TeXLive 2021) was when we introduced versioning to the // URL. if format_version < 32 { - "https://relay.fullyjustified.net/default_bundle.tar".to_owned() + format!("{web_bundle_prefix}/default_bundle.tar") } else { - format!("https://relay.fullyjustified.net/default_bundle_v{format_version}.tar") + format!("{web_bundle_prefix}/default_bundle_v{format_version}.tar") } }