Skip to content

prelude/rust: from_any_dir.py execs the C compiler with os.execl, which does not search PATH — fails with ENOENT under the default system_cxx_toolchain (bare clang) #1491

Open

Description

@yesme

Summary

prelude/rust/tools/from_any_dir.py re-executes the C compiler with os.execl(cc[0], …). execl does not search PATH, but the default system_cxx_toolchain() (prelude//toolchains/cxx/clang:path_clang_tools) hands the shim a bare command name such as clang. The combination fails with ENOENT for every cargo_buildscript that compiles C, even though the very same toolchain compiles ordinary cxx_library targets fine — so a configuration that works everywhere else in the prelude breaks only inside the build-script shim.

Where

  • prelude/rust/tools/from_any_dir.py line 68 (unchanged between the 2026-08-22 tag and main as of 2026-09-04):
    os.chdir(args.cwd)
    try:
        os.execl(cc[0], cc[0], *cc[1:])
  • prelude/rust/cargo_buildscript.bzl: env["CC"] = _make_cc_shim(cmd = cmd_args(cxx_toolchain_info.c_compiler_info.compiler, …)) — cc[0] is exactly what the cxx toolchain declares as its compiler.
  • prelude/toolchains/cxx.bzl: system_cxx_toolchain resolves an unset compiler to the path_clang_tools default, i.e. a bare clang looked up on PATH.

Reproduce

  1. Default toolchains: system_cxx_toolchain() (no explicit compiler=), system_python_bootstrap_toolchain() with a Python ≥ 3.12 (otherwise you hit the walk_up problem first — see prelude/rust: from_any_dir.py needs Python ≥ 3.12 (Path.relative_to(walk_up=True)) but the bootstrap toolchain runs whatever host python3 is #1490).
  2. Any Rust crate whose build.rs compiles C via the cc crate, run as a cargo_buildscript (e.g. Reindeer-generated libsqlite3-sys 0.38.2 with buildscript.run = true, bundled feature).

Result:

exec failed: ['clang', '--ld-path=…/__ld_shim.sh', …]
FileNotFoundError: [Errno 2] No such file or directory: 'clang'

cxx_library targets built with the same toolchain in the same invocation succeed, because there the executor resolves clang normally.

Real-world case: yesme/hctl2#157 (worked around downstream in yesme/hctl2#165 by resolving cc/c++/ar to absolute paths in the launcher and passing them to system_cxx_toolchain via --config). Note for macOS: the absolute path has to be the /usr/bin/clang xcrun shim, not the binary inside Xcode.app, because only the shim injects the active SDK's -isysroot — one more reason a bare name is the natural configuration and the shim should be able to consume it.

Suggested fix

Resolve the executable before exec'ing, e.g.

exe = shutil.which(cc[0]) or cc[0]
os.execv(exe, [cc[0], *cc[1:]])

or use os.execvp, which does the PATH lookup itself (falling back to os.defpath when PATH is absent from the action environment).

Happy to send a PR if that is the preferred direction.

Environment

  • buck2 prelude 2026-08-22 (file identical on main at 2026-09-04)
  • Observed on macOS 26.6.2 arm64; the execl semantics are platform-independent, and the downstream workaround had to resolve absolute paths on Linux x86_64 and macOS x86_64 as well
  • Reindeer v2026.08.24.00, libsqlite3-sys 0.38.2
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