Skip to content

Linking project extras to maturin features #16465

@chitralverma

Description

@chitralverma

Summary

I have python rust mixed pyo3 project (mypackage) which is built using maturin build-backend and I want to make certain Rust features compile only when optional Python dependencies (or “extras”) are installed.

I know what the dependencies and optional-dependencies section a pyproject.toml are to manipulate the included python packages. but I was wondering if there is a known pattern to use these to manipulate a feature gated (maturin) build itself.

Any help would be greatly appreciated, let me know if i need to raise this as a github issue.
thanks

Example

It'll be awesome for the end users to do something like :

# base build with default features
uv pip install mypackage           

# enables "fast" Rust feature + includes any other py dependencies in fast extra
uv pip install mypackage[fast]     

# enables "something" and "fast" Rust feature + includes any other py dependencies in "something" and "fast" extra
uv pip install mypackage[fast, something]    

and have those optional extras map to Cargo features in your Cargo.toml so that maturin knows to build with those features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement to existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions