fix: compiling on windows requires cosmic-icons in project root
* fix: compiling on windows requires cosmic-icons in project root crabtime provides crabtime::WORKSPACE_PATH to refer to the CARGO_MANIFEST_DIR of the top level crate being built, which means when building libcosmic directly, crabtime::WORKSPACE_PATH will work, but when building it as a dependency of another crate, crabtime::WORKSPACE_PATH will no longer refer to the path to libcosmic. I don't think there's a good workaround, since when in the context of crabtime, CARGO_MANIFEST_DIR refers to the path to the crate generated by crabtime rather than to libcosmic. This replaces crabtime with a simple build.rs script that generates a file in OUT_DIR. * fix: do not generate icon bundle for unix targets --------- Co-authored-by: Michael Aaron Murphy <michael@mmurphy.dev>
This commit is contained in:
parent
18182e5f97
commit
80875d5962
3 changed files with 57 additions and 45 deletions
|
|
@ -107,8 +107,6 @@ cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-c
|
|||
chrono = "0.4.42"
|
||||
cosmic-config = { path = "cosmic-config" }
|
||||
cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon", optional = true }
|
||||
# Compile-time generation of code
|
||||
crabtime = "1.1.4"
|
||||
# Internationalization
|
||||
i18n-embed = { version = "0.16.0", features = [
|
||||
"fluent-system",
|
||||
|
|
|
|||
56
build.rs
Normal file
56
build.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
fn main() {
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
|
||||
#[cfg(not(unix))]
|
||||
generate_bundled_icons();
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn generate_bundled_icons() {
|
||||
println!("cargo::rerun-if-changed=cosmic-icons");
|
||||
|
||||
let manifest_dir = std::path::Path::new(std::env!("CARGO_MANIFEST_DIR"));
|
||||
let icon_paths = [
|
||||
"cosmic-icons/freedesktop/scalable",
|
||||
"cosmic-icons/extra/scalable",
|
||||
];
|
||||
|
||||
let key_value_assignments = icon_paths
|
||||
.into_iter()
|
||||
.map(|path| manifest_dir.join(path))
|
||||
.inspect(|icon_path| assert!(icon_path.exists(), "path = {icon_path:?}"))
|
||||
.map(|icon_path| std::fs::read_dir(icon_path).unwrap())
|
||||
.flat_map(|dir| {
|
||||
dir.flat_map(|entry| entry.unwrap().path().read_dir().unwrap())
|
||||
.map(|entry| {
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path().canonicalize().unwrap();
|
||||
let file_name = path.file_stem().unwrap().to_str().unwrap().to_owned();
|
||||
let path = path.into_os_string().into_string().unwrap();
|
||||
(file_name, path)
|
||||
})
|
||||
})
|
||||
.fold(
|
||||
std::collections::BTreeMap::new(),
|
||||
|mut set, (name, path)| {
|
||||
set.insert(name, path);
|
||||
set
|
||||
},
|
||||
)
|
||||
.into_iter()
|
||||
.fold(String::new(), |mut output, (name, path)| {
|
||||
output.push_str(&format!(" \"{name}\" => include_bytes!(\"{path}\"),\n"));
|
||||
output
|
||||
});
|
||||
|
||||
let code = [
|
||||
"static ICONS: phf::Map<&'static str, &'static [u8]> = phf::phf_map!(\n",
|
||||
&key_value_assignments,
|
||||
");",
|
||||
]
|
||||
.concat();
|
||||
|
||||
let out_dir = std::env::var_os("OUT_DIR").unwrap();
|
||||
let out_file = std::path::Path::new(&out_dir).join("bundled_icons.rs");
|
||||
std::fs::write(&out_file, &code).unwrap();
|
||||
}
|
||||
|
|
@ -18,46 +18,4 @@ pub fn get(icon_name: &str) -> Option<super::Data> {
|
|||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[crabtime::expression]
|
||||
fn comptime_icon_bundler() -> String {
|
||||
let manifest_dir = std::path::Path::new(crabtime::WORKSPACE_PATH);
|
||||
let icon_paths = [
|
||||
"cosmic-icons/freedesktop/scalable",
|
||||
"cosmic-icons/extra/scalable",
|
||||
];
|
||||
|
||||
let key_value_assignments = icon_paths
|
||||
.into_iter()
|
||||
.map(|path| manifest_dir.join(path))
|
||||
.inspect(|icon_path| assert!(icon_path.exists(), "path = {icon_path:?}"))
|
||||
.map(|icon_path| std::fs::read_dir(icon_path).unwrap())
|
||||
.flat_map(|dir| {
|
||||
dir.flat_map(|entry| entry.unwrap().path().read_dir().unwrap())
|
||||
.map(|entry| {
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path().canonicalize().unwrap();
|
||||
let file_name = path.file_stem().unwrap().to_str().unwrap().to_owned();
|
||||
let path = path.into_os_string().into_string().unwrap();
|
||||
(file_name, path)
|
||||
})
|
||||
})
|
||||
.fold(
|
||||
std::collections::BTreeMap::new(),
|
||||
|mut set, (name, path)| {
|
||||
set.insert(name, path);
|
||||
set
|
||||
},
|
||||
)
|
||||
.into_iter()
|
||||
.fold(String::new(), |mut output, (name, path)| {
|
||||
output.push_str(&format!(" \"{name}\" => include_bytes!(\"{path}\"),\n"));
|
||||
output
|
||||
});
|
||||
|
||||
["phf::phf_map!(\n", &key_value_assignments, ")"].concat()
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
static ICONS: phf::Map<&'static str, &'static [u8]> = {
|
||||
comptime_icon_bundler! {}
|
||||
};
|
||||
include!(concat!(env!("OUT_DIR"), "/bundled_icons.rs"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue