Skip to content

feat: support if(...) conditional package dependencies#6269

Merged
baszalmstra merged 4 commits into
prefix-dev:mainfrom
Hofer-Julian:conditional-package-dependencies
Jun 11, 2026
Merged

feat: support if(...) conditional package dependencies#6269
baszalmstra merged 4 commits into
prefix-dev:mainfrom
Hofer-Julian:conditional-package-dependencies

Conversation

@Hofer-Julian

Copy link
Copy Markdown
Contributor

Description

Add support for conditional dependencies in the [package] section using an if(<expression>) key inside the dependency tables, e.g. [package.build-dependencies."if(host_platform != build_platform)"]. The expression is passed through to rattler-build. The old [package.target.*] syntax keeps working but emits a deprecation warning.

Fixes #4625

How Has This Been Tested?

pixi run test

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: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}

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.

@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch 3 times, most recently from 8b45cf3 to d01ad12 Compare June 5, 2026 09:46
Comment thread tests/data/pixi-build/rattler-build-backend/smokey2/pixi.toml
@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch from d01ad12 to 8e47274 Compare June 5, 2026 13:56
@Hofer-Julian Hofer-Julian requested a review from ruben-arts June 8, 2026 12:24
@Hofer-Julian Hofer-Julian marked this pull request as ready for review June 8, 2026 12:31
@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch from 8e47274 to 62e0808 Compare June 8, 2026 12:45
@Hofer-Julian

Copy link
Copy Markdown
Contributor Author

@baszalmstra I've adapted a lot of tests to use the pass-through backend instead and removed the example satisfiability tests as we discussed.

However, I am a bit unsure about your "simple_test", maybe you can check this one out

@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch 2 times, most recently from 6ea014b to f869de9 Compare June 8, 2026 15:06
@GuillaumeQuenneville

GuillaumeQuenneville commented Jun 8, 2026

Copy link
Copy Markdown

Will this support all the parameters / virtual packages from the specificiers "rich" platforms pr? #4458

I am particularly interested in using if(__cuda)

at the moment the way to swap between cuda and non cuda dependencies is through the pixi environments. This works for workspaces but not for building packages. There is no syntax at the package level to define "these deps if CPU, these deps if GPU" as far as i know without going to rattler-build.

in the example you added in the latest commit. how do you specify to a cuda and non-cuda variant for windows and linux? This example would break for all workspace users on a machine without an nvidia gpu since they dont have the __cuda virtual package.

# --- Conditional dependencies: the feature this example shows off ---------
[package.run-dependencies."if(linux or win)"]
cuda-version = "12.*"
cuda-nvcc = "12.*"

@Hofer-Julian

Hofer-Julian commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

TODO for myself:

  • make sure that invalid syntax is correctly rejected by rattler-build
  • check whether we should bump api-version one more than v3 of it is fine to just put both changes in same bump

@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch 2 times, most recently from 1cda39a to d74b55f Compare June 9, 2026 15:27
A minimal C++ package that shows off `if(...)` conditional dependencies in a
Pixi `[package]` section.

`cuda_probe` is a tiny executable that reports which compiler built it and

@GuillaumeQuenneville GuillaumeQuenneville Jun 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuda toolkit is installable on systems without cuda drivers and the CMakeLists only checks for presence of cuda toolkit. From my understanding, users on win and linux would build unuseable cuda binaries that crash due to missing drivers instead of falling back to the CPU build.

it would be useful if the example showed how to use build variants to have a CPU and CUDA version. And how switch between them on Windows and Linux depending on the presence of the __cuda virtual package.

@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch 7 times, most recently from c1b4923 to c0ae5b7 Compare June 11, 2026 11:43
Comment thread docs/build/dependency_types.md Outdated
Hofer-Julian and others added 4 commits June 11, 2026 13:55
Add support for conditional dependencies in the [package] section using
an if(<expression>) key inside the dependency tables, e.g.
[package.build-dependencies."if(host_platform != build_platform)"]. The
expression is not evaluated by pixi; it is modelled as a dedicated
ConditionalExpression type in the project model, separate from platform
target selectors, and passed through verbatim to rattler-build as part
of pixi-build-api-version 5.

The legacy [package.target.*] tables keep working but emit a deprecation
warning that spells out the equivalent if(...) tables, and they are
removed from the JSON schema. Workspace [target.*] tables reject
expression selectors with an error pointing at the package dependency
tables.

The passthrough test backend has no jinja evaluator and panics on
if(...) conditionals instead of silently dropping them.
Cover a simple platform family condition, a complex boolean expression, a
match() condition evaluated against build variants and the error message
for an expression that does not parse.

Extend target_specific_channel_1 with stub cmake and ninja packages so the
build environment of pixi-build-cmake can be solved offline.
@Hofer-Julian Hofer-Julian force-pushed the conditional-package-dependencies branch from 584327f to 1aba46e Compare June 11, 2026 14:07
@baszalmstra baszalmstra changed the title feat(build): support if(...) conditional package dependencies feat: support if(...) conditional package dependencies Jun 11, 2026
@baszalmstra baszalmstra merged commit 206b59f into prefix-dev:main Jun 11, 2026
42 checks passed
@Hofer-Julian Hofer-Julian deleted the conditional-package-dependencies branch June 11, 2026 14:55
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.

feat(build): design platform specific package dependencies

5 participants