Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bryango
Copy link
Contributor

@bryango bryango commented Dec 15, 2023

This PR enables us to override the default web bundle at build time, through the environment variables (or in build.rs):

  • TECTONIC_BUNDLE_PREFIX
  • TECTONIC_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. This is related to #1002 and its resolution in #1132.

Currently, the default web bundle is hardcoded, as observed in #1002. A related issue is the version mismatch between biber and the tectonic bundle #893, which we would like to addressed in #1132 and nixpkgs NixOS/nixpkgs#273740.

P.S. I am very new to rust, so if the code / interface is no good, please help me improve! And thank you for this wonderful package!

@codecov
Copy link

codecov bot commented Dec 15, 2023

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
βœ… Project coverage is 28.10%. Comparing base (96be4fb) to head (e98864c).
⚠️ Report is 35 commits behind head on master.

Files with missing lines Patch % Lines
crates/bundles/src/lib.rs 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1131      +/-   ##
==========================================
- Coverage   28.93%   28.10%   -0.84%     
==========================================
  Files         266      266              
  Lines      178909   202414   +23505     
  Branches   178909   202414   +23505     
==========================================
+ Hits        51774    56889    +5115     
- Misses      54496    64159    +9663     
- Partials    72639    81366    +8727     
Components Coverage Ξ”
tectonic 50.54% <ΓΈ> (ΓΈ)
bridge_core 34.71% <ΓΈ> (+0.48%) ⬆️
bridge_flate 38.82% <ΓΈ> (ΓΈ)
bridge_fontconfig 83.06% <ΓΈ> (-0.37%) ⬇️
bridge_freetype2 92.00% <ΓΈ> (ΓΈ)
bridge_graphite2 βˆ… <ΓΈ> (βˆ…)
bridge_harfbuzz βˆ… <ΓΈ> (βˆ…)
bridge_icu βˆ… <ΓΈ> (βˆ…)
bridge_png 100.00% <ΓΈ> (ΓΈ)
bundles 34.78% <75.00%> (+0.34%) ⬆️
cfg_support 94.84% <ΓΈ> (ΓΈ)
dep_support 0.00% <ΓΈ> (ΓΈ)
docmodel 84.09% <ΓΈ> (ΓΈ)
engine_bibtex 64.32% <ΓΈ> (ΓΈ)
engine_spx2html 0.00% <ΓΈ> (ΓΈ)
engine_xdvipdfmx 55.58% <ΓΈ> (-9.01%) ⬇️
engine_xetex 35.28% <ΓΈ> (-0.46%) ⬇️
errors 47.61% <ΓΈ> (ΓΈ)
geturl 27.16% <ΓΈ> (ΓΈ)
io_base 76.04% <ΓΈ> (ΓΈ)
pdf_io 14.29% <ΓΈ> (+0.11%) ⬆️
status_base 71.76% <ΓΈ> (ΓΈ)
xdv 0.00% <ΓΈ> (ΓΈ)
xetex_format 22.80% <ΓΈ> (ΓΈ)
xetex_layout 42.81% <ΓΈ> (-3.47%) ⬇️

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bryango bryango force-pushed the build-env-web-bundle branch from 2967a30 to 4491480 Compare December 15, 2023 17:45
@bryango bryango changed the title Read from env variables for the default web bundle Allow overriding web bundle in v2 CLI & at build time Dec 16, 2023
@bryango bryango changed the title Allow overriding web bundle in v2 CLI & at build time Allow overriding web bundle in v2 CLI & at build time, fix #1002 Dec 16, 2023
@rm-dr
Copy link
Contributor

rm-dr commented Dec 16, 2023

This is somewhat related to #1121, which completely overhauls Tectonic's bundles (and thus conflicts with the changes here)

Notably, #1121 adds a new bundle format, and setting a variable for just the url prefix won't work. It may be a better idea (even without extra bundles) to have the variable contain the whole URL.

Also, I don't think I understand the difference between the LOCKED and PREFIX variables. Is there any reason to have two? I think one variable that overrides the default bundle url should be enough.

A few more notes about the issue in #1002:

  • Should this be a cli option or a env variable?
  • Why does tectonic new touch the network in the first place? I'd argue that the command should create a skeleton project completely offline (with the default url in tectonic.toml), which can be changed later by the user. This is clearer and doesn't need any extra config options.

@bryango
Copy link
Contributor Author

bryango commented Dec 17, 2023

Hi @rm-dr! Thank you for the comment!

This is somewhat related to #1121, which completely overhauls Tectonic's bundles (and thus conflicts with the changes here)

Wow amazing! I didn't know this before! This is a huge change though. Are you aware of #1122? I think being a member would probably make it easier to land these changes.

Notably, #1121 adds a new bundle format, and setting a variable for just the url prefix won't work. It may be a better idea (even without extra bundles) to have the variable contain the whole URL.

Also, I don't think I understand the difference between the LOCKED and PREFIX variables. Is there any reason to have two? I think one variable that overrides the default bundle url should be enough.

Currently, the bundle url depends on the format_version:

/// webservice.
pub fn get_fallback_bundle_url(format_version: u32) -> String {
// 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()
} else {
format!("https://relay.fullyjustified.net/default_bundle_v{format_version}.tar")
}
}

So the PREFIX variant only modifies the prefix, in this case https://relay.fullyjustified.net, and keeps the version suffix default_bundle_v{format_version}.tar. If this is going away in the future, then only the LOCKED variant is needed. What do you think? Should I simply remove the PREFIX variant?

Should this be a cli option or a env variable?

They are different! Let me clarify:

I think for the runtime override, we should only provide the CLI option, because env variables are more implicit and thus reduce reproducibility. For build time, however, I think env variables are the only way to pass around the customized build constants, so I have to use it.

Why does tectonic new touch the network in the first place? I'd argue that the command should create a skeleton project completely offline (with the default url in tectonic.toml), which can be changed later by the user. This is clearer and doesn't need any extra config options.

AFAIK, tectonic -X new and init:

  • takes a generic web bundle link https://relay.fullyjustified.net/default_bundle_v33.tar,
  • redirects it to a version-locked one, such like https://data1.fullyjustified.net/tlextras-2022.0r0.tar,
  • and finally pins it down in the Tectonic.toml file.

I think this behavior is nice as it maximizes reproducibility. There are some suggestions in issues to put the locked url ...tlextras-2022.0r0.tar in a dedicated Tectonic.lock file. When and if that happens, tectonic -X new and init can be completely offline, as it only needs to write the unlocked link ...default_bundle_v33.tar.

$ tectonic -X init
note: "version 2" Tectonic command-line interface activated
note: creating new document in this directory ($HOME/apps/tectest)
note: connecting to https://relay.fullyjustified.net/default_bundle_v33.tar
note: resolved to https://data1.fullyjustified.net/tlextras-2022.0r0.tar

$ cat Tectonic.toml
[doc]
name = "tectest"
bundle = "https://data1.fullyjustified.net/tlextras-2022.0r0.tar"
...

Note how the url gets redirected and locked down.

@doronbehar
Copy link

I really like the idea of having an environment variable for this, but I also don't understand why we need 2 environment variables, and not only 1.

Besides that, I also support having this environment variable read in runtime and not build time, as this would also help users to test different bundles in a different way, I think there is no advantage in terms of reproducibility between reading this environment variable in runtime vs build time; since Tectonic from different distributions may have different environments anywhere.

I also think it'd be fair for Tectonic to not guarantee reproducibility in case it reads a dedicated environment variable, and there's a conflict with the URL in the Tectonic.toml file. In such a case I think it'd be best to simply print a big warning, saying that we used the URL from the environment variable and not the the URL from Tectonic.toml file.

@bryango
Copy link
Contributor Author

bryango commented Dec 18, 2023

Hi @doronbehar! Thank you very much for the comment!

  1. I am absolutely okay with a single env variable such as TECTONIC_WEB_BUNDLE_URL. As explained above, the PREFIX variant is only introduced for backward compatibility and ease of mirroring. If we decide that it is confusing, I can easily remove it!

  2. When it comes to runtime, I would still prefer explicit flags such as --web-bundle, which can be overridden by a second --web-bundle. This is not yet the current behavior, and I can look into fixing it it has been fixed with the latest commit in this PR.

I think there is no advantage in terms of reproducibility between reading this environment variable in runtime vs build time; since Tectonic from different distributions may have different environments anywhere.

Yes, this is true in reality, but ideally, I would like Tectonic to not read any environment variables at all (at runtime), by design. It's like the new flake-y nix no longer reads the NIXPKGS_* env variables; sure, it makes things a bit more inconvenient, but I like the purity in the UI.

I know @pkgw is probably busy, but since this is now more than a bugfix and related to the UI design, I would very much like to hear your opinion, and I can fix the code accordingly!

@doronbehar
Copy link

2. When it comes to runtime, I would still prefer explicit flags such as --web-bundle, which can be overridden by a second --web-bundle. This is not yet the current behavior, and I can look into fixing it.

I did noticed that the 2nd commit of this PR as of currently is referring to this? But not completely? Maybe it'd be easier for upstream to digest this change only in a PR of its own.

@rm-dr rm-dr mentioned this pull request Dec 18, 2023
@rm-dr
Copy link
Contributor

rm-dr commented Dec 18, 2023

They are different! Let me clarify:

Ah, I see. We really do need a compile-time option for this.
The two-link config is a bit messy, but I see why it's necessary...

and I don't think I know a better way to do this, if we want easy bundle updates through a "default" redirect.

@bryango
Copy link
Contributor Author

bryango commented Dec 19, 2023

Following the suggestion of @doronbehar I have moved the CLI changes to a separate PR #1132. These two PRs are both related to the web bundle interface, but they are technically independent, so it would be easier to review this way.

@bryango bryango force-pushed the build-env-web-bundle branch from 3056a01 to 4491480 Compare December 19, 2023 05:22
@bryango bryango changed the title Allow overriding web bundle in v2 CLI & at build time, fix #1002 Allow overriding web bundle at _build time_ Dec 19, 2023
@pkgw
Copy link
Collaborator

pkgw commented Feb 4, 2024

I've merged #1132, so that this PR becomes a lot smaller.

It does seem reasonable to me to have the default bundle URL be build-time configurable, for specialized applications.

My only comment upon first glance is one of the evergreen ones: these changes should come with corresponding documentation somewhere!

@bryango
Copy link
Contributor Author

bryango commented Feb 5, 2024

My only comment upon first glance is one of the evergreen ones: these changes should come with corresponding documentation somewhere!

Yes indeed! But since #1132 (run time web bundle override) has been merged, this one is no longer a blocking issue for me πŸ˜† But I will try to document it sometime!

@bryango bryango force-pushed the build-env-web-bundle branch from 4491480 to e2fcb53 Compare March 3, 2024 12:51
@bryango bryango marked this pull request as draft March 3, 2024 14:42
@bryango bryango force-pushed the build-env-web-bundle branch from e2fcb53 to 489dfb2 Compare March 4, 2024 15:03
@bryango bryango force-pushed the build-env-web-bundle branch from 489dfb2 to 0cb32d3 Compare March 12, 2024 10:13
@bryango bryango force-pushed the build-env-web-bundle branch from 0cb32d3 to 35c3664 Compare August 21, 2024 05:33
@bryango bryango force-pushed the build-env-web-bundle branch from 35c3664 to dcdadea Compare March 1, 2025 06:52
@bryango bryango marked this pull request as ready for review March 1, 2025 07:44
@bryango
Copy link
Contributor Author

bryango commented Mar 1, 2025

The top level bundle override tectonic --web-bundle -X ... broke after the bundle work:

... so we need this again for downstream reproducible packaging / distribution of tectonic. I have added the relevant documentation in the tectonic book.

It would be great if this patch is considered before the next release; that would make downstream packaging much easier πŸ˜† Thank you! @rm-dr @CraftSpider @pkgw

Update:

  • added a new commit that prints a message when then bundle variable is set; this is good for debugging
  • the test failure seems unrelated; in particular it didn't happen for the previous commit rebased and CI happy now.

@bryango bryango force-pushed the build-env-web-bundle branch from 8cfe3b3 to bc5f6ed Compare June 18, 2025 10:26
@CraftSpider
Copy link
Contributor

I'll have to take some time to familiarize myself with our bundle code, but I'll try to take a look at this.

bryango added 3 commits July 24, 2025 10:37
This commit makes it easy to override the default web bundle through the
environment variables:

- `TECTONIC_BUNDLE_PREFIX`
- `TECTONIC_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.
@bryango bryango force-pushed the build-env-web-bundle branch from bc5f6ed to 6d0219f Compare July 24, 2025 02:38
@bryango bryango force-pushed the build-env-web-bundle branch 6 times, most recently from 6101bd8 to 52f1119 Compare July 27, 2025 02:20
Adds integration tests for the `get_fallback_bundle_url` function
to verify compile-time environment variable behavior.

A helper crate `bundle_env_overrides_test` is created; it is compiled
with different environment variables to properly test the env vars behavior
used in get_fallback_bundle_url.
@bryango bryango force-pushed the build-env-web-bundle branch from 52f1119 to e98864c Compare July 27, 2025 08:25
@bryango
Copy link
Contributor Author

bryango commented Jul 27, 2025

I'd remove this whole build script, and just do an unwrap_or(TECTONIC_BUNDLE_PREFIX_DEFAULT) in lib.rs. The environment variables will be passed through to rustc by default.

This is now done! I added a commit that moves the changes to lib.rs. Note that:

  • Now I remember the reason that I chose to put the variables in build.rs instead of lib.rs is for discoverability: back then I have not yet written docs for these new compile time env vars, so I want it to be in a more visible place. However, docs are now included in the PR, so I guess it's easier for them to reside in lib.rs
  • In the final commit I added some tests for these environment variables. Since we are testing compile time behaviors I created a mini sub crate under /tests/bundle_env_overrides_test and it's compiled by tests/bundle_env_overrides.rs to verify these behaviors.
    • The test turns out to be a bit too complicated than I would like it to be, so feel free to drop it if it feels unnecessarily complex!

Copy link
Contributor

@CraftSpider CraftSpider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does get a bit complicated, but I like that the behavior is tested. There may be a way to simplify it with the ui_test crate or similar in the future, but for now I think this is good to merge. It works on all our many CI setups.

@CraftSpider CraftSpider merged commit f41cacd into tectonic-typesetting:master Jul 28, 2025
27 of 28 checks passed
@CraftSpider
Copy link
Contributor

Thank you for keeping up on this after a whole year and a half of waiting - hopefully a 0.16 release can be cut soon.

@bryango
Copy link
Contributor Author

bryango commented Jul 29, 2025

I should thank you for taking care of the project! Once I experienced Tectonic, I don't want to go back to texlive anymore, so I am just trying my best to help it live on πŸ˜†

There may be a way to simplify it with the ui_test crate or similar in the future, but for now I think this is good to merge. It works on all our many CI setups.

I didn't know about ui_test, I will investigate if it can be simplified with that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants