Skip to content

feat(pixi-build-cmake): Extract compilers from CMake project and use toolchain file to set compilers - #6782

Open
hunger wants to merge 3 commits into
mainfrom
push-rzkystvtpnws
Open

feat(pixi-build-cmake): Extract compilers from CMake project and use toolchain file to set compilers#6782
hunger wants to merge 3 commits into
mainfrom
push-rzkystvtpnws

Conversation

@hunger

@hunger hunger commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

Extract the languages the CMAke project uses from the CMakeLists.txt file. Ask Conda to install those compilers and use a toolchain file to set up CMake to use the compilers.

This change is a bit bigger than I wanted it to be, but it is mostly pretty straight forward code to parse the project statement that should be in any top level CMakeLists.txt.

How Has This Been Tested?

Manually + generated unit tests

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.

The build script created and entered `build` by writing the name out, next
to a template variable holding the same name and the NINJA_BUILD_DIR
constant that the input tracking uses to find the tree again afterwards.
Three spellings of one name, and the two in the template were already out of
step: the Windows branch used the variable, while the Unix branch and the
shared `pushd` did not.

Nothing misbehaves today, as all three say `build`. Changing one of them is
what breaks: the input tracking would go looking for a tree the script no
longer creates, and no test would notice.

The constant is now the single definition and reaches the template through
the context, the way the source directory already does. The rendered scripts
are unchanged.
@hunger
hunger requested a review from Hofer-Julian August 6, 2026 12:20
@hunger
hunger force-pushed the push-rzkystvtpnws branch from 27dcccb to 610862d Compare August 6, 2026 15:01
Tobias Hunger added 2 commits August 6, 2026 17:41
The backend requested a C++ compiler for every package and left the package
metadata to the manifest. CMake requires the top level CMakeLists.txt to call
project(), which declares the languages the build enables along with its
version, description and homepage.

Parse that call and use it for both: request exactly the compilers the
declared languages need, and fill in metadata the pixi.toml leaves out. A
command name inside a quoted argument, such as a help text that mentions
project(...), is text rather than a call and is skipped.

Anything the manifest declares still wins, as it does for the Cargo.toml and
pyproject.toml of the other backends. When the languages cannot be determined
the backend assumes C and CXX, the same default CMake applies to a project()
call that names none. Values CMake only expands while configuring, such as
VERSION ${DEMO_VERSION}, cannot be resolved here and are skipped.
…file

The conda compiler packages only export their compiler through CC, CXX and
friends, leaving the choice to CMake's own detection. Write a toolchain file
that names those compilers explicitly and pass it to the configure step, so
the choice is visible in the build directory and propagates to sub-builds
that inherit CMAKE_TOOLCHAIN_FILE.

Every entry is guarded on its environment variable, so a compiler the build
environment does not export keeps CMake's detection. A user supplied
toolchain file in extra-args still wins, as CMake honors the last one.
@hunger
hunger force-pushed the push-rzkystvtpnws branch from 610862d to a6740d4 Compare August 6, 2026 18:25
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