1 fn main() {
2 // ── SDK credentials ──────────────────────────────────────────────────
3 // Load .env from the onde crate root so GresIQ credentials are available
4 // to option_env!() in pulse/client.rs. Consumer apps never set these —
5 // they're Onde Inference's own infrastructure secrets.
6 println!("cargo:rerun-if-changed=.env");
7 let _ = dotenvy::from_filename(
8 std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(".env"),
9 );
10 for var in [
11 "GRESIQ_API_KEY_DEV",
12 "GRESIQ_API_SECRET_DEV",
13 "GRESIQ_API_KEY_PRODUCTION",
14 "GRESIQ_API_SECRET_PRODUCTION",
15 "HF_TOKEN",
16 ] {
17 println!("cargo:rerun-if-env-changed={var}");
18 if let Ok(val) = std::env::var(var) {
19 if !val.is_empty() {
20 println!("cargo:rustc-env={var}={val}");
21 }
22 }
23 }
24
25 // ── UniFFI scaffolding ───────────────────────────────────────────────
26 // Not strictly required when using `uniffi::setup_scaffolding!()` in
27 // lib.rs (the proc-macro approach), but having it here ensures the
28 // build-dep on `uniffi` with `features = ["build"]` is exercised and
29 // keeps compatibility if we ever switch to UDL-based generation.
30
31 // ── Apple: provide missing ___chkstk_darwin symbol ───────────────────
32 //
33 // On macOS, `___chkstk_darwin` is exported by libSystem as a stack
34 // probing function. On arm64 the kernel grows the stack via guard
35 // pages so the probe is effectively a no-op `ret`.
36 //
37 // tvOS, visionOS, and watchOS do NOT export this symbol at all.
38 //
39 // iOS exports it in libSystem, but deployment-target mismatches
40 // between dependencies (e.g. onig_sys built for iOS 26.0 linked
41 // against a min-target of iOS 10.0) can cause the linker to fail
42 // to resolve it. Providing the stub on iOS is harmless — if
43 // libSystem already has the symbol the linker prefers it; if not,
44 // our stub satisfies the reference.
45 //
46 // `aws-lc-sys` assembly (transitive via reqwest → rustls → aws-lc-rs)
47 // references ___chkstk_darwin unconditionally, so we compile a tiny
48 // `ret` stub for all non-macOS Apple targets.
49 let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
50
51 if target_os == "ios"
52 || target_os == "tvos"
53 || target_os == "visionos"
54 || target_os == "watchos"
55 {
56 let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
57 let asm_path = std::path::Path::new(&manifest_dir).join("scripts/tvos_chkstk.s");
58
59 if asm_path.exists() {
60 // Use the `cc` crate to assemble the stub into a static library
61 // that the linker will pick up. If `cc` is not available as a
62 // build-dependency, fall back to printing a cargo link directive
63 // that tells the linker to include the object directly.
64 //
65 // Since `cc` is already a transitive build-dep (pulled in by
66 // aws-lc-sys, ring, etc.), we use it directly.
67 cc::Build::new().file(&asm_path).compile("tvos_chkstk");
68
69 println!("cargo:rerun-if-changed=scripts/tvos_chkstk.s");
70 } else {
71 println!(
72 "cargo:warning=tvos_chkstk.s not found at {} — \
73 ___chkstk_darwin will be unresolved on tvOS",
74 asm_path.display()
75 );
76 }
77 }
78 }