diff --git a/precompiled/serde_derive/build.rs b/precompiled/serde_derive/build.rs index a5d2d1fe..06dd1f49 100644 --- a/precompiled/serde_derive/build.rs +++ b/precompiled/serde_derive/build.rs @@ -1,3 +1,4 @@ fn main() { println!("cargo:rustc-cfg=precompiled"); + println!("cargo:rustc-cfg=feature=\"deserialize_in_place\""); } diff --git a/precompiled/serde_derive/main.rs b/precompiled/serde_derive/main.rs index 443300b2..c8383e5d 100644 --- a/precompiled/serde_derive/main.rs +++ b/precompiled/serde_derive/main.rs @@ -3,6 +3,7 @@ extern crate proc_macro2; use proc_macro2::watt; use proc_macro2::watt::buffer::InputBuffer; use std::io::{self, Read, Write}; +use std::sync::atomic::Ordering; fn main() { let mut buf = Vec::new(); @@ -12,6 +13,10 @@ fn main() { let derive = match buf.read_u8() { 0 => serde_derive::derive_serialize, 1 => serde_derive::derive_deserialize, + 2 => { + serde_derive::DESERIALIZE_IN_PLACE.store(true, Ordering::Relaxed); + serde_derive::derive_deserialize + } _ => unreachable!(), }; diff --git a/precompiled/x86_64-unknown-linux-gnu/Cargo.toml b/precompiled/x86_64-unknown-linux-gnu/Cargo.toml index 23e47c9d..dd5887de 100644 --- a/precompiled/x86_64-unknown-linux-gnu/Cargo.toml +++ b/precompiled/x86_64-unknown-linux-gnu/Cargo.toml @@ -16,6 +16,10 @@ repository = "https://github.com/serde-rs/serde" name = "serde_derive" proc-macro = true +[features] +default = [] +deserialize_in_place = [] + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/precompiled/x86_64-unknown-linux-gnu/src/lib.rs b/precompiled/x86_64-unknown-linux-gnu/src/lib.rs index d50c9c3f..09809a74 100644 --- a/precompiled/x86_64-unknown-linux-gnu/src/lib.rs +++ b/precompiled/x86_64-unknown-linux-gnu/src/lib.rs @@ -23,7 +23,7 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream { #[proc_macro_derive(Deserialize, attributes(serde))] pub fn derive_deserialize(input: TokenStream) -> TokenStream { - derive(1, input) + derive(1 + cfg!(feature = "deserialize_in_place") as u8, input) } fn derive(select: u8, input: TokenStream) -> TokenStream { diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index cb98b8ea..f3226f1c 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -1,5 +1,7 @@ use proc_macro2::{Literal, Span, TokenStream}; use quote::ToTokens; +#[cfg(precompiled)] +use std::sync::atomic::Ordering; use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::{self, Ident, Index, Member}; @@ -304,6 +306,11 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment { #[cfg(feature = "deserialize_in_place")] fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option { + #[cfg(precompiled)] + if !crate::DESERIALIZE_IN_PLACE.load(Ordering::Relaxed) { + return None; + } + // Only remote derives have getters, and we do not generate // deserialize_in_place for remote derives. assert!(!params.has_getter); diff --git a/serde_derive/src/lib.rs b/serde_derive/src/lib.rs index 399bbc0a..c612597e 100644 --- a/serde_derive/src/lib.rs +++ b/serde_derive/src/lib.rs @@ -78,6 +78,8 @@ extern crate proc_macro2 as proc_macro; mod internals; use proc_macro::TokenStream; +#[cfg(precompiled)] +use std::sync::atomic::AtomicBool; use syn::DeriveInput; #[macro_use] @@ -102,6 +104,9 @@ macro_rules! parse_macro_input { }; } +#[cfg(precompiled)] +pub static DESERIALIZE_IN_PLACE: AtomicBool = AtomicBool::new(false); + #[cfg_attr(not(precompiled), proc_macro_derive(Serialize, attributes(serde)))] pub fn derive_serialize(input: TokenStream) -> TokenStream { let mut input = parse_macro_input!(input as DeriveInput);