Skip to content

Instantly share code, notes, and snippets.

@Hofer-Julian
Created March 28, 2025 15:32
Show Gist options
  • Save Hofer-Julian/399707042cada047074a079daa911406 to your computer and use it in GitHub Desktop.
Save Hofer-Julian/399707042cada047074a079daa911406 to your computer and use it in GitHub Desktop.
Variables Proposal

Variables in manifest

Goals:

  • Avoid repeating values
  • Make it easy to interact with a full tree of tasks
[vars]
profile = "--release"

[tasks.install]
cmd = "cargo install {{ profile }}"

[tasks.test]
depends-on = ["install"]
cmd = "cargo test {{ profile }}"
pixi run test
# Runs:
# cargo install --release
# cargo test --release

pixi run --var profile=--debug test
# Runs:
# cargo install --debug
# cargo test --debug

Cross environments

[vars]
profile = "--release"

[tasks.install]
cmd = "cargo install {{ profile }}"

[feature.test.vars]
profile = "--debug"

[feature.test.tasks.test]
depends-on = ["install"]
cmd = "cargo test {{ profile }}"

[environments]
test = ["test"]
pixi run install
# Runs:
# cargo install --release

pixi run test
# Runs:
# cargo install --release
# cargo test --debug    

pixi run --environment test test
# Runs:
# cargo install --debug
# cargo test --debug

pixi run --var "profile=--profile" test
# Runs:
# cargo install --profile
# cargo test --profile

Slightly adapted example

[vars]
profile = "--release"

[tasks.install]
cmd = "cargo install {{ profile }}"

[feature.test.vars]
profile = "--debug"

[feature.test.tasks.test]
depends-on = ["install"]
cmd = "cargo test {{ profile }}"

[environments]
test = { features= ["test"], no-default-feature = true }
pixi run install
# Runs:
# cargo install --release

pixi run test
# Runs:
# cargo install --release
# cargo test --debug    

pixi run --environment test test
# Task `install` doesn't exist in environment "test", so it will run in environment "default" instead.
# Runs:
# cargo install --debug
# cargo test --debug

pixi run --var "profile=--profile" test
# Runs:
# cargo install --profile
# cargo test --profile

Merging vars

We need to take care when we merge vars. The current behaviour is that, that the first feature wins:

[feature.test1.vars]
profile = "--debug"

[feature.test1.tasks]
start = "cargo test {{ profile }}"

[feature.test2.vars]
profile = "--release"

[envs]
test = ["test2", "test1"]

Running should behaves as follows:

$ pixi run start
cargo test --release

Keep in mind, that unless no-default-feature=true, the default feature is always implicitly appended:

test = ["test2", "test1", "default"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment