forked from rust-num/num-rational
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable
rustc-serialize
derives for future compilers
The built-in derives are being [removed], but crater showed problems with crates depending on `num v0.1`, where this feature is enabled by default. With this PR, we detect the missing built-ins and disable the derives, adding a build-script warning about it. Cargo won't show such warnings by default from non-path dependencies, unless the build fails. [removed]: rust-lang/rust#134272
- Loading branch information
Showing
6 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extern crate autocfg; | ||
|
||
fn main() { | ||
autocfg::rerun_path("build.rs"); | ||
autocfg::emit_possibility(HAS_DERIVE); | ||
if std::env::var_os("CARGO_FEATURE_RUSTC_SERIALIZE").is_some() { | ||
let ac = autocfg::new(); | ||
|
||
// These built-in derives are being removed! (rust-lang/rust#134272) | ||
// | ||
// It's hard to directly probe for `derive(RustcDecodable, RustcEncodable)`, because that | ||
// depends on the external `rustc-serialize` dependency. They're in `prelude::v1` where we | ||
// can probe by path, but ironically only on relatively new versions, so we're also using | ||
// *inaccessible* `rust_2024` as a proxy for older versions. | ||
if ac.probe_raw(PRELUDE_DERIVE).is_ok() || !ac.probe_path(RUST_2024) { | ||
autocfg::emit(HAS_DERIVE); | ||
} else { | ||
println!("cargo:warning=rustc-serialize is not supported by the current compiler"); | ||
} | ||
} | ||
} | ||
|
||
const HAS_DERIVE: &str = "has_derive_rustc_serialize"; | ||
|
||
const PRELUDE_DERIVE: &str = " | ||
#[allow(soft_unstable, deprecated)] | ||
pub use std::prelude::v1::{RustcDecodable, RustcEncodable}; | ||
"; | ||
|
||
const RUST_2024: &str = "std::prelude::rust_2024"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters