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 Dec 15, 2023
1 parent c64e524 commit 2967a30
Show file tree
Hide file tree
Showing 2 changed files with 23 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 `${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}");
}
14 changes: 12 additions & 2 deletions crates/bundles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,22 @@ 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").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 122 in crates/bundles/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bundles/src/lib.rs#L122

Added line #L122 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 128 in crates/bundles/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bundles/src/lib.rs#L128

Added line #L128 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 2967a30

Please sign in to comment.