Skip to content

Commit

Permalink
Vendor json
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Jul 29, 2022
1 parent 142bf3a commit 9cf89ab
Show file tree
Hide file tree
Showing 44 changed files with 17,378 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ once_cell = { version = "1", default_features = false }
pyo3-ffi = { version = "^0.16.5", default_features = false, features = ["extension-module"]}
ryu = { version = "1", default_features = false }
serde = { version = "1", default_features = false }
serde_json = { version = "^1.0.68", default_features = false, features = ["std", "float_roundtrip"] }
serde_json = { path = "include/json", default_features = false, features = ["std", "float_roundtrip"] }
simdutf8 = { version = "0.1", default_features = false, features = ["std"] }
smallvec = { version = "^1.8", default_features = false, features = ["union", "write"] }
smallvec = { version = "^1.9", default_features = false, features = ["union", "write"] }

[build-dependencies]
cc = { version = "1" }
Expand Down
86 changes: 86 additions & 0 deletions include/json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[package]
name = "serde_json"
version = "1.0.82" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "A JSON serialization file format"
repository = "https://github.com/serde-rs/json"
documentation = "https://docs.serde.rs/serde_json/"
keywords = ["json", "serde", "serialization"]
categories = ["encoding"]
readme = "README.md"
edition = "2018"
rust-version = "1.36"

[dependencies]
serde = { version = "1.0.100", default-features = false }
indexmap = { version = "1.5.2", features = ["std"], optional = true }
itoa = "1.0"
ryu = "1.0"

[dev-dependencies]
automod = "1.0"
ref-cast = "1.0"
rustversion = "1.0"
serde = { version = "1.0.100", features = ["derive"] }
serde_bytes = "0.11"
serde_derive = "1.0"
serde_stacker = "0.1"
trybuild = { version = "1.0.49", features = ["diff"] }

[package.metadata.docs.rs]
features = ["raw_value", "unbounded_depth"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
features = ["raw_value"]


### FEATURES #################################################################

[features]
default = ["std"]

std = ["serde/std"]

# Provide integration for heap-allocated collections without depending on the
# rest of the Rust standard library.
# NOTE: Disabling both `std` *and* `alloc` features is not supported yet.
# Available on Rust 1.36+.
alloc = ["serde/alloc"]

# Make serde_json::Map use a representation which maintains insertion order.
# This allows data to be read into a Value and written back to a JSON string
# while preserving the order of map keys in the input.
preserve_order = ["indexmap", "std"]

# Use sufficient precision when parsing fixed precision floats from JSON to
# ensure that they maintain accuracy when round-tripped through JSON. This comes
# at an approximately 2x performance cost for parsing floats compared to the
# default best-effort precision.
#
# Unlike arbitrary_precision, this feature makes f64 -> JSON -> f64 produce
# output identical to the input.
float_roundtrip = []

# Use an arbitrary precision number representation for serde_json::Number. This
# allows JSON numbers of arbitrary size/precision to be read into a Number and
# written back to a JSON string without loss of precision.
#
# Unlike float_roundtrip, this feature makes JSON -> serde_json::Number -> JSON
# produce output identical to the input.
arbitrary_precision = []

# Provide a RawValue type that can hold unprocessed JSON during deserialization.
raw_value = []

# Provide a method disable_recursion_limit to parse arbitrarily deep JSON
# structures without any consideration for overflowing the stack. When using
# this feature, you will want to provide some other way to protect against stack
# overflows, such as by wrapping your Deserializer in the dynamically growing
# stack adapter provided by the serde_stacker crate. Additionally you will need
# to be careful around other recursive operations on the parsed result which may
# overflow the stack after deserialization has completed, including, but not
# limited to, Display and Debug and Drop impls.
unbounded_depth = []
52 changes: 52 additions & 0 deletions include/json/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};

fn main() {
// Decide ideal limb width for arithmetic in the float parser. Refer to
// src/lexical/math.rs for where this has an effect.
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
match target_arch.as_str() {
"aarch64" | "mips64" | "powerpc64" | "x86_64" => {
println!("cargo:rustc-cfg=limb_width_64");
}
_ => {
println!("cargo:rustc-cfg=limb_width_32");
}
}

let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};

// BTreeMap::get_key_value
// https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
if minor < 40 {
println!("cargo:rustc-cfg=no_btreemap_get_key_value");
}

// BTreeMap::remove_entry
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
if minor < 45 {
println!("cargo:rustc-cfg=no_btreemap_remove_entry");
}

// BTreeMap::retain
// https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
if minor < 53 {
println!("cargo:rustc-cfg=no_btreemap_retain");
}
}

fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
let next = pieces.next()?;
u32::from_str(next).ok()
}
Loading

0 comments on commit 9cf89ab

Please sign in to comment.