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 3, 2024
1 parent b19a34a commit e2fcb53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 11 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
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 `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())

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

View check run for this annotation

Codecov / codecov/patch

crates/bundles/src/lib.rs#L118

Added line #L118 was not covered by tests
.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();

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 e2fcb53

Please sign in to comment.