summaryrefslogtreecommitdiffstats
path: root/servo/components/style/build.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /servo/components/style/build.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream/115.8.0esr.tar.xz
firefox-esr-upstream/115.8.0esr.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/components/style/build.rs')
-rw-r--r--servo/components/style/build.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/servo/components/style/build.rs b/servo/components/style/build.rs
new file mode 100644
index 0000000000..2247e87618
--- /dev/null
+++ b/servo/components/style/build.rs
@@ -0,0 +1,91 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#[macro_use]
+extern crate lazy_static;
+
+use std::env;
+use std::path::Path;
+use std::process::{exit, Command};
+use walkdir::WalkDir;
+
+#[cfg(feature = "gecko")]
+mod build_gecko;
+
+#[cfg(not(feature = "gecko"))]
+mod build_gecko {
+ pub fn generate() {}
+}
+
+lazy_static! {
+ pub static ref PYTHON: String = env::var("PYTHON3").ok().unwrap_or_else(|| {
+ let candidates = if cfg!(windows) {
+ ["python3.exe"]
+ } else {
+ ["python3"]
+ };
+ for &name in &candidates {
+ if Command::new(name)
+ .arg("--version")
+ .output()
+ .ok()
+ .map_or(false, |out| out.status.success())
+ {
+ return name.to_owned();
+ }
+ }
+ panic!(
+ "Can't find python (tried {})! Try fixing PATH or setting the PYTHON3 env var",
+ candidates.join(", ")
+ )
+ });
+}
+
+fn generate_properties(engine: &str) {
+ for entry in WalkDir::new("properties") {
+ let entry = entry.unwrap();
+ match entry.path().extension().and_then(|e| e.to_str()) {
+ Some("mako") | Some("rs") | Some("py") | Some("zip") => {
+ println!("cargo:rerun-if-changed={}", entry.path().display());
+ },
+ _ => {},
+ }
+ }
+
+ let script = Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap())
+ .join("properties")
+ .join("build.py");
+
+ let status = Command::new(&*PYTHON)
+ .arg(&script)
+ .arg(engine)
+ .arg("style-crate")
+ .status()
+ .unwrap();
+ if !status.success() {
+ exit(1)
+ }
+}
+
+fn main() {
+ let gecko = cfg!(feature = "gecko");
+ let servo = cfg!(feature = "servo");
+ let l2013 = cfg!(feature = "servo-layout-2013");
+ let l2020 = cfg!(feature = "servo-layout-2020");
+ let engine = match (gecko, servo, l2013, l2020) {
+ (true, false, false, false) => "gecko",
+ (false, true, true, false) => "servo-2013",
+ (false, true, false, true) => "servo-2020",
+ _ => panic!(
+ "\n\n\
+ The style crate requires enabling one of its 'servo' or 'gecko' feature flags \
+ and, in the 'servo' case, one of 'servo-layout-2013' or 'servo-layout-2020'.\
+ \n\n"
+ ),
+ };
+ println!("cargo:rerun-if-changed=build.rs");
+ println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap());
+ generate_properties(engine);
+ build_gecko::generate();
+}