From 2ebb71f08a9e2521a2fd277c2bc2b54b9e21dd8d Mon Sep 17 00:00:00 2001 From: webbeef Date: Fri, 9 Aug 2024 02:16:51 -0700 Subject: [PATCH] Set the cfg properly for the production-stripped profile (#32991) Signed-off-by: webbeef --- components/fonts/Cargo.toml | 3 +++ components/shared/embedder/build.rs | 11 +++++++++-- ports/servoshell/build.rs | 11 +++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/components/fonts/Cargo.toml b/components/fonts/Cargo.toml index a0301ceaad8..120e16037f4 100644 --- a/components/fonts/Cargo.toml +++ b/components/fonts/Cargo.toml @@ -49,6 +49,9 @@ webrender_api = { workspace = true } webrender_traits = { workspace = true } xi-unicode = { workspace = true } +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ohos_mock)'] } + [target.'cfg(target_os = "macos")'.dependencies] byteorder = { workspace = true } core-foundation = "0.9" diff --git a/components/shared/embedder/build.rs b/components/shared/embedder/build.rs index 25c737ffaa9..06e47f2099b 100644 --- a/components/shared/embedder/build.rs +++ b/components/shared/embedder/build.rs @@ -6,14 +6,21 @@ use std::error::Error; use std::path::Path; fn main() -> Result<(), Box> { + println!("cargo::rustc-check-cfg=cfg(servo_production)"); + println!("cargo::rustc-check-cfg=cfg(servo_do_not_use_in_production)"); // Cargo does not expose the profile name to crates or their build scripts, // but we can extract it from OUT_DIR and set a custom cfg() ourselves. let out = std::env::var("OUT_DIR")?; let out = Path::new(&out); let krate = out.parent().unwrap(); let build = krate.parent().unwrap(); - let profile = build.parent().unwrap(); - if profile.file_name().unwrap() == "production" { + let profile = build + .parent() + .unwrap() + .file_name() + .unwrap() + .to_string_lossy(); + if profile == "production" || profile.starts_with("production-") { println!("cargo:rustc-cfg=servo_production"); } else { println!("cargo:rustc-cfg=servo_do_not_use_in_production"); diff --git a/ports/servoshell/build.rs b/ports/servoshell/build.rs index c593c3f8a88..2bce85cdefb 100644 --- a/ports/servoshell/build.rs +++ b/ports/servoshell/build.rs @@ -21,14 +21,21 @@ fn generate_egl_bindings(out_dir: &Path) { } fn main() -> Result<(), Box> { + println!("cargo::rustc-check-cfg=cfg(servo_production)"); + println!("cargo::rustc-check-cfg=cfg(servo_do_not_use_in_production)"); // Cargo does not expose the profile name to crates or their build scripts, // but we can extract it from OUT_DIR and set a custom cfg() ourselves. let out = std::env::var("OUT_DIR")?; let out = Path::new(&out); let krate = out.parent().unwrap(); let build = krate.parent().unwrap(); - let profile = build.parent().unwrap(); - if profile.file_name().unwrap() == "production" { + let profile = build + .parent() + .unwrap() + .file_name() + .unwrap() + .to_string_lossy(); + if profile == "production" || profile.starts_with("production-") { println!("cargo:rustc-cfg=servo_production"); } else { println!("cargo:rustc-cfg=servo_do_not_use_in_production");