Bump MSRV to 1.36.0

This commit is contained in:
Graham Esau 2020-09-21 08:42:07 +01:00
parent 7a1e02eefd
commit 5ca2d08013
8 changed files with 38 additions and 82 deletions

View file

@ -16,7 +16,7 @@ build = "build.rs"
schemars_derive = { version = "=0.8.0-alpha-4", optional = true, path = "../schemars_derive" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
dyn-clone = "= 1.0.1"
dyn-clone = "1.0"
chrono = { version = "0.4", default-features = false, optional = true }
indexmap = { version = "1.2", features=["serde-1"], optional = true }

View file

@ -1,67 +1,25 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};
// Based on https://github.com/serde-rs/serde/blob/master/serde/build.rs
fn main() {
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
// Atomic types, and non-zero signed integers stabilized in Rust 1.34:
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
if minor >= 34 {
println!("cargo:rustc-cfg=num_nonzero_signed");
// Whitelist of archs that support std::sync::atomic module. Ideally we
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
// Instead this is based on rustc's src/librustc_target/spec/*.rs.
let has_atomic64 = target.starts_with("x86_64")
|| target.starts_with("i686")
|| target.starts_with("aarch64")
|| target.starts_with("powerpc64")
|| target.starts_with("sparc64")
|| target.starts_with("mips64el");
let has_atomic32 = has_atomic64 || emscripten;
if has_atomic64 {
println!("cargo:rustc-cfg=std_atomic64");
}
if has_atomic32 {
println!("cargo:rustc-cfg=std_atomic");
}
// Whitelist of archs that support std::sync::atomic module. Ideally we
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
// Instead this is based on rustc's src/librustc_target/spec/*.rs.
let has_atomic64 = target.starts_with("x86_64")
|| target.starts_with("i686")
|| target.starts_with("aarch64")
|| target.starts_with("powerpc64")
|| target.starts_with("sparc64")
|| target.starts_with("mips64el");
let has_atomic32 = has_atomic64 || emscripten;
if has_atomic64 {
println!("cargo:rustc-cfg=std_atomic64");
}
if has_atomic32 {
println!("cargo:rustc-cfg=std_atomic");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return None,
};
let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return None,
};
let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return None,
};
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
let next = match pieces.next() {
Some(next) => next,
None => return None,
};
u32::from_str(next).ok()
}

View file

@ -55,7 +55,6 @@ mod ffi;
#[cfg(feature = "indexmap")]
mod indexmap;
mod maps;
#[cfg(num_nonzero_signed)]
mod nonzero_signed;
mod nonzero_unsigned;
mod primitives;

View file

@ -1,5 +1,4 @@
use crate::schema::{RootSchema, Schema, SchemaObject, SingleOrVec};
use std::fmt::Debug;
/// TODO document
pub trait Visitor {

View file

@ -1,21 +1,18 @@
mod util;
#[cfg(num_nonzero_signed)]
mod nonzero_ints {
use super::*;
use schemars::JsonSchema;
use util::*;
use super::*;
use schemars::JsonSchema;
use util::*;
#[derive(Debug, JsonSchema)]
struct MyStruct {
unsigned: u32,
nonzero_unsigned: std::num::NonZeroU32,
signed: i32,
nonzero_signed: std::num::NonZeroI32,
}
#[test]
fn nonzero_ints() -> TestResult {
test_default_generated_schema::<MyStruct>("nonzero_ints")
}
#[derive(Debug, JsonSchema)]
struct MyStruct {
unsigned: u32,
nonzero_unsigned: std::num::NonZeroU32,
signed: i32,
nonzero_signed: std::num::NonZeroI32,
}
#[test]
fn nonzero_ints() -> TestResult {
test_default_generated_schema::<MyStruct>("nonzero_ints")
}