Repository navigation
macOS builds and links with no host toolchain: the SDK's sysroot and lld, framework stubs, SDK cmake/ninja, dsymutil (#1915) - #1926
Merged
Merged
Conversation
added 11 commits
September 30, 2026 01:23
…ds no Apple SDK (#1915) Eric (2026-09-29): "I want *zero* dependencies in *all* platforms ... except our own SDK and system calls." and "our SDK is built per-platform to provide exactly what's needed to compile With on that platform." The darwin sysroot (build/sdk.w run_darwin_sysroot_action, `:darwin-sysroot`) is built from two pinned inputs fetched by URL+sha256, so no C header is committed here: - Zig 0.16.0's source archive (codeberg.org/ziglang/zig, sha256 966f1702…): lib/libc/darwin/libSystem.tbd (the stub Zig generates from the macOS 26.4 SDK) and lib/libc/include/any-darwin-any (Apple's Libc/xnu/libpthread headers, APSL-2.0 or BSD per file; Zig itself MIT). Zig's releases ship exactly this tree to link for macOS from any host. - LLVM 22.1.6's libc++ ABI list for arm64-apple-darwin (Apache-2.0 WITH LLVM-exception, sha256 15f185e6…): libc++.tbd is generated from its defined symbols; libc++.1.dylib is part of every macOS since 10.7. It holds usr/lib/{libSystem,libc,libm,libpthread,libdl,libc++}.tbd, usr/include, an SDKSettings.json clang's driver parses, and PROVENANCE naming both sources and their licenses. No framework stubs: an application links its frameworks through its dependencies (`with get`) or by hand. Off macOS the pack is empty and nothing is fetched. The darwin SDK package carries the tree as sysroot/. The compiler's own link (llvm_ld.rsp / llvm_link.rsp) now names that sysroot as -syslibroot, links -lc++ through our stub, and no longer probes or reads SDKROOT / the Command Line Tools / Xcode. The compiler link also pulls in the SDK's lld drivers (Mach-O, ELF and WebAssembly on macOS: lld-link's manifest merger needs libxml2, which the sysroot does not stub) and aliases each `lld::<flavor>::link` and llvm::outs/errs to plain names, as with_clang_main is; the generated embedded_lld_flavors() fact says which are real. Every compiler binary embeds the sysroot pack as the `darwin_sysroot` blob (empty in cross compilers).
…, no nm (#1915) A native macOS link is now `<this compiler> __ld ...` (src/compiler/ LldDriver.w): lld's Mach-O driver linked into the binary, over the embedded darwin sysroot materialized to ~/.cache/with/sysroot/darwin-<hash> (src/compiler/EmbeddedSysroot.w; unpacked beside its final name and renamed into place). Not `cc`, not the host `ld`, no Xcode, Command Line Tools or Apple SDK. `__ld` is the compiler invoking itself, like `__ar`; a user `with ld` needs the specification to list it first. - The undefined-symbol probe reads the Mach-O symbol table itself (link_stage_macho_undefined_symbols) instead of the host `nm`. - c_import's -isysroot and `with cc`'s are compiler.EmbeddedSysroot's darwin_sdk_root(): WITH_SDKROOT, SDKROOT or with.toml [c_import] sdk_path when named, else the embedded sysroot; the Command Line Tools / Xcode probes are gone. ClangBridge stays import-free and is handed the answer. - `with cc` hands clang's driver this binary as its linker (`-fuse-ld=lld --ld-path=<cache>/ld64.lld`, a link to the compiler; run under that name the compiler is lld), so a `with get` source build links without the host's ld. - A failed macOS link prints lld's diagnostics, or the linker and its exit status, instead of a bare "error: build failed" (with PATH=/nonexistent the cc link used to fail with nothing else said). A framework the program's dependencies do not provide is lld's "framework not found". Before, under `env -i PATH=/nonexistent` in a sandbox denying /Library/Developer: hi.w failed with "could not probe ... with 'nm' (exit 127)" and "error: build failed"; a stdio.h c_import failed "'stdio.h' file not found". After: both build and run, and otool -L shows only /usr/lib/libSystem.B.dylib.
…, in :gate and the battery (#1915) build/host_toolchain.w. Two halves: 1. every link record the build writes (llvm_ld.rsp, llvm_link.rsp, llvm_ld, llvm_cc under out/bootstrap-lib, out/bootstrap/lib, out/lib) names no /Library/Developer, /Applications/Xcode, MacOSX.sdk, /usr/lib/gcc, /usr/lib/<triple>, Program Files or Windows Kits path, and no absolute path outside the repository and the SDK (.deps, or the LLVM_PREFIX a lane pins); 2. on macOS the fresh release compiler builds and runs test/host_toolchain/{hi,cimport_stdio}.w under `env -i PATH=/nonexistent` with a fresh HOME, inside sandbox-exec denying reads of /Library/Developer and /Applications/Xcode.app and exec of the host's cc, clang, ld, nm, xcrun and dsymutil; each prints its expect-stdout. The Linux and Windows slices add their sandboxed half; off macOS the verdict says it was not checked. Shown red before the fix: the pre-change release compiler fails both fixtures in the sandbox (nm probe exit 127 then a bare "build failed"; "'stdio.h' file not found"), and an Apple SDK -syslibroot or -L/opt/homebrew line appended to out/lib/llvm_ld.rsp is reported by name.
…packing in-process (#1915) Eric (2026-09-29): "`with get c.raylib` should handle that" — the frameworks a package links. The toolchain reads no Apple SDK, so a package that links Cocoa, IOKit or OpenGL gets their link stubs from the OS itself: - src/compiler/FrameworkStubs.w reads this machine's dyld shared cache (the Cryptex copy on macOS 13+, main file and sub-caches, mappings and image list), finds the framework's image, and writes a multi-document .tbd: install name, versions, LC_REEXPORT_DYLIB libraries and every symbol of the exports trie (weak and thread-local separated), then one document per re-exported library, transitively (Cocoa -> AppKit, Foundation, CoreData). CoreFoundation's stub is written in ~0.3 s. - conan_write_metadata runs it for every `-framework X` a package's link arguments name, into <dep>/Frameworks, and records "framework_paths"; the project config turns that into -F<dep>/Frameworks. A stub that cannot be written fails `with get` with the reason. - `with __framework-stubs <dir> <Name>...` runs the same step alone. Host tools `with get` no longer runs (#1915 item 3): - curl -> std.http's https_download (std.tls), retried three times; - tar xzf -> src/compiler/TarExtract.w over std.zlib (ustar, pax path and linkpath, GNU long names, directories, files, symlinks, hard links; refuses absolute and `..` names); checked against the host's tar on the raylib Conan package and the 250 MB Zig source archive (identical trees); - chmod +x -> with_fs_chmod. Still the host's: tar/unzip for .zip, .tar.xz and .tar.bz2 source archives, now with a printed warning (no With xz/bzip2 decompressor; std.zip cannot be imported into the compiler until #1919), and cmake/ninja for source builds (the spec names them the programmer's to install). Tests, red first: :no-host-toolchain gains test/host_toolchain/ framework_project, a program calling CFAbsoluteTimeGetCurrent through a with-get-style dependency whose stub `with __framework-stubs` writes in the sandbox (before: "Usage: with [command]", no such subcommand); test/ internals/tar_extract_test.w unpacks a hand-built ustar image (strip, pax path, symlink, `..` refused).
…SYM that cannot be made is a warning (#1915) A macOS debug build ran Xcode's dsymutil from PATH and ignored its failure, so with no Xcode the build silently kept no debug info. SDK side (build/sdk.w, takes effect at the next darwin SDK build): - sdk_patch_dsymutil_cfbundle: dsymutil's CFBundle.cpp reads an app bundle's Info.plist through CoreFoundation under three `#ifdef __APPLE__` guards; they become `#if 0`, so dsymutil links no Apple framework (it then takes the other hosts' path: no bundle version strings, which a plain executable has none of). Exactly three guards or the patch refuses. - sdk_archive_dsymutil_main archives dsymutil's objects (dsymutil_main, not the generated driver) as lib/libdsymutilMain.a after `ninja install`; the darwin package refuses an SDK without it. Proven by hand before wiring: the patched CFBundle.o plus this SDK build's other dsymutil objects, linked with a With caller of dsymutil_main against the darwin sysroot, depend only on libSystem and libc++ and produce a .dSYM that `dwarfdump --verify` passes. Compiler side: when the SDK has the archive the compiler link aliases dsymutil_main to with_dsymutil_main (build/compiler.w; cross and other hosts alias a stand-in), embedded_dsymutil_linked() says so, and a debug build runs `<this compiler> __dsymutil <binary>`. Until the SDK is republished it runs the host's dsymutil, and a failure prints "warning: no .dSYM for <bin>: ... exited N; its debug info is not collected" instead of nothing.
… sdk_path overrides the darwin sysroot (§16.1, D81)
D81 (spec v7.15, §16.1): "No host SDK is consulted unless the program names
one." darwin_sdk_root() followed WITH_SDKROOT and SDKROOT, which Xcode's
tools and many shells set; with SDKROOT pointing into the Command Line Tools,
a link and c_import read the Apple SDK again. Now only with.toml's
[c_import] sdk_path names another SDK; otherwise the embedded sysroot.
:no-host-toolchain's sandboxed builds set SDKROOT to the (denied) Command
Line Tools SDK. Red first: the previous release binary, so run, fails the
hi.w link ("ld64.lld: error: too many errors emitted ... build failed").
Relative paths were joined onto $PWD, and with no PWD (env -i, some launchers) left relative: in a `with get c.raylib` project, `env -i HOME=... PATH=/nonexistent with build src/main.w` failed with "'./.with/deps/c/raylib/6.0/include/raylib.h' file not found" (the pre-change release binary does the same). runtime_cwd() is $PWD, else getcwd(3) through the platform runtime's rt_getcwd; the project root, tracked inputs, module keys, the Conan launcher path and `with cc`'s linker path use it.
…1919) Exact line: src/compiler/Frontend.w frontend_fn_tier_verdict, the within-tier rule "a real fn beats any extern fn of the same name": an NK_EXTERN_FN was DROPped when any NK_FN_DECL of that name was in the tier, whatever module declared it. With `use std.libc` anywhere in the program, std.libc's `pub fn unlink` dropped a helper module's `extern fn unlink`, the helper's call bound to std.libc's fn, and Sema rejected it as "'unlink' requires an explicit import (§18.1)" (the analyzer showed no helper extern declaration left at all). Now an extern and a standard-library fn of another module both stand: the extern stays its module's global C symbol, and the std fn (a With wrapper named like the C function) is DISPLACED to its module-qualified identity (the #1350 mechanism), so each module's references bind to its own declaration and std.libc's importers keep std.libc's unlink. Outside the standard library an extern still binds to a same-name fn of the program: the compiler's bridges declare `extern fn wl_*` for functions LlvmBridge.w defines (the first cut, across all modules, left stage2 with undefined _wl_assemble_to_object and three more). A non-displaceable fn (interface or c_export) still drops the extern. test/behavior/behav_1919_extern_beside_std_fn.w (+ lib/extern_unlink_owner.w): red on the pre-change release ("requires an explicit import"), "-1 -1" with stage1. behav_1350 (both), 1362, 1703, the libc facade and SDK-header tests still pass on stage1.
…ders in With, std.zip (#1915) The last archives `with get` handed to the host's tar/unzip. - src/compiler/Xz.w: the .xz container (stream header, block headers, index, footer, stream padding, concatenated streams) around LZMA2 chunks around an LZMA range decoder. A filter chain other than a lone LZMA2 is refused by id; each block's CRC32, CRC64 or SHA-256 check is verified. - src/compiler/Bzip2.w: bzip2 streams (selectors, delta-coded Huffman tables, MTF/RLE2, inverse BWT, RLE1), concatenated streams; every block CRC and the combined stream CRC verified; randomized (0.9.0) blocks refused. - compiler.TarExtract.archive_extract picks the format by its first bytes (a URL's name need not say): gzip, xz, bzip2 tarballs, zip (std.zip). An unknown format is refused by name; the host tar/unzip fallback is gone. - ClangBridge declares unlink(2) as `@[link_name("unlink")] extern fn ci_unlink`: the pinned seed predates the #1919 fix, and the compiler now imports std.zip (std.libc). Checked against the reference tools, byte for byte / tree for tree: sed-4.9.tar.xz and gmp-6.3.0.tar.bz2 (GNU release archives), zlib 1.3.1's GitHub .zip; xz -0, -9e, --check=crc32/sha256/none, 11 blocks with -T4, two concatenated streams; bzip2 -1/-9, concatenated, long runs, empty; a damaged byte is refused (LZMA distance / block CRC). test/internals/archive_formats_test.w with test/internals/archives/ pkg-1.0.{tar.xz,tar.bz2,zip} (made by xz -9, bzip2 -9, zip -r): red on the previous commit ("undefined variable" archive_extract), ok now.
…y the compiler; C++ through `with cc` (#1915, D81) `with get` ran cmake and ninja from PATH. They are our SDK's: sdk-cmake and sdk-ninja build them into the SDK prefix, and the SDK package ships bin/cmake, bin/ninja and share/cmake-4.2. A released `with` is one file, so it carries them: build/sdk.w run_sdk_build_tools_pack_action packs the SDK's cmake, ninja and CMake modules (CMake's Help/ reference manual left out) as the `sdk_tools` blob every compiler embeds (24.7 MB; empty off macOS until that host's slice), and compiler.EmbeddedSysroot unpacks it on first use to ~/.cache/with/sdk-tools/Macos-<hash> ("E" entries are written executable). The pack/unpack code is the darwin sysroot's, generalized. conan_build_tool: WITH_CMAKE / WITH_NINJA name a tool; otherwise the compiler's own; PATH only on a host whose compiler carries none. A project that declares C++ (raylib: `project(raylib C CXX)`) gets `-DCMAKE_CXX_COMPILER=<launcher: with cc --driver-mode=g++>`, not the host c++. `with __sdk-tools` prints the unpacked directory. Proof (sandbox denying /Library/Developer, /Applications/Xcode.app, /opt/homebrew, /usr/local and exec of the host cc, c++, clang, ld, nm, xcrun, curl, tar, unzip, chmod; env -i, PATH=/opt/homebrew/bin:/usr/local/bin so the denied host tools would be found if looked for): `with get --from-source c.zlib` configured, built and installed zlib 1.3.2 (libz.a, zlib.h) in 7.6 s. Red first: the previous release failed it with "needs cmake and ninja, which are not on PATH". :no-host-toolchain runs the carried cmake and ninja (--version) in its sandbox; red first on the previous release ("`with __sdk-tools` failed").
…for raylib's source build (#1915) Reverts be9964e3. Eric (2026-09-29): the Apple framework headers raylib's source includes (IOKit, CoreAudio) are the user's to provide in real life and CI's to provision — and CI already has them (the runner's Xcode). An explicitly set SDKROOT (or WITH_SDKROOT, or with.toml's sdk_path) is how one is named (§16.1: no host SDK unless named); unset, the compiler reads only the sysroot it carries. The nightly-release macOS UAT steps set SDKROOT=$(xcrun --show-sdk-path) for the rlsw source build (#1375); the local release host takes Conan's binary raylib and needs none. :no-host-toolchain's sandboxed builds run under env -i, so no SDKROOT is named there.
added 2 commits
September 30, 2026 03:42
…or, a test fixture) The in-process client (#1915) accepted only https:// and failed conan_http_temp_test, which drives conan_http_get's temp-file handling through file:// URLs (curl had read them). conan_https_to_file now copies a file:// source (percent-escapes decoded, a Windows drive path without its leading slash) through the same temporary; an absent file is a failed download. Verified: internals-tests 57/57 (red in the stack battery).
… PreLink fixture appends lld's flag The native macOS link is the compiler's lld (#1915), not cc. A program's link arguments written for the C driver (-Wl,a,b — package metadata keeps that form) are unwrapped into a and b before they reach lld (link_stage_driver_args_for_ld); other arguments pass as written and lld names one it does not know. No test drives driver-style link arguments through this path yet; the Workspace API case below is the linker's raw argv, not this channel. cli-selfhost-build-w-tests' workspace-message case intercepts the PreLink command — the linker's own argv — and appended cc's -Wl,-dead_strip, which ld64.lld rejects: on macOS it appends lld's -dead_strip; Linux (still the C driver) keeps -Wl,--gc-sections. Verified: cli-selfhost-build-w-tests green (red in the stack battery).
ehartford
marked this pull request as ready for review
September 30, 2026 07:59
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Zero dependencies on macOS (D81, #1915). Draft until the stack battery is green.
<compiler> __ld, never cc/nm/xcrun; the compiler's own link reads no Apple SDK.with get: framework stubs generated from the running OS's dyld shared cache; downloads, tar/xz/bzip2/zip unpacking in-process; cmake and ninja from the SDK, carried by the compiler.with __dsymutil, active after the SDK republish); a dSYM that cannot be made is a warning, not silence.:no-host-toolchainin :gate and the battery: link records name no host paths; hi.w, a stdio c_import program and a CoreFoundation program build and run in a sandbox denying Xcode, the CLT and host cc/ld/nm/xcrun/curl/tar/cmake/ninja.Verified: :gate green; the raylib spiral UAT's CI route (rlsw source build, SDKROOT from xcrun) checks and builds, linking only OS frameworks and libSystem.