Skip to main content

Cargo builds and artifact installation

Build and install Cargo artifacts for mixed Rust/Python projects.

fastws.cargo is not re-exported from fastws, so import it explicitly:

from fastws.cargo import build, develop, stage_binaries

Cargo command failures raise subprocess.CalledProcessError with Cargo’s standard error; missing pyproject.toml settings raise ConfigError.

Building and installing artifacts

develop builds and atomically installs a project’s extension and opted-in binaries (local=True installs the extension in-tree without touching .venv, for isolated git worktrees). build and stage_binaries compile Cargo artifacts and stage native binaries for wheels.

develop

def develop(
    root:str | pathlib._local.Path, # Project directory containing `pyproject.toml` and `Cargo.toml` (expands `~`)
    *, profile:str=None, # Cargo profile; None uses `tool.fastws.dev-profile`, else `'release'`
    env:dict=None, # Extra environment variables for Cargo and any post-develop generator
    local:bool=False, # Install the extension in-tree without modifying the active virtual environment?
    post:bool=True, # Run any `post-develop-module` generator and copy wheel data?
):

Build and atomically install a mixed Rust/Python project’s extension and opted-in binaries.

post_develop

def post_develop(
    root:str | pathlib._local.Path, # Project directory containing `pyproject.toml` (expands `~`)
    *, env:dict=None, # Extra environment variables for any post-develop generator
    local:bool=False, # Skip copying wheel data into the active virtual environment?
)->bool: # True if a `post-develop-module` generator ran

Run any post-develop-module generator and copy wheel data into the active venv.

build

def build(
    root, # The project directory, whose `tool.maturin` gives the defaults (expands `~`)
    *, library:bool=True, # Build the library target?
    binaries:bool=False, # Build the binary targets?
    profile=None, # Cargo profile; None: `tool.maturin.profile`, or Cargo's default
    target=None, # Target triple; None: the host
    features=None, # Features to enable, as a list or a string; None: `tool.maturin.features`
    all_features:bool=False, # Enable every feature? `tool.maturin`'s `all-features` also turns this on
    no_default_features:bool=False, # Leave out the default features? `tool.maturin`'s `no-default-features` also turns this on
    for_maturin:bool=False, # Use the macOS linker flags that maturin's own wheel build uses?
    env=None, # Extra environment variables for Cargo
    zig:bool=False, # Build via `cargo zigbuild` for Linux glibc targeting?
    manylinux=None, # Target glibc version for `zig`, e.g. `'2_31'` or `'manylinux_2_31'`
)->list[dict]: # Cargo `compiler-artifact` JSON records for workspace members

Build with Cargo and return the compiler artifacts of the workspace’s packages.

stage_binaries

def stage_binaries(
    root:str | pathlib._local.Path, # Project directory whose `tool.maturin.data` sets the staging root (expands `~`)
    profile:str=None, # Cargo profile; None uses `tool.maturin.profile` or Cargo's default
    target:str=None, # Cargo target triple; None targets the host
    features=None, # Features to enable, as a list or comma/space-separated string
    all_features:bool=False, # Enable all Cargo features?
    no_default_features:bool=False, # Disable default Cargo features?
    zig:bool=False, # Build via `cargo zigbuild` for Linux glibc targeting?
    manylinux:str=None, # Target glibc version for `zig`, e.g. `'2_31'` or `'manylinux_2_31'`
)->list[pathlib._local.Path]: # Paths of the staged executables inside `<root>/<tool.maturin.data>/scripts/`

Stage Python-free Cargo binaries for a maturin wheel build.

cargo

def cargo(
    root:str | pathlib._local.Path, # Working directory for Cargo (expands `~`)
    *args:str, # Arguments passed to the `cargo` executable
    env:dict=None, # Extra environment variables for the Cargo subprocess
)->str: # Standard output from Cargo

Run Cargo in the project and return its standard output.

Helpers

settings

def settings(
    root:str | pathlib._local.Path, # Project directory containing `pyproject.toml` (expands `~`)
)->dict: # Parsed `[tool]` table from `pyproject.toml` (empty dict when absent)

Read the project’s tool configuration.

members

def members(
    root:str | pathlib._local.Path, # Project or workspace directory (expands `~`)
)->set[pathlib._local.Path]: # `Cargo.toml` paths of the workspace's member packages

The manifests of the workspace’s member packages.

sources

def sources(
    root:str | pathlib._local.Path, # Project or workspace directory (expands `~`)
)->set[pathlib._local.Path]: # Manifest paths and target source files or directories for local packages

The manifests, and the target directories or files, of the local packages that the workspace builds: its members and its path dependencies.

replace

def replace(
    source:pathlib._local.Path, # Newly built file to copy
    destination:pathlib._local.Path, # Target path to replace atomically
)->pathlib._local.Path: # `destination`

Replace an installed artifact without changing the file held by running processes.

ConfigError

def ConfigError(
    *args, **kwargs
):

A project’s pyproject.toml lacks a setting that a command needs.