Skip to content

Fix: resolve compiler paths from env vars with flags#435

Open
zhusy54 wants to merge 1 commit intohw-native-sys:mainfrom
zhusy54:cc-compile
Open

Fix: resolve compiler paths from env vars with flags#435
zhusy54 wants to merge 1 commit intohw-native-sys:mainfrom
zhusy54:cc-compile

Conversation

@zhusy54
Copy link
Copy Markdown
Contributor

@zhusy54 zhusy54 commented Apr 2, 2026

Summary

  • Add _resolve_compiler() helper in python/toolchain.py to safely handle CC/CXX env vars that contain compiler flags (e.g. conda-derived gcc -pthread -B /path/compiler_compat)
  • Fix IndexError when env var is set to whitespace-only string
  • Update GxxToolchain and Gxx15Toolchain to use self.cc_path/self.cxx_path as defaults, ensuring consistency between the C and C++ compiler defaults
  • Gxx15Toolchain now defaults to gcc-15/g++-15, consistent with its c++23 requirement

Root Cause

When pip install uses scikit-build-core's isolated build environment, Python's sysconfig.CC (gcc -pthread -B .../compiler_compat) is injected as the CC environment variable. This value contains flags and is not a valid CMAKE_C_COMPILER path, causing CMake configuration to fail.

Testing

  • python3 -m pip install -e . --user --force-reinstall succeeds without setting CC/CXX
  • Verified on conda environment where sysconfig.CC contains extra flags

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a _resolve_compiler utility to correctly parse compiler paths from environment variables, specifically handling cases where the variables include additional flags. The Gxx15Toolchain and GxxToolchain classes were updated to use this utility. Review feedback recommends moving the resolution logic into the class constructors to ensure that all compiler invocations, including those outside of CMake, consistently respect the environment variables.

Added _resolve_compiler() helper to properly extract and resolve compiler
executables from environment variables that may contain compiler flags
(e.g., 'gcc -pthread -B /path' from sysconfig). Updated Gxx15Toolchain and
GxxToolchain to resolve CC/CXX in __init__ so all usages (CMake and direct
subprocess invocations via KernelCompiler) benefit from the resolution.

- Handle compiler env vars with embedded flags by splitting and extracting exe name
- Use shutil.which() to resolve exe name to full path via PATH
- Fix IndexError when CC/CXX contains only whitespace
- Resolve CC/CXX in __init__ so KernelCompiler direct calls also use resolved paths
- Gxx15Toolchain defaults to gcc-15/g++-15 for c++23 consistency
- GxxToolchain uses self.cc_path/self.cxx_path in get_cmake_args for simplicity
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