Skip to content

Commit

Permalink
Read from env variables for the default web bundle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bryango committed Mar 12, 2024
1 parent ca1a1bb commit 0cb32d3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
35 changes: 35 additions & 0 deletions crates/bundles/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016-2021 the Tectonic Project
// Licensed under the MIT License.

use std::env;

/// The current hardcoded default prefix for tectonic's web bundle.
const TECTONIC_WEB_BUNDLE_PREFIX_DEFAULT: &str = "https://relay.fullyjustified.net";

/// Environment variable names to look for the bundle URLs.
const LOCKED_VAR: &str = "TECTONIC_WEB_BUNDLE_LOCKED";
const PREFIX_VAR: &str = "TECTONIC_WEB_BUNDLE_PREFIX";

/// Sets the environment variables for the default web bundle.
///
/// `${TECTONIC_WEB_BUNDLE_PREFIX}` would lead to a url in the form of
/// `${TECTONIC_WEB_BUNDLE_PREFIX}/default_bundle.tar`, while the optional
/// "locked" url, `${TECTONIC_WEB_BUNDLE_LOCKED}`, can be used to pin the
/// default bundle to a specific version if specified. This would be useful
/// for reproducible builds.
fn web_bundle_presets() {
// load from env
let web_bundle_locked = env::var(LOCKED_VAR).unwrap_or("".into());
let web_bundle_prefix = match env::var(PREFIX_VAR) {
Ok(x) if !x.is_empty() => x,
_ => TECTONIC_WEB_BUNDLE_PREFIX_DEFAULT.into(),
};

// export to rustc
println!("cargo:rustc-env={LOCKED_VAR}={web_bundle_locked}");
println!("cargo:rustc-env={PREFIX_VAR}={web_bundle_prefix}");
}

fn main() {
web_bundle_presets();
}
15 changes: 13 additions & 2 deletions crates/bundles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,23 @@ impl<B: Bundle + ?Sized> Bundle for Box<B> {
/// 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 `bundles/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())
.expect("TECTONIC_WEB_BUNDLE_PREFIX must be defined at compile time");

// Simply return the locked url when it is specified:
if !web_bundle_locked.is_empty() {
return web_bundle_locked.to_owned();

Check warning on line 123 in crates/bundles/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bundles/src/lib.rs#L123

Added line #L123 was not covered by tests
}

// 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")

Check warning on line 129 in crates/bundles/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bundles/src/lib.rs#L129

Added line #L129 was not covered by tests
} else {
format!("https://relay.fullyjustified.net/default_bundle_v{format_version}.tar")
format!("{web_bundle_prefix}/default_bundle_v{format_version}.tar")
}
}

Expand Down

0 comments on commit 0cb32d3

Please sign in to comment.