Set the cfg properly for the production-stripped profile (#32991)

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef 2024-08-09 02:16:51 -07:00 committed by GitHub
parent a1d3649f7c
commit 2ebb71f08a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -49,6 +49,9 @@ webrender_api = { workspace = true }
webrender_traits = { workspace = true } webrender_traits = { workspace = true }
xi-unicode = { workspace = true } xi-unicode = { workspace = true }
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ohos_mock)'] }
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
byteorder = { workspace = true } byteorder = { workspace = true }
core-foundation = "0.9" core-foundation = "0.9"

View file

@ -6,14 +6,21 @@ use std::error::Error;
use std::path::Path; use std::path::Path;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
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, // 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. // but we can extract it from OUT_DIR and set a custom cfg() ourselves.
let out = std::env::var("OUT_DIR")?; let out = std::env::var("OUT_DIR")?;
let out = Path::new(&out); let out = Path::new(&out);
let krate = out.parent().unwrap(); let krate = out.parent().unwrap();
let build = krate.parent().unwrap(); let build = krate.parent().unwrap();
let profile = build.parent().unwrap(); let profile = build
if profile.file_name().unwrap() == "production" { .parent()
.unwrap()
.file_name()
.unwrap()
.to_string_lossy();
if profile == "production" || profile.starts_with("production-") {
println!("cargo:rustc-cfg=servo_production"); println!("cargo:rustc-cfg=servo_production");
} else { } else {
println!("cargo:rustc-cfg=servo_do_not_use_in_production"); println!("cargo:rustc-cfg=servo_do_not_use_in_production");

View file

@ -21,14 +21,21 @@ fn generate_egl_bindings(out_dir: &Path) {
} }
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
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, // 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. // but we can extract it from OUT_DIR and set a custom cfg() ourselves.
let out = std::env::var("OUT_DIR")?; let out = std::env::var("OUT_DIR")?;
let out = Path::new(&out); let out = Path::new(&out);
let krate = out.parent().unwrap(); let krate = out.parent().unwrap();
let build = krate.parent().unwrap(); let build = krate.parent().unwrap();
let profile = build.parent().unwrap(); let profile = build
if profile.file_name().unwrap() == "production" { .parent()
.unwrap()
.file_name()
.unwrap()
.to_string_lossy();
if profile == "production" || profile.starts_with("production-") {
println!("cargo:rustc-cfg=servo_production"); println!("cargo:rustc-cfg=servo_production");
} else { } else {
println!("cargo:rustc-cfg=servo_do_not_use_in_production"); println!("cargo:rustc-cfg=servo_do_not_use_in_production");