1#![no_std]
2#![deny(missing_docs)]
3#[cfg(feature = "vendor")]
6extern crate std;
7
8#[cfg(feature = "embed")]
9pub mod embed {
11 use phf::{Map, phf_map};
12
13 pub const MEDIA_SPLASH_RAW: &[u8] =
14 include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../media/splash.raw"));
15 pub const MEDIA_ALCHEMIST_404_RAW: &[u8] = include_bytes!(concat!(
16 env!("CARGO_MANIFEST_DIR"),
17 "/../media/alchemist-404.raw"
18 ));
19 pub const MEDIA_ALCHEMIST_500_RAW: &[u8] = include_bytes!(concat!(
20 env!("CARGO_MANIFEST_DIR"),
21 "/../media/alchemist-500.raw"
22 ));
23 pub const MEDIA_OAK_WOOD_GRAIN_RAW: &[u8] = include_bytes!(concat!(
24 env!("CARGO_MANIFEST_DIR"),
25 "/../media/oak-wood-grain.raw"
26 ));
27 pub const ICON_FAVICON_RAW: &[u8] =
28 include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/favicon.raw"));
29 pub const ICON_FILE_RAW: &[u8] =
30 include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/file.raw"));
31 pub const ICON_GLOBE_RAW: &[u8] =
32 include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/globe.raw"));
33 pub const ICON_SOFT_O_OUTLINE_YELLOW_RAW: &[u8] = include_bytes!(concat!(
34 env!("CARGO_MANIFEST_DIR"),
35 "/../icons/soft-o-outline-yellow.raw"
36 ));
37 pub const ICON_SOFTOBOROS_LETTER_LOGO_RAW: &[u8] = include_bytes!(concat!(
38 env!("CARGO_MANIFEST_DIR"),
39 "/../icons/softoboros-letter-logo.raw"
40 ));
41 pub const ICON_WINDOW_RAW: &[u8] =
42 include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../icons/window.raw"));
43
44 static INDEX: Map<&'static str, &'static [u8]> = phf_map! {
45
46 "media/splash.raw" => MEDIA_SPLASH_RAW,
47 "media/alchemist-404.raw" => MEDIA_ALCHEMIST_404_RAW,
48 "media/alchemist-500.raw" => MEDIA_ALCHEMIST_500_RAW,
49 "media/oak-wood-grain.raw" => MEDIA_OAK_WOOD_GRAIN_RAW,
50 "icons/favicon.raw" => ICON_FAVICON_RAW,
51 "icons/file.raw" => ICON_FILE_RAW,
52 "icons/globe.raw" => ICON_GLOBE_RAW,
53 "icons/soft-o-outline-yellow.raw" => ICON_SOFT_O_OUTLINE_YELLOW_RAW,
54 "icons/softoboros-letter-logo.raw" => ICON_SOFTOBOROS_LETTER_LOGO_RAW,
55 "icons/window.raw" => ICON_WINDOW_RAW,
56
57 };
58
59 pub fn get(path: &str) -> Option<&'static [u8]> {
61 INDEX.get(path).copied()
62 }
63}
64
65#[cfg(feature = "vendor")]
66pub mod vendor {
68 use std::path::Path;
69
70 pub fn copy_all(out_dir: &Path) -> std::io::Result<()> {
72 vendor_api::copy_all(out_dir, ASSETS)
73 }
74
75 pub fn generate_rust_module(out_dir: &Path) -> std::io::Result<()> {
77 vendor_api::generate_rust_module(out_dir, ASSETS)
78 }
79
80 const ASSETS: &[(&str, &str)] = &[
81 ("MEDIA_SPLASH_RAW", "media/splash.raw"),
82 ("MEDIA_ALCHEMIST_404_RAW", "media/alchemist-404.raw"),
83 ("MEDIA_ALCHEMIST_500_RAW", "media/alchemist-500.raw"),
84 ("MEDIA_OAK_WOOD_GRAIN_RAW", "media/oak-wood-grain.raw"),
85 ("ICON_FAVICON_RAW", "icons/favicon.raw"),
86 ("ICON_FILE_RAW", "icons/file.raw"),
87 ("ICON_GLOBE_RAW", "icons/globe.raw"),
88 (
89 "ICON_SOFT_O_OUTLINE_YELLOW_RAW",
90 "icons/soft-o-outline-yellow.raw",
91 ),
92 (
93 "ICON_SOFTOBOROS_LETTER_LOGO_RAW",
94 "icons/softoboros-letter-logo.raw",
95 ),
96 ("ICON_WINDOW_RAW", "icons/window.raw"),
97 ];
98
99 mod vendor_api {
100 use std::{format, fs, path::Path, string::String};
101
102 pub fn copy_all(out_dir: &Path, assets: &[(&str, &str)]) -> std::io::Result<()> {
103 let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../");
104 for (_, path) in assets {
105 let src = root.join(path);
106 let dest = out_dir.join(path);
107 if let Some(parent) = dest.parent() {
108 fs::create_dir_all(parent)?;
109 }
110 fs::copy(&src, &dest)?;
111 }
112 Ok(())
113 }
114
115 pub fn generate_rust_module(
116 out_dir: &Path,
117 assets: &[(&str, &str)],
118 ) -> std::io::Result<()> {
119 let mut module = String::from("//! Auto-generated asset constants\n\n");
120 for (name, path) in assets {
121 module.push_str(&format!(
122 "pub const {}: &[u8] = include_bytes!(\"{}\");\n",
123 name, path
124 ));
125 }
126 fs::write(out_dir.join("rlvgl_assets.rs"), module)?;
127 Ok(())
128 }
129 }
130}