Skip to content

Make declared config-settings available as template keys in path settings #1607

Done

Description

@zklaus

With 1.1's declared config-settings a project can define a typed, env-bound knob (torch.variant, env PYTORCH_VARIANT) and switch settings on it through if.config-setting overrides. What it cannot do is substitute the value: there is no {torch.variant} key for build-dir or editable.rebuild-dir, so keying the build tree on the knob means one override block per value.

For PyTorch that could be seven blocks (cpu, cu126, cu130, cu132, rocm7.1, rocm7.2, xpu) that each repeat the same two lines with the value spliced in, and the list has to be edited every time a toolkit is added or retired. The overrides still have a job (selecting a preset, a build type), but the directory keying wants one line: build-dir = "build/{torch.variant}".

Proposal: add the resolved declared settings to the formatting namespace of the templated path settings, under their declared name (dotted names are fine as format keys when passed via a mapping, or they could be exposed as {config-setting.torch.variant} / a sanitized form). An unset setting with no default should format as empty or error, whichever matches current practice for the other keys. The values are already resolved before build-dir is formatted, so this looks like a pure plumbing change in the same pyproject_format call.

Related: #1606 asks for a {build_dir} key in the same namespace.

Drafted with an AI assistant from our measurements against 1.1.1, reviewed and edited by me.

Activity

  1. added a commit that references this issue on Oct 27, 2026
    5bca196
  2. added 2 commits that reference this issue on Nov 18, 2026
    99587bb
    90546a7
  3. henryiii commented on Nov 25, 2026

    @henryiii
    Collaborator

    Okay, assuming #1637 goes in (I like that one), the three requests together look like this:

    🤖 AI text below 🤖

    All three requests (#1606, #1607, #1608) work for PyTorch on this branch. I tested at the settings and metadata level only. I did not do a full CMake build.

    Changes to PyTorch (in ~/git/scikit-build-projects/pytorch, new branch skbc-format-keys from current upstream main, not committed):

    build-dir = "build/{variant}"
    
    [tool.scikit-build.config-setting."torch.variant"]
    env = "PYTORCH_VARIANT"
    
    [tool.scikit-build.format-keys]
    variant = { config-setting = "torch.variant", default = "cpu" }
    
    [[tool.dynamic-metadata]]
    provider = { path = "tools/metadata", module = "dependencies" }
    variant = "cpu"
    tool.scikit-build.config-setting.variant = "torch.variant"
    
    [tool.scikit-build.editable]
    rebuild-dir = "{build_dir}/install/{wheel_tag}"

    The dependencies provider now takes a variant setting. If PYTORCH_EXTRA_INSTALL_REQUIREMENTS is not set, it reads the requirements for that CUDA variant from the table in .github/scripts/generate_binary_build_matrix.py.

    Results, from calling the real get_build_dir, get_editable_rebuild_dir and prepare_metadata_for_build_wheel:

    Input build-dir rebuild-dir Requires-Dist
    nothing build/cpu build/cpu/install/<tag> base only
    -C torch.variant=cu132 build/cu132 build/cu132/install/<tag> CUDA 13.2 set
    PYTORCH_VARIANT=cu134 build/cu134 build/cu134/install/<tag> CUDA 13.4 set
    SKBUILD_BUILD_DIR=/tmp/elsewhere /tmp/elsewhere /tmp/elsewhere/install/<tag> follows variant
    PYTORCH_VARIANT=a/b clear error: must be one path component

    So -C and the environment variable now give the same build tree and the same dependencies, which was the split described in #1608. If both are set, the environment variable wins, as documented.

  4. henryiii commented on Nov 25, 2026

    @henryiii
    Collaborator

    And, a followup for using variant-label:

    🤖 AI text below 🤖

    They work together in one direction only. A declared knob can select the variant label, but the label cannot drive anything else. I tested this with SettingsReader on a small pyproject:

    Pattern Result
    torch.variant → override sets variant-label = "cu132" Works. The label and format-keys both resolve.
    format-keys.variant = { config-setting = "variant-label" } Error: references undeclared config-setting 'variant-label'
    if.config-setting."variant-label" = "cu132" Error: 'variant-label' is not declared

    variant-label is a built-in setting that can only be set from config-settings or an override. It is not a declared config-setting, so the new plumbing cannot see it.

    What this means for PyTorch:

    • torch.variant must stay the main knob. Users should not pass -Cvariant-label directly, because then build-dir and the dependencies do not follow it.
    • Override values are not templated, so selecting the label needs one override block per variant. That brings back the seven-block list from Make declared config-settings available as template keys in path settings #1607, but only for one line in each block:
      [[tool.scikit-build.overrides]]
      if.config-setting."torch.variant" = "^cu132$"
      variant-label = "cu132"
    • {wheel_tag} does not contain the variant label. A build or rebuild directory keyed on the tag alone puts all variants in the same directory, so key it on {variant} too, as my adaptation does.
    • Dynamic-metadata providers get the knob, but not the label or the [variant.variants.<label>] properties. Under PEP 817, the dependencies are exactly what changes between variants, so this is the next gap.

    Possible follow-ups, in order of value:

    1. Let variant-label take { config-setting = "torch.variant" }, the same form as cmake.define. This removes the per-variant override blocks.
    2. Add a built-in {variant_label} format key, empty when no label is set. Then build-dir = "build/{variant_label}" works with no declared setting.
    3. Give dynamic-metadata providers the label and its properties, through the same reserved-key mapping as feat: map config-settings to dynamic-metadata plugin settings #1632.
    4. Add an if.variant-label override condition. This is less important once items 1 and 2 exist.

    Item 1 plus item 2 would let the label alone, or a knob mapped to it, drive the whole build. Tell me if you want me to start on any of these.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions