Cargo.toml


Overview

`Cargo.toml` is the manifest file for the Rust package **orjson**, a high-performance JSON serialization and deserialization library for Python. This file serves as the central configuration point for the Rust build system Cargo, specifying metadata, dependencies, features, build profiles, and compilation settings for the Rust components of the project.

The key functionalities of this file include:

This manifest is essential for enabling reproducible, configurable builds that integrate Rust with embedded C code and Python bindings.


Detailed Explanation of Sections

[package]

Defines core metadata and packaging details.

Field

Description

name

The package name, `"orjson"`.

version

Current version, `"3.11.1"`.

`authors`

List of authors; here `["ijl "]`.

`description`

Brief description of the package.

`edition`

Rust edition used, `"2021"`.

`resolver`

Dependency resolver version, `"2"`.

`rust-version`

Minimum Rust compiler version required, `"1.82"`.

license

License type, `"Apache-2.0 OR MIT"` (dual licensed).

`readme`

Path to the README file included in the package.

`keywords`

Array of keywords describing the package, aiding discoverability.

`include`

List of files/directories to include in the published package (e.g., source, tests, licenses).


[lib]

Configures the Rust library crate output.

Field

Description

name

Library crate name, `"orjson"`.

`crate-type`

Build output types. Here [["cdylib"]](/projects/287/67747) indicates building a C-compatible dynamic library, suitable for Python FFI via PyO3.


[features]

Defines optional and conditional compilation features.

Feature

Description

default

Empty array, meaning no features enabled by default.

`unwind`

Enables panic unwinding support, specifically avoiding bundling [libgcc](/projects/287/67747) on musl targets.

`yyjson`

Enables building and linking the embedded `yyjson` C JSON parser backend.

avx512

Detected by `build.rs`, enables AVX-512 SIMD optimizations on supported hardware.

c_ulong_32

Detected by `build.rs`, related to platform-specific integer size handling.

`generic_simd`

Detected by `build.rs`, enables generic SIMD optimizations.

inline_int

Detected by `build.rs`, enables inline integer optimizations.

intrinsics

Detected by `build.rs`, enables use of CPU intrinsics for performance.

optimize

Detected by `build.rs`, enables general build-time optimizations.

**Note:** Features marked as "detected by build.rs" are automatically enabled based on environment and compiler capabilities and should not be manually specified.


[dependencies]

Lists runtime dependencies for the Rust crate with specific version constraints and feature flags.

Dependency

Version/Source

Features & Notes

associative-cache

`"2"`

[default-features = false](/projects/287/68131) disables features not required.

bytes

`"1"`

[default-features = false](/projects/287/68131).

`bytecount`

`"^0.6.7"`

Disabled default features; enables ["runtime-dispatch-simd"](/projects/287/67764) for SIMD.

`encoding_rs`

`"0.8"`

[default-features = false](/projects/287/68131).

`half`

`"2"`

Enables `"std"` feature for standard library support.

`itoa`

`"1"`

Integer to ASCII conversions, [default-features = false](/projects/287/68131).

`itoap`

`"1"`

Fast integer to ascii printing, with `"std"` and `"simd"` features.

`jiff`

`"^0.2"`

[default-features = false](/projects/287/68131).

`once_cell`

`"1"`

For lazy static initialization with ["alloc"](/projects/287/67784) and `"race"` features.

`pyo3-ffi`

`"0.25"`

Python FFI layer with ["extension-module"](/projects/287/67734) feature enabled.

`ryu`

`"1"`

Fast float-to-string conversion, [default-features = false](/projects/287/68131).

`serde`

`"1"`

Serialization framework, no default features.

serde_json

`"1"`

JSON serialization with `"std"` and ["float_roundtrip"](/projects/287/67755) features.

simdutf8

`"0.1"`

UTF-8 validation with SIMD acceleration, `"std"`, `"public_imp"`, `"aarch64_neon"` features enabled.

`smallvec`

`"^1.11"`

Small vector optimization with `"union"` and `"write"` features.

`unwinding`

`"=0.2.5"`

Optional dependency for panic unwinding with `"unwinder"` feature.

uuid

`"1"`

UUID support, defaults disabled.

`xxhash-rust`

`"^0.8"`

Fast hashing with `"xxh3"` feature enabled.


[build-dependencies]

Crates required during the build process, not linked to the final binary.

Dependency

Version

Purpose

cc

`"1"`

Used to compile embedded C code (`yyjson`).

pyo3-build-config

`"0.25"`

Detects Python interpreter configuration for PyO3 integration.

version_check

`"0.9"`

Checks Rust compiler version for conditional compilation.


[profile.dev]

Compiler settings for development builds.

Setting

Value

Description

`codegen-units`

1

Number of codegen units, affecting build parallelism and optimization.

debug

2

Debug information level.

debug-assertions

true

Enable debug assertions.

`incremental`

false

Disable incremental compilation for consistency.

`lto`

`"off"`

Link Time Optimization off for faster build times.

opt-level

`3`

Optimization level (max for dev).

`overflow-checks`

true

Enable integer overflow checks.


[profile.release]

Compiler settings for release builds.

Setting

Value

Description

`codegen-units`

1

Single codegen unit for better optimization.

debug

false

No debug info for smaller binary.

`incremental`

false

Disable incremental builds for reproducibility.

`lto`

`"thin"`

Enables thin link-time optimization for better performance.

opt-level

`3`

Maximum optimization level.

`panic`

`"abort"`

Panic strategy set to abort for smaller binary and performance.


[profile.release.build-override]

Overrides for builds triggered during the release build process.

Setting

Value

Description

opt-level

0

No optimization during build override.


Important Implementation Details


Usage Example

This file is not directly "used" in code but consumed by Cargo during build commands. Typical usage involves running:

cargo build --release

or when building Python wheels with maturin or other build tools that call Cargo internally. The manifest guides the build process, dependency resolution, and feature activation.


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[Cargo.toml Manifest]
    B[Package Metadata]
    C[Dependencies & Features]
    D[Build Dependencies]
    E[Profiles: dev & release]
    F[Build Script (build.rs)]
    G[Rust Core & Embedded C Libraries Compilation]
    H[Python FFI Dynamic Library (cdylib)]
    I[Packaging & Distribution]

    A --> B
    A --> C
    A --> D
    A --> E
    C --> F
    D --> F
    F --> G
    G --> H
    H --> I

**Diagram Explanation:** The manifest (`Cargo.toml`) declares metadata, dependencies, features, build dependencies, and profiles. The build script (`build.rs`) reads feature flags and dependencies to conditionally compile Rust and embedded C code. The result is a dynamic library (`cdylib`) exposing Rust functions to Python. Finally, the artifact is packaged and distributed.


Summary

The `Cargo.toml` file is the declarative cornerstone of the **orjson** Rust package. It defines the package identity, manages dependencies and feature flags, controls build profiles, and integrates with build scripts to enable conditional compilation and embedding of the high-performance `yyjson` C JSON parser. By specifying dependencies with precision and tailoring compilation profiles, it ensures reproducible, optimized builds of the Rust core that seamlessly interface with Python. This manifest connects the Rust ecosystem, build tooling, and Python FFI, enabling the performant and correct JSON serialization library that **orjson** is known for.