Skip to content

Add cmake.environmentSetupScript for preset mode#4996

Open
vasdal wants to merge 1 commit into
microsoft:mainfrom
vasdal:feature/preset-environment-setup-script
Open

Add cmake.environmentSetupScript for preset mode#4996
vasdal wants to merge 1 commit into
microsoft:mainfrom
vasdal:feature/preset-environment-setup-script

Conversation

@vasdal

@vasdal vasdal commented Jul 7, 2026

Copy link
Copy Markdown

This changes visible behavior + adds a setting

The following changes are proposed:

  • Add a cross-platform cmake.environmentSetupScript setting. When using CMake
    Presets, CMake Tools sources (Linux/macOS) or calls (Windows) the script and
    uses its environment as the parent environment.
  • The script env is applied to both $penv{}/include resolution and to
    per-preset expansion + the configure/build/test spawn, so a single script
    bootstraps everything. Cached by script path + mtime; re-applied on change.
  • Reuses the kit's script-sourcing code (no behavior change for kits).

The purpose of this change

Presets can only auto-bootstrap a parent environment on Windows (vcvarsall via
tryApplyVsDevEnv). On other platforms there's no way to source a setup script,
so environments whose variables are large, interdependent, or produced by a
tool's own setup script can't be used with presets: $penv{...} in
include/toolchain paths doesn't resolve (presets may fail to load) and
find_package() fails at configure time. Reconstructing such environments as
static cmake.environment entries isn't viable; sourcing the script is — which
is exactly what kits already do. This brings that to preset mode,
cross-platform.

Other Notes/Information

  • Same __parentEnvironment seam as the VS Dev Env; no new driver plumbing.
  • Setting value supports ${workspaceFolder}-style substitution.
  • eslint clean; yarn.lock untouched; no dependency changes.

Presets can only bootstrap a parent environment on Windows (vcvarsall via
tryApplyVsDevEnv). Add a cross-platform setting that sources (Linux/macOS) or
calls (Windows) a script and uses its environment for presets, so environments
that cannot be expressed as static variables work with presets.

The script env is applied both to include/`$penv{}` resolution (via the presets
controller's settings environment) and to per-preset expansion and the
configure/build/test spawn (via preset.__parentEnvironment). Cached by script
path + mtime; re-applied when the setting changes.
@vasdal

vasdal commented Jul 7, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant