Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding web bundle at _build time_ #1131

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/// 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