1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Mirrors `webbluetooth-apple`'s capability flag, since a `cfg` emitted by one
//! crate's build script does not reach another's — and embeds the `Info.plist`
//! that macOS reads before it will hand a process Bluetooth.
/// Link this crate's `Info.plist` into every executable it builds: its
/// examples and its test binaries.
///
/// macOS gates Bluetooth behind TCC, which reads
/// `NSBluetoothAlwaysUsageDescription` from the running image's
/// `__TEXT,__info_plist` section. An app bundle supplies it from
/// `Contents/Info.plist`; a bare `cargo run` binary has no bundle, so the
/// section is linked in instead. Without it the process is reported
/// `Unauthorized` and is never prompted — it just sees no adapter.
///
/// # Why here rather than in `.cargo/config.toml`
///
/// That is where this lived, as a `target.'cfg(target_os = "macos")'.rustflags`
/// entry naming `Info.plist` relative to the directory cargo was invoked from.
/// Two things follow from that, both silent:
///
/// * A `.cargo/config.toml` is discovered by walking up from the *invocation*
/// directory, so `cargo build --manifest-path …/webbluetooth/Cargo.toml` run
/// from anywhere else — an IDE, a wrapper script, a parent workspace — never
/// finds it. The build succeeds and produces a binary with no section in it,
/// which fails later as an authorization error with nothing to connect it to
/// the build that caused it.
/// * `cargo package` verifies an archive by compiling it in
/// `target/…/package/<crate>-<version>/`, which is a different workspace
/// root with no `Info.plist` in it, so the link fails outright — on
/// `webbluetooth-apple`'s *build script*, before a line of the crate is
/// compiled. Packaging on a Mac could not pass at all.
///
/// A build script has neither problem: `CARGO_MANIFEST_DIR` is absolute and
/// points at this package wherever it has been unpacked, and
/// `cargo::rustc-link-arg` applies to this package's own executables and not
/// to anyone's build script.