Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide opt-out feature=from_source to use serde_derive source #2580

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion precompiled/serde_derive/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ deserialize_in_place = []
[lib]
proc-macro = true

[target.'cfg(not(all(serde_derive_build = "precompiled", target_arch = "x86_64", target_os = "linux", target_env = "gnu")))'.dependencies]
[target.'cfg(serde_derive_build = "source")'.dependencies]
proc-macro2 = "1"
quote = "1"
syn = "2.0.28"
Expand Down
21 changes: 21 additions & 0 deletions precompiled/serde_derive/build.rs
pinkforest marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,21 @@
fn is_target_precompiled(target: &str) -> bool {
target == "x86_64-unknown-linux-gnu"
}

fn main() {
// Alternatively use platforms crate etc. for Types
let target = match std::env::var("TARGET") {
Ok(target) => target,
_ => "".to_string(), // TARGET should be required ?
};
println!("cargo:warning=\"{target}\"");
// This is required to simplify gating
let derive_build = match std::env::var("CARGO_CFG_SERDE_DERIVE_BUILD").as_deref() {
Ok("source") => "source",
_ => match is_target_precompiled(&target) {
true => "precompiled",
false => "source",
},
};
println!("cargo:rustc-cfg=serde_derive_build=\"{derive_build}\"");
}
14 changes: 2 additions & 12 deletions precompiled/serde_derive/src/lib.rs
Expand Up @@ -15,18 +15,8 @@

#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.183")]

#[cfg(all(
serde_derive_build = "source",
target_arch = "x86_64",
target_os = "linux",
target_env = "gnu"
))]
#[cfg(serde_derive_build = "source")]
include!("lib_from_source.rs");

#[cfg(all(
not(serde_derive_build = "source"),
target_arch = "x86_64",
target_os = "linux",
target_env = "gnu"
))]
#[cfg(not(serde_derive_build = "source"))]
include!("lib_precompiled.rs");