1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | use crate::cbindgen::EnabledFeatures; |
5 | use std::path::Path; |
6 | mod cbindgen; |
7 | |
8 | fn main() -> Result<(), anyhow::Error> { |
9 | let manifest_dir: OsString = std::env::var_os(key:"CARGO_MANIFEST_DIR" ).unwrap(); |
10 | |
11 | // Go from $root/api/cpp down to $root |
12 | let root_dir: &Path = Path::new(&manifest_dir).ancestors().nth(2).expect(&format!( |
13 | "Failed to locate root directory, relative to {}" , |
14 | manifest_dir.to_string_lossy() |
15 | )); |
16 | |
17 | let output_dir: OsString = std::env::var_os(key:"SLINT_GENERATED_INCLUDE_DIR" ).unwrap_or_else(|| { |
18 | Path::new(&std::env::var_os("OUT_DIR" ).unwrap()).join(path:"generated_include" ).into() |
19 | }); |
20 | let output_dir: &Path = Path::new(&output_dir); |
21 | |
22 | println!("cargo:GENERATED_INCLUDE_DIR= {}" , output_dir.display()); |
23 | |
24 | let enabled_features: EnabledFeatures = EnabledFeatures::from_env(); |
25 | |
26 | let dependencies: Vec = cbindgen::gen_all(&root_dir, &output_dir, enabled_features)?; |
27 | for path: PathBuf in dependencies { |
28 | println!("cargo:rerun-if-changed= {}" , path.display()); |
29 | } |
30 | Ok(()) |
31 | } |
32 | |