Skip to content

Commit

Permalink
writeext feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Feb 28, 2023
1 parent c5a1c8a commit 02910ee
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux-cross.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
CFLAGS: "-O2 -fno-plt"
LDFLAGS: "-O2 -flto -Wl,--as-needed"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
ORJSON_ENABLE_WRITEEXT: "1"
with:
maturin-version: v0.14.14
target: ${{ matrix.target.arch }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/manylinux2014.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
CFLAGS: "-O2 -fno-plt"
LDFLAGS: "-O2 -flto -Wl,--as-needed"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
ORJSON_ENABLE_WRITEEXT: "1"
container:
image: quay.io/pypa/manylinux2014_x86_64:latest
options: --user 0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/manylinux_2_28.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
ORJSON_ENABLE_WRITEEXT: "1"
container:
image: quay.io/pypa/manylinux_2_28_x86_64:latest
options: --user 0
Expand Down
18 changes: 15 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

use std::env;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=include/yyjson/*");
println!("cargo:rerun-if-env-changed=CC");
println!("cargo:rerun-if-env-changed=CFLAGS");
println!("cargo:rerun-if-env-changed=LDFLAGS");
println!("cargo:rerun-if-env-changed=RUSTFLAGS");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_WRITEEXT");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_YYJSON");
println!("cargo:rerun-if-env-changed=ORJSON_ENABLE_WRITEEXT");

let py_cfg = pyo3_build_config::get();
py_cfg.emit_pyo3_cfgs();
Expand All @@ -20,8 +24,16 @@ fn main() {
println!("cargo:rustc-cfg=feature=\"optimize\"");
}

if std::env::var("ORJSON_DISABLE_YYJSON").is_ok() {
if std::env::var("CARGO_FEATURE_YYJSON").is_ok() {
if env::var("ORJSON_DISABLE_WRITEEXT").is_ok() {
} else if env::var("ORJSON_ENABLE_WRITEEXT").is_ok()
|| env::var("CARGO_CFG_TARGET_OS").unwrap() == "macos"
|| env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu"
{
println!("cargo:rustc-cfg=feature=\"writeext\"");
}

if env::var("ORJSON_DISABLE_YYJSON").is_ok() {
if env::var("CARGO_FEATURE_YYJSON").is_ok() {
panic!("ORJSON_DISABLE_YYJSON and --features=yyjson both enabled.")
}
} else {
Expand All @@ -36,7 +48,7 @@ fn main() {
println!("cargo:rustc-cfg=feature=\"yyjson\"");
}
Err(_) => {
if std::env::var("CARGO_FEATURE_YYJSON").is_ok() {
if env::var("CARGO_FEATURE_YYJSON").is_ok() {
panic!("yyjson was enabled but the build failed. To build with a different backend do not specify the feature.")
}
}
Expand Down
2 changes: 2 additions & 0 deletions ci/azure-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ steps:
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
RUSTFLAGS: "-C linker=clang -C target-feature=+sse4.2"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
ORJSON_ENABLE_WRITEEXT: "1"
displayName: build
- bash: pip install target/wheels/orjson*.whl
displayName: install
Expand All @@ -37,6 +38,7 @@ steps:
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
RUSTFLAGS: "-C linker=clang"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
ORJSON_ENABLE_WRITEEXT: "1"
displayName: build universal2
- bash: pip install --force-reinstall target/wheels/orjson*universal2.whl
displayName: install universal2
Expand Down
1 change: 1 addition & 0 deletions src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod tuple;
mod uuid;
mod writer;

#[cfg(feature = "writeext")]
mod json;

pub use serializer::serialize;
4 changes: 4 additions & 0 deletions src/serialize/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use serde::ser::{Serialize, SerializeMap, Serializer};
use std::io::Write;
use std::ptr::NonNull;

#[cfg(not(feature = "writeext"))]
use serde_json::{to_writer, to_writer_pretty};

#[cfg(feature = "writeext")]
use crate::serialize::json::{to_writer, to_writer_pretty};

pub const RECURSION_LIMIT: u8 = 255;
Expand Down

0 comments on commit 02910ee

Please sign in to comment.