Skip to main content

max / shop

2.6 KB · 59 lines History Blame Raw
1 //! Cut the bundled face, rather than commit one.
2 //!
3 //! The house face is cut from a pinned base by `quasi-type`, and cutting it
4 //! here is what keeps the glyph set and the shipped face from drifting apart: a
5 //! face in the repo would be a second source of truth that nothing rebuilds.
6 //!
7 //! The base is downloaded once into `OUT_DIR` and checksummed against
8 //! `quasi-type`'s pins, so a warm target directory needs no network.
9 //!
10 //! A cold one reaches raw.githubusercontent.com, which rate-limits by IP and
11 //! can fail a container image build. `QUASI_TYPE_MIRROR` in the environment
12 //! names a base URL that is tried first, with the pinned url as the fallback;
13 //! every file is addressed under it by the sha256 the pin already carries, so a
14 //! mirror is a second source rather than a second thing to trust. Nothing here
15 //! reads it: it is `quasi-type`'s own knob, and setting it is what lets a build
16 //! host cover this fetch without shop changing.
17
18 fn main() {
19 println!("cargo:rerun-if-changed=build.rs");
20
21 let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("cargo sets OUT_DIR"));
22 // cut_native writes the ttf and the OFL text and hands back what has to be
23 // exported beside them.
24 let written = match quasi_type::cut_native(
25 &out,
26 &out.join("bases"),
27 false,
28 &[("quasi-mono", "face.ttf")],
29 ) {
30 Ok(written) => written,
31 Err(e) => panic!(
32 "could not cut the bundled face: {e}\n\
33 The base is fetched from its pinned url on the first build and cached in \
34 OUT_DIR after that, so this needs network once per target directory."
35 ),
36 };
37 let face = written
38 .first()
39 .unwrap_or_else(|| panic!("quasi-mono cut no faces"));
40
41 // Both paths come back from cut_native rather than being spelled again here:
42 // the licence file is named for the family (`OFL-QuasiMono.txt`), and a
43 // second spelling of that is a rename away from a build failure.
44 println!("cargo:rustc-env=SHOP_FONT_FACE={}", face.path.display());
45 println!(
46 "cargo:rustc-env=SHOP_FONT_LICENSE={}",
47 face.license_path.display()
48 );
49 println!("cargo:rustc-env=SHOP_FONT_FAMILY={}", face.family);
50 println!("cargo:rustc-env=SHOP_FONT_STYLE={}", face.style);
51 // The style is the base's default instance and is not always `Regular`:
52 // Atkinson Mono's is `ExtraLight`, which is the whole reason shop names a
53 // weight when it renders rather than taking what the file opens at.
54 println!(
55 "cargo:rustc-env=SHOP_FONT_DEFAULT_WEIGHT={}",
56 face.default_weight
57 );
58 }
59