diff --git a/README.md b/README.md index 477fd3647..d458df318 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,11 @@ fn main() { } ``` +## Note about serde_derive Binary + +To force building `serde_derive` from source, an override is provided via +feature `from_source` if the target environment requires it. + ## Getting help Serde is one of the most widely used Rust libraries so any place that Rustaceans diff --git a/precompiled/serde_derive/Cargo.toml b/precompiled/serde_derive/Cargo.toml index 0910b574a..c5d33bef5 100644 --- a/precompiled/serde_derive/Cargo.toml +++ b/precompiled/serde_derive/Cargo.toml @@ -17,10 +17,18 @@ rust-version = "1.56" [features] default = [] deserialize_in_place = [] +from_source = ["proc-macro2", "quote", "syn"] [lib] proc-macro = true +# By feature source compilation +[dependencies] +proc-macro2 = { version = "1", optional = true } +quote = { version = "1", optional = true } +syn = { version = "2.0.28", optional = true } + +# Compile from source when no precompiled binary available [target.'cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))'.dependencies] proc-macro2 = "1" quote = "1" diff --git a/precompiled/serde_derive/src/lib.rs b/precompiled/serde_derive/src/lib.rs index fbddcca56..bcc18a7d4 100644 --- a/precompiled/serde_derive/src/lib.rs +++ b/precompiled/serde_derive/src/lib.rs @@ -15,8 +15,16 @@ #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.183")] -#[cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))] +#[cfg(any( + feature = "from_source", + not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")) +))] include!("lib_from_source.rs"); -#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] +#[cfg(all( + not(feature = "from_source"), + target_arch = "x86_64", + target_os = "linux", + target_env = "gnu" +))] include!("lib_precompiled.rs"); diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 342645206..6c4167e3a 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -40,6 +40,9 @@ default = ["std"] # Provide derive(Serialize, Deserialize) macros. derive = ["serde_derive"] +# Force compilation from source - currently serde_derive +from_source = ["serde_derive/from_source"] + # Provide impls for common standard library types like Vec and HashMap. # Requires a dependency on the Rust standard library. std = [] diff --git a/serde_derive/Cargo.toml b/serde_derive/Cargo.toml index 1baae9f27..04f8e6c4f 100644 --- a/serde_derive/Cargo.toml +++ b/serde_derive/Cargo.toml @@ -14,6 +14,7 @@ rust-version = "1.56" [features] default = [] +from_source = [] deserialize_in_place = [] [lib]