Repository navigation
Conversation
…time (macOS) zig cc's Mach-O linker resolves relative -L/-l (see resolveColonLibraries) but not a relative -F framework dir, so `-framework Foo` against a sysroot passed with a relative -F fails 'unable to find framework ...: searched paths: none'. Rewrite relative -F/-iframework dirs to absolute at exec time (cwd = execroot), the framework-dir analog of the existing relative -L handling. macOS-scoped; existing dirs only; cache-safe (action key still sees the relative flags). Full rationale + repro: #1.
0388d21 to
f947d66
Compare
|
Closing this — the premise is wrong. zig cc's Mach-O linker resolves relative What actually happenszig's clang option table ( So Verified letter map (
Absolute paths only ever worked because they start with So the rule this patch encodes ("relative -F is ignored, absolutize it") is not the actual behavior, and The fix, on the consumer sidePrefix the glued path with linkopts = [
"-F./" + _MACOS_SDK_PATH + "/System/Library/Frameworks",
"-L./" + _MACOS_SDK_PATH + "/usr/lib",
]Keeps the path relative (cache/RBE correct) and single-token (so rules_rust's trailing Verified end to end against
Control: same base, unprefixed linkopts -> uber#263 (the The real bug belongs upstream in zig: the clang-cl joined options should be gated to cl mode rather than matched in |
Absolutize relative
-F/-iframeworkframework search dirs at exec time (macOS)Stacks on the external-sysroot feature (uber#263); base
here is that feature pinned at
01d6714so this diff is only the framework-dirfix.
The bug it fixes
zig cc's self-hosted Mach-O linker resolves a relative
-L/-lsearchpath fine — the wrapper already relies on this in
resolveColonLibraries,where cwd is the Bazel execroot — but it does not resolve a relative
-Fframework search dir. A framework dir has to be absolute for thelinker to search it. So a relative
-Fexternal/…/System/Library/Frameworks(exactly what Bazel emits) makes any
-framework Foofail with:Neither obvious alternative helps:
-isysroot <sdk>alone does not add the sysroot'sSystem/Library/Frameworksto the framework search path (zig's linker,unlike Apple
ld64, doesn't auto-search it);-Wl,-F/-Wl,-syslibroot—is rejected by zig as an unsupported linker arg.
An absolute
-Fis the only lever that works.Why it has to live in the wrapper
Bazel only ever emits execroot-relative paths (for cache-correctness and
remote-execution portability), and nothing at analysis time — not even a
custom Starlark rule — can produce an absolute execroot path, because the
execroot isn't known until the action runs. Only a runtime wrapper, executing
in the execroot, can absolutize it. So
absolutizeFrameworkDirsrewritesrelative
-F/-iframeworkdirs to<cwd-abs>/<dir>at exec time. This is theframework-dir analog of the existing relative-
-Lhandling inresolveColonLibraries.Scope / safety
-F/-iframeworkonly appear on Apple-frameworklinks, so non-macOS compiles are untouched.
path, or one that doesn't exist, is left as-is (no behavior change).
"-F" "dir") and fused ("-Fdir") spellings, for-Fand-iframework.original relative flags.
Minimal repro
A
cc_binarylinking an Apple framework against a vendored SDK exposed with arelative
-F, built with this toolchain as the host/exec cc toolchain:with the sysroot feature pointing zig cc at the SDK via a relative
-Fexternal/…/System/Library/Frameworks. Before this change the link failsunable to find framework 'CoreFoundation'. searched paths: none; after it,it links and runs (exit 0). Same fix unblocks protobuf/Abseil's
-framework CoreFoundation, a Cocoa#importchain, and rules_swift's compile worker.