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

Add derive_compiled feature to force compilation of serde_derive #2579

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ fn main() {
}
```

## Note about serde_derive Binary

When using `serde_derive` either directly or via `serde` with `derive` feature it
may be distributed from within pre-compiled binary (currently only on `x86_64-linux-gnu` target)

To force building `serde_derive` from source, an override is provided via:

- `derive_compiled` feature in `serde`
- `compiled` feature in `serde_derive`

## Getting help

Serde is one of the most widely used Rust libraries so any place that Rustaceans
Expand Down
6 changes: 6 additions & 0 deletions precompiled/serde_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rust-version = "1.56"
[features]
default = []
deserialize_in_place = []
compiled = ["proc-macro2", "quote", "syn"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compiled = ["proc-macro2", "quote", "syn"]
from_source = ["proc-macro2", "quote", "syn"]

I think compiled would imply that it's opt-in but given we are opt-out it would perhaps work as a name ?


[lib]
proc-macro = true
Expand All @@ -26,6 +27,11 @@ proc-macro2 = "1"
quote = "1"
syn = "2.0.28"

[dependencies]
sagudev marked this conversation as resolved.
Show resolved Hide resolved
proc-macro2 = { version = "1", optional = true }
quote = { version = "1", optional = true }
syn = { version = "2.0.28", optional = true }

[dev-dependencies]
serde = { version = "1", path = "../../serde" }

Expand Down
10 changes: 8 additions & 2 deletions precompiled/serde_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

#![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 = "compiled",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
feature = "compiled",
feature = "from_source",

as above

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(not(any(
feature = "compiled",
not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))
)))]
include!("lib_precompiled.rs");
3 changes: 3 additions & 0 deletions serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ default = ["std"]
# Provide derive(Serialize, Deserialize) macros.
derive = ["serde_derive"]

# Force full compilation of serde_derive
derive_compiled = ["serde_derive/compiled"]
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Force full compilation of serde_derive
derive_compiled = ["serde_derive/compiled"]
# Force compilation from source - currently serde_derive
from_source = ["serde_derive/from_source"]


# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
# Requires a dependency on the Rust standard library.
std = []
Expand Down
1 change: 1 addition & 0 deletions serde_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rust-version = "1.56"
[features]
default = []
deserialize_in_place = []
compiled = []

[lib]
name = "serde_derive"
Expand Down