Skip to main content

cageforge_bwrap/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Bubblewrap builder and embedded Linux resources.
4
5#![deny(missing_docs)]
6
7#[cfg(target_os = "linux")]
8mod embedded {
9    // These bytes are executables produced from the pinned, original
10    // Bubblewrap sources in `vendor/bubblewrap/`; they are not Cageforge Rust
11    // code.
12    #[cfg(all(feature = "embedded", target_arch = "x86_64"))]
13    pub(super) const BINARY: &[u8] = include_bytes!("../assets/linux-x86_64/bwrap");
14
15    #[cfg(all(feature = "embedded", target_arch = "x86_64"))]
16    pub(super) const DIGEST: &str = include_str!("../assets/linux-x86_64/bwrap.sha256");
17
18    #[cfg(all(feature = "embedded", target_arch = "aarch64"))]
19    pub(super) const BINARY: &[u8] = include_bytes!("../assets/linux-aarch64/bwrap");
20
21    #[cfg(all(feature = "embedded", target_arch = "aarch64"))]
22    pub(super) const DIGEST: &str = include_str!("../assets/linux-aarch64/bwrap.sha256");
23}
24
25/// Returns the reviewed Bubblewrap executable built for this Linux target.
26///
27/// The bytes are embedded in the library so a downstream application can
28/// materialize the bundled resource without relying on Cargo's private
29/// `OUT_DIR` or a local C toolchain after compilation. They are built from the
30/// original upstream Bubblewrap sources and remain covered by the accompanying
31/// LGPL license.
32#[cfg(all(target_os = "linux", feature = "embedded"))]
33pub fn bundled_bubblewrap() -> &'static [u8] {
34    embedded::BINARY
35}
36
37/// Returns the expected SHA-256 digest for the embedded executable.
38#[cfg(all(target_os = "linux", feature = "embedded"))]
39pub fn bundled_bubblewrap_sha256() -> &'static str {
40    embedded::DIGEST.trim()
41}