Skip to content

feat: Derive c_stdlib build variants from system requirements#6320

Open
hunger wants to merge 2 commits into
prefix-dev:mainfrom
hunger:push-zzpqursrznyw
Open

feat: Derive c_stdlib build variants from system requirements#6320
hunger wants to merge 2 commits into
prefix-dev:mainfrom
hunger:push-zzpqursrznyw

Conversation

@hunger

@hunger hunger commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Derive c_stdlib build variants from system requirements

Problem

When pixi-build builds a compiled (non-noarch) package, the C stdlib target is
selected through conda-forge's c_stdlib / c_stdlib_version build variants
(consumed by the stdlib('c') recipe function). Today users have to spell those
out by hand in [workspace.build-variants], even though pixi already knows the
target from the workspace's platforms.

Changes

Derive the variant pair from system requirements (pixi_core)

Workspace::variants now derives c_stdlib / c_stdlib_version from the
platform's declared virtual packages and fills them in only where the user
hasn't set them explicitly (an explicit [workspace.build-variants] entry
always wins):

subdir virtual package c_stdlib c_stdlib_version
osx-* __osx macosx_deployment_target the __osx version
linux-* __glibc sysroot the __glibc version

Windows is skipped (no meaningful stdlib version), and a platform with no
matching virtual package derives nothing rather than inventing a value. The
logic lives in the new crates/pixi_core/src/workspace/stdlib_variants.rs.

__musl and __cuda are noted as follow-ups (TODO(#6175)). They are not fully described
in any CEP, so whatever we do there is goiung to be incomplete.

Set MACOSX_DEPLOYMENT_TARGET on macOS (pixi_build_python)

For compiled macOS builds where the c_stdlib_version variant is present, the
python backend injects MACOSX_DEPLOYMENT_TARGET=${{ c_stdlib_version }} into
the build-script env (rendered lazily by rattler-build). It's skipped for noarch
builds, off macOS, and when the variant is absent. An explicit
MACOSX_DEPLOYMENT_TARGET in the backend config is left untouched — the derived
value only fills the gap.

Tests

  • Unit tests for derive_stdlib_variants (osx, linux, windows-skipped,
    glibc-absent, and bare-subdir defaults).
  • Unit test that an explicit build-variant overrides the derived value while an
    unset key is still filled in.
  • Unit tests for macos_deployment_target_env and two end-to-end
    generate_recipe tests (derived value wired in; user config respected).
  • New integration test test_macos_deployment_target_from_system_requirements
    plus fixture tests/data/pixi-build/system-requirements-osx-python pinning
    macos = "12.0" (deliberately different from the 13.0 osx-subdir default).
    It asserts a single compiled artifact is produced on every platform, and on
    macOS that the build script env carries MACOSX_DEPLOYMENT_TARGET=12.0.

Fixes #6175.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Claude

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py.

@hunger hunger requested a review from ruben-arts June 9, 2026 15:09
@baszalmstra

baszalmstra commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

I think (not entirely sure) that conda-forge adds MACOSX_DEPLOYMENT_TARGET as a variant too.

Nope thats wrong. Its handled by the macosx_deployment_target package.

Comment thread crates/pixi_build_python/src/main.rs Outdated
Comment thread crates/pixi_core/src/workspace/stdlib_variants.rs
Comment thread crates/pixi_core/src/workspace/stdlib_variants.rs Outdated
@hunger hunger force-pushed the push-zzpqursrznyw branch from 87ffb9f to b6cca2b Compare June 11, 2026 12:30
@hunger hunger marked this pull request as draft June 11, 2026 12:31
@hunger

hunger commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

This should mostly work, but it has severe trouble in the presence of "old" lockfiles. That needs looking into still.

@hunger hunger force-pushed the push-zzpqursrznyw branch 2 times, most recently from 937a1bb to f2ddb9e Compare June 12, 2026 18:07
hunger added 2 commits June 15, 2026 12:29
Inject conda-forge c_stdlib/c_stdlib_version build variants from a
platform's declared virtual packages (__osx, __glibc) in
Workspace::variants(), so build backends pin the minimum OS/libc target
and stop emitting wheels tagged for the host OS version (e.g.
macosx_26_0). Explicit [workspace.build-variants] entries still win;
derivation only fills absent keys.

osx-* derives macosx_deployment_target, linux-* derives sysroot;
windows and unmatched platforms are skipped. The providers are
conda-forge packages, so derivation is gated on the workspace resolving
at least one conda-forge channel; the macosx_deployment_target package's
activation script sets MACOSX_DEPLOYMENT_TARGET during the build. musl
and __cuda are left for a follow-up (TODO marker).

Refs: prefix-dev#6175
@hunger hunger force-pushed the push-zzpqursrznyw branch from f2ddb9e to c73a6f4 Compare June 15, 2026 13:23
@hunger hunger marked this pull request as ready for review June 15, 2026 13:25
@hunger

hunger commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

We report better build variants to the build backend, which filters them and hands them back to us, so we can store them in the lock file. So this PR does invalidate lock files. I think that is what we need to do in this case and users will benefit from better builds.

I have no Mac to test this on, but the linux side works reliably, and the mac shows up with the expected variants in the lock file, so I am positive this works as expected.

Windows is unchanged, nothing to test there.

The examples/pixi-build/cpp-sdl is a small example to test this with, but all the pixi-build examples should work just as well.

@wolfv

wolfv commented Jun 15, 2026

Copy link
Copy Markdown
Member

I am going to ping @h-vetinari as he might have some opinions here and I would love his input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pixi-build] Inject system-requirements as c_stdlib variants

3 participants