Repository navigation
Description
Summary
Replace the unconditional xcrun --show-sdk-path shell-out used for Darwin SDK discovery in the c_import bridge with a With-owned target-SDK configuration/discovery path. Target SDKs are legitimate target inputs; discovering them by spawning a host tool on every compile is an implementation gap that breaks hermetic builds and cross-compilation.
Spec
§16.1 c_import (Target C headers are inputs / Cross-compilation):
- "Platform libc headers, operating system SDKs, vendor headers, and package headers are part of the target environment being imported. They may be supplied by the host platform SDK, by package metadata such as
with get c.*, bywith.toml, or by build target include paths." - "They are target inputs, not a dependency on an arbitrary host LLVM/Clang installation."
- "Any remaining shell-out to host tools for SDK discovery or macro/preprocessor helper paths is an implementation gap, not a language requirement."
Current state
get_sdk_path in src/compiler/ClangBridge.w:650-668: on macOS, the first call builds argv xcrun --show-sdk-path (ClangBridge.w:660-661), runs it via capture_command_stdout (ClangBridge.w:620, backed by with_exec_argv_capture) with a 30s timeout, and caches the first output line in sdk_path_buf. Every libclang session passes the result as -isysroot: ClangBridge.w:1170 (main parse), 2185 (macro collection), 2447, 2531, plus the cc helper paths via append_cc_common_args (ClangBridge.w:637; see #348).
Contrast: the Clang resource dir is already self-contained — get_clang_resource_dir (ClangBridge.w:677-689) uses only the embedded resources plus the WITH_CLANG_RESOURCE_DIR override, with an explicit comment that probing external LLVM is forbidden. SDK discovery never got the same treatment.
Failure mode today: no xcrun (non-Xcode host, sandboxed CI) → empty sdk_path_buf → libclang parses without -isysroot → 'stdio.h' file not found with no hint that the target SDK input is missing.
Implementation plan
- Add a configuration-first resolution order in
get_sdk_path(or a newresolve_target_sdk_pathit delegates to):WITH_SDKROOTenv override (and honor the conventionalSDKROOTif set — Xcode populates it, no process spawn needed);with.tomlkey (e.g.[c_import] sdk_path = "..."insrc/compiler/ProjectConfig.w— add toproject_config_wants_key/project_config_apply_entrynext toinclude_paths, ProjectConfig.w:148-149/254-255) and/or build-target input plumbed the same wayg_cimport_include_pathsis;- well-known filesystem probe on Darwin: check
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdkand/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdkfor existence (stat via runtime fs calls — file checks, not process spawns).
- Delete the
xcrunargv construction (ClangBridge.w:656-662) and the now-unused temp-file plumbing for it. Do not keepxcruneven as a last resort — that re-introduces the silent host-tool dependency this issue exists to remove. - Loud diagnostic when required but unresolved: when a
c_importparse fails AND no SDK path was resolved on Darwin, the c_import failure diagnostic must say so, e.g.c_import: no macOS SDK found for target headers; set SDKROOT/WITH_SDKROOT, configure [c_import] sdk_path in with.toml, or install Command Line Tools— naming the missing target input, not a host tool. Do not fail eagerly when the header parses without an SDK (pure local-header imports must keep working with no SDK at all). - Do not probe system LLVM/Clang resources as a workaround (AGENTS.md Self-Contained Toolchain;
get_clang_resource_dircomment is the precedent). - Pure compiler-source change (ClangBridge.w + ProjectConfig.w); no rt/Link.w/seed coupling. Normal
with build/:fixpointgates apply. Note ClangBridge is compiled into the compiler; the installed seed keeps its baked-in behavior until a new seed is installed (expected, not a hazard).
Test plan
test/behavior/behav_c_import_sdk_header.w:use c_import("stdio.h")+ call a modeled value function — proves system-header import still works after the change (macOS CI has CLT SDK at the well-known path).- No-
xcrunregression: internals/driver test that runs the compiler withPATHemptied ofxcrunandSDKROOTpointing at the CLT SDK;c_import("stdio.h")must still succeed (proves resolution no longer spawnsxcrun). test/compile_errors/err_c_import_missing_sdk.w(driver-level, envWITH_SDKROOT=/nonexistentwith probes disabled or pointing nowhere)://! expect-error:containing "no macOS SDK" / "target SDK" guidance text.- Local-header import with no SDK resolvable (env-sanitized): local
.hvia include path must import fine — proves SDK is optional for non-system headers.
Acceptance criteria
- No
xcruninvocation remains insrc/compiler/ClangBridge.w. - SDK resolution order is: explicit env (
WITH_SDKROOT/SDKROOT) → with.toml/build-target config → well-known path stat-probes; no process spawn in any branch. - Missing-SDK failures name the missing target SDK/sysroot input and the three remedies; missing host tools are never mentioned because none are used.
- System-header
c_importcontinues to work on a normal macOS host; local-headerc_importworks with no SDK at all. -
with build && with build :fixpoint && with build :testpass.
Dependencies
- c_import macro helpers still shell out to cc -E #348 (cc -E helpers in the same file share
append_cc_common_args; coordinate). - --target flag and cross-compilation path (§18.5) #425 (--target/cross-compilation will extend the same target-input configuration surface).
- with.toml: feature flags, target defaults, defines/link-libs, version constraints (§18.5a) #450 (with.toml allowed-keys work; the
[c_import] sdk_pathkey should land consistently with that issue's key inventory).
Traceability
Per spec §16.1 (v7.0 rework): SDK discovery shell-outs are implementation gaps, not language requirements.
Activity
Resolve Darwin c_import SDK without xcrun (#349)
ehartford commentedon Jun 17, 2026
Implemented in 3256541.
ClangBridge.get_sdk_pathno longer shells out toxcrun. Resolution is now spawn-free:WITH_SDKROOT, then the Xcode-populatedSDKROOTenv varwith.toml[c_import] sdk_path(new ProjectConfig key, plumbed viaci_set_sdk_pathalongside include_paths)The
xcrunargv + temp-file plumbing is deleted. A c_import header-parse failure with no resolvable SDK on macOS now appends a directional hint naming the missing target SDK input and the three remedies (never a host tool, since none is used). Local-header imports still work with no SDK at all.Acceptance criteria
xcruninvocation remains insrc/compiler/ClangBridge.w(verified:grep xcrun→ none)stdio.h→ SEEK_SET/SEEK_END); local-header works with no SDKNote: the
cc -Emacro-helper shell-outs in the same file shareappend_cc_common_argsand are tracked separately in #348.