Skip to content

Commit

Permalink
Provide opt-out source compilation by feature `from_source
Browse files Browse the repository at this point in the history
Co-authored-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Oliver Schneider <oli-obk@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 20, 2023
1 parent 6bccee7 commit 5854820
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,8 @@ fn main() {

## Note about serde_derive Binary

When using `serde_derive` either directly or via `serde` with `derive` feature.

Please note that `serde_derive` may be distributed from within pre-compiled binary

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

```sh
RUSTFLAGS='--cfg serde_derive_build="source"'
```

Alternatively in `~/.cargo/config`:
```toml
rustflags = ['--cfg serde_derive_build="source"']
```

More info from [cargo reference](https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags).
To force building `serde_derive` from source, an override is provided via
feature `from_source` if the target environment requires it.

## Getting help

Expand Down
10 changes: 9 additions & 1 deletion precompiled/serde_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ rust-version = "1.56"
[features]
default = []
deserialize_in_place = []
from_source = ["proc-macro2", "quote", "syn"]

[lib]
proc-macro = true

[target.'cfg(any(serde_derive_build = "source", not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))))'.dependencies]
# 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"
syn = "2.0.28"
Expand Down
4 changes: 2 additions & 2 deletions precompiled/serde_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.183")]

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

#[cfg(all(
not(serde_derive_build = "source"),
not(feature = "from_source"),
target_arch = "x86_64",
target_os = "linux",
target_env = "gnu"
Expand Down
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 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 @@ -14,6 +14,7 @@ rust-version = "1.56"

[features]
default = []
from_source = []
deserialize_in_place = []

[lib]
Expand Down

0 comments on commit 5854820

Please sign in to comment.