From f3d177322f13209b152883e64a3eb985f64c1ba5 Mon Sep 17 00:00:00 2001 From: Teddy Sudol Date: Fri, 15 May 2026 18:40:20 -0700 Subject: [PATCH 1/2] Use get_tool_for_action and absolutize CC-related paths --- uv/private/pep517_whl/build_helper.py | 16 +++++++++++++--- uv/private/pep517_whl/rule.bzl | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/uv/private/pep517_whl/build_helper.py b/uv/private/pep517_whl/build_helper.py index a5107788b..bdb232701 100644 --- a/uv/private/pep517_whl/build_helper.py +++ b/uv/private/pep517_whl/build_helper.py @@ -48,12 +48,22 @@ # Get a path to the outdir which will be valid after we cd outdir = path.abspath(opts.outdir) -# Resolve CC/CXX to absolute paths so they remain valid after cwd changes -# into the extracted source tree (Bazel sets these as exec-root-relative). -for _cc_var in ("CC", "CXX"): +# Resolve compiler variables to absolute paths so they remain valid after cwd +# changes into the extracted source tree (Bazel sets these as +# exec-root-relative). +for _cc_var in ("CC", "CXX", "SYSROOT"): if _cc_var in os.environ and not path.isabs(os.environ[_cc_var]): os.environ[_cc_var] = path.abspath(os.environ[_cc_var]) +if "SYSROOT" in os.environ: + _sysroot = os.environ["SYSROOT"] + _sysroot_cflag = f'--sysroot="{_sysroot}"' + if "CFLAGS" in os.environ: + _cflags = os.environ["CFLAGS"] + os.environ["CFLAGS"] = f"{_cflags} {_sysroot_cflag}" + else: + os.environ["CFLAGS"] = _sysroot_cflag + # Preserve PATH so native sdist builds can find compilers (clang, gcc). build_env = dict(os.environ) build_env.update({ diff --git a/uv/private/pep517_whl/rule.bzl b/uv/private/pep517_whl/rule.bzl index 14f1cfcb8..a8d64e7e8 100644 --- a/uv/private/pep517_whl/rule.bzl +++ b/uv/private/pep517_whl/rule.bzl @@ -6,6 +6,8 @@ build backend the sdist declares in its `[build-system]` table. """ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", find_cc_toolchain = "find_cpp_toolchain") +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME") load("//py/private/toolchain:types.bzl", "NATIVE_BUILD_TOOLCHAIN", "PY_TOOLCHAIN") CC_TOOLCHAIN = "@bazel_tools//tools/cpp:toolchain_type" @@ -70,8 +72,27 @@ def _pep517_native_whl(ctx): # rather than falling back to whatever is on the system PATH. cc_toolchain = find_cc_toolchain(ctx, mandatory = False) if cc_toolchain: - env["CC"] = cc_toolchain.compiler_executable + feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + ) + c_compiler_path = cc_common.get_tool_for_action( + feature_configuration = feature_configuration, + action_name = C_COMPILE_ACTION_NAME, + ) + # Note that these paths are relative to the bazel exec root, + # and they need to be absolutized if they're to be invoked from any + # other working directory. (e.g. in build_helper.py for sdist builds.) + env["CC"] = c_compiler_path extra_inputs.append(cc_toolchain.all_files) + # We can extract the relative path to the @llvm-provided sysroot from + # the list of include directories. + # It still needs to be absolutized, so we can't add it directly to + # CFLAGS here. + for c in cc_toolchain.built_in_include_directories: + if c.endswith("sysroot"): + env["SYSROOT"] = c + break ctx.actions.run( mnemonic = "PySdistNativeBuild", From c72643a16ff442d3291afdba93d80917c2349449 Mon Sep 17 00:00:00 2001 From: Teddy Sudol Date: Mon, 15 Jun 2026 14:01:15 -0700 Subject: [PATCH 2/2] fixup! Use get_tool_for_action and absolutize CC-related paths --- uv/private/pep517_whl/rule.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uv/private/pep517_whl/rule.bzl b/uv/private/pep517_whl/rule.bzl index a8d64e7e8..8f041d51c 100644 --- a/uv/private/pep517_whl/rule.bzl +++ b/uv/private/pep517_whl/rule.bzl @@ -6,8 +6,8 @@ build backend the sdist declares in its `[build-system]` table. """ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", find_cc_toolchain = "find_cpp_toolchain") -load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME") +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("//py/private/toolchain:types.bzl", "NATIVE_BUILD_TOOLCHAIN", "PY_TOOLCHAIN") CC_TOOLCHAIN = "@bazel_tools//tools/cpp:toolchain_type" @@ -80,11 +80,13 @@ def _pep517_native_whl(ctx): feature_configuration = feature_configuration, action_name = C_COMPILE_ACTION_NAME, ) + # Note that these paths are relative to the bazel exec root, # and they need to be absolutized if they're to be invoked from any # other working directory. (e.g. in build_helper.py for sdist builds.) env["CC"] = c_compiler_path extra_inputs.append(cc_toolchain.all_files) + # We can extract the relative path to the @llvm-provided sysroot from # the list of include directories. # It still needs to be absolutized, so we can't add it directly to