diff --git a/build.rs b/build.rs index 11dbe8160..8ca7078db 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 `${TECTONIC_WEB_BUNDLE_PREFIX}` would lead to a url in the form of + // `${TECTONIC_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. Empty variables + // lead to a hardcoded fallback, currently defined in `crates/bundles/src/lib.rs`. + let web_bundle_prefix = env::var("TECTONIC_WEB_BUNDLE_PREFIX").unwrap_or("".to_owned()); + let web_bundle_locked = 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 503dbcac2..45583eeac 100644 --- a/crates/bundles/src/lib.rs +++ b/crates/bundles/src/lib.rs @@ -112,12 +112,23 @@ 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") + .filter(|x| !x.is_empty()) + .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") } }