Skip to content

Windows builds and links with no Visual Studio or Windows SDK: mingw-w64 UCRT runtime, compiler-rt, libc++ in our SDK; windows-gnu target; with get from source (#1915, #1916, #1925) - #1931

Merged
ehartford merged 25 commits into
mainfrom
win-own-sdk
Sep 30, 2026

Conversation

@ehartford

@ehartford ehartford commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Zero dependencies on Windows (D81, #1915; Eric's rulings 2026-09-30). Draft until the stack battery is green.

Verified on win10 with no VS/Kits: the compiler builds to a stage2 == stage3 fixpoint from a seed of this branch against the new SDK; hello, a windows.h c_import program and bzip2 via with get build and run. Mac :gate green on the five-layer stack.

Landing needs, first: a published Windows seed from this branch and the published windows-gnu SDK with the sdk.lock bump.

@ehartford
ehartford added this pull request to stack #1928 September 30, 2026 07:16
@ehartford ehartford changed the title win own sdk Windows builds and links with no Visual Studio or Windows SDK: mingw-w64 UCRT runtime, compiler-rt, libc++ in our SDK; windows-gnu target; with get from source (#1915, #1916, #1925) Sep 30, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1928 battery GREEN on the top commit 3b9d06a (win-own-sdk) — covers all five layers.

  • gate rc=0 548 s; battery-checks rc=0 406 s (≈16 min end to end).
  • Every test ran fresh on the new compiler (0 cached): behavior 1520, native-compile-error 1560, native-spec 210, native-phase 69, internals 57, codegen 17, comptime-diff 6, lexer 7, parser 9.
  • fixpoint: stage2 == stage3 over all 16 units; drop-audit and move-audit green; :no-host-toolchain green.

The previous run (6cd934e) was red on internals-tests and cli-selfhost-build-w-tests; both fixed in the macOS layer (9abc92d file:// downloads, eba9cf2 lld link flags) and the stack re-folded.

Layers 1–4 are ready to merge. Layer 5 (#1931, Windows) stays draft until the Windows seed and the windows-gnu SDK are published and pinned (in progress).

Base automatically changed from fix-int-fmt to main September 30, 2026 08:00
Eric Hartford added 19 commits September 30, 2026 04:00
…m source into the SDK (#1915)

mingw-w64 v14.0.0 is fetched at SDK build time from its pinned release tag,
exactly like LLVM, and built with the SDK's own clang and llvm-dlltool into
<sdk>/libc/windows: its headers (installed as configure would with ucrt and
0xa00 defaults), the UCRT startup objects and support libraries from
mingw-w64-crt/Makefile.am's own source lists and flags (read, not
transcribed), ucrt.lib from lib-common/ucrt.mri, and the import libraries
of the in-box DLLs the runtime and the compiler need. Licenses and a
PROVENANCE file travel with them. compiler-rt's builtins (the mingw
runtime's ___chkstk_ms and helpers) and libunwind/libc++abi/libc++ build
with compiler-rt's and the runtimes' own CMake projects against that libc.

New targets: :sdk-mingw-source, :sdk-windows-libc,
:sdk-compiler-rt-builtins, :sdk-libcxx (SDK_OUTPUT_PREFIX may name the
bootstrap SDK itself: they only add). The build-layer code avoids what the
pinned seed's comptime evaluator lacks (print, str.trim, Vec[bool] pop).
Archive members go through a response file (#1916).
…io's startup (#1915)

With's Windows objects are MSVC-environment code: LLVM calls __chkstk for
frames over a page and references _fltused wherever floating point is used.
Visual Studio's CRT defined both; the SDK's mingw-w64 UCRT runtime does not,
so the one object every Windows program links defines them, weakly, so the
compiler's own link (still Visual Studio's static CRT until the SDK's LLVM
is rebuilt against its libc++) keeps libcmt's.

The wide-argv setup asked Visual Studio's startup code for its argv mode
(_get_startup_argv_mode), which mingw-w64's startup does not export. Both
startups use the unexpanded mode (mingw-w64's wildcard.c is built with
globbing off; Visual Studio's without setargv.obj), so the runtime names it.
A program link on Windows x86_64 reads nothing but the LLVM SDK: the
mingw-w64 UCRT startup (crt2.o, mingw32, mingwex), compiler-rt's builtins,
the UCRT and the in-box DLLs' import libraries from <sdk>/libc/windows, in
lld's MinGW mode with mainCRTStartup as the entry. No Visual Studio, no
Windows Kit, no vcruntime140: every import is a DLL Windows 10 ships. The
SDK is the one the link's lld belongs to; WITH_WINDOWS_LIBC_DIR names
another libc laid out the same, and a missing one is a loud error naming
the build target that makes it. The compiler's own link (the LLVM bridge
rsp) and windows-aarch64 keep the Visual Studio recipe until their slices.

c_import for the same target parses mingw-w64's headers for
x86_64-w64-windows-gnu with the SDK's libc as clang's sysroot, so no host
gcc, Visual Studio or Windows Kit is searched (libclang's MSVC toolchain
found the Kit's headers through the registry with no environment set).

The native Windows object triple is pinned to the MSVC environment, so an
SDK whose LLVM is itself built for windows-gnu does not change what the
compiler emits. WITH_LINK_VERBOSE=1 prints each link's argv and asks
lld-link for /verbose.

behav_1915_windows_program_imports_in_box_dlls reads its own PE import
table: under the old recipe the c_import of stdio.h failed (the Kit's
inline printf); now it prints through the UCRT and imports only in-box DLLs.
… import (#1915)

- UNREFERENCED_PARAMETER(P) is `{(P) = (P);}`: a parameter assigned through
  parentheses is now bound mutably (was: cannot assign to immutable
  variable).
- An inline body that calls an inline function the import omitted is
  omitted with the reason chain (winbase.h InitializeThreadpoolEnvironment
  over winnt.h TpInitializeCallbackEnviron, omitted over an opaque bitfield
  record), instead of emitted naming an undeclared symbol.
- A packed record's flexible-array accessor offsets the record's address by
  the field's clang offset instead of referencing an underaligned field
  (mmeapi.h, winioctl.h under #pragma pack(1); §16.4).

behav_1915_cimport_mingw_header_shapes fails all three on the installed
compiler and passes on stage1.
A whole c_import("windows.h") program references GUID_NULL and the other
GUIDs the headers declare extern; mingw-w64's libuuid (built into the SDK's
libc) defines them. The Visual Studio recipe linked the Kit's uuid.lib.
…bc++; the compiler links from the SDK only (#1915)

The Windows SDK build no longer uses clang-cl, Visual Studio's STL or a
Windows Kit's mt.exe/rc.exe. After :sdk-windows-libc,
:sdk-compiler-rt-builtins and :sdk-libcxx, ninja (built against the SDK's
libc++) and LLVM/clang/lld build for <arch>-w64-windows-gnu with the
bootstrap SDK's clang, the output SDK's libc as sysroot, compiler-rt,
libunwind, libc++ and lld; the SDK's clang defaults to that toolchain for
windows-gnu targets. CMake follows LLVM, its resources compiled by the
SDK's own llvm-windres. Archives are GNU-named on every platform
(lib/libclang.a); packaging carries libc/ and the ld.lld, llvm-ar,
llvm-ranlib, llvm-dlltool, llvm-rc and llvm-windres names, and validation
requires them, the libc, libc++ and the builtins. SDK_WINDOWS_MT is gone.

The compiler's link metadata recognizes such an SDK by its libclang.a: the
rsp names the SDK's libc++ and libunwind and the Itanium clang_main, and
Link.w links the compiler like any program (mingw-w64 UCRT startup,
compiler-rt, in-box DLLs). A Visual Studio-built SDK (libclang.lib, every
SDK pinned before this) keeps the Visual Studio recipe for the compiler's
link only, until sdk.lock pins an SDK built by this recipe.
…and a stale libc++ install (#1915)

Verified by building :sdk-ninja on the Windows VM into a fresh SDK prefix:
CMake's Windows-Clang module appended gdi32/winspool/comdlg32/oldnames to
every link (the SDK carries none, clang's MinGW driver names the runtime's
own), and a rebuild of :sdk-libcxx compiled against the libc++ headers the
previous run installed into the sysroot. The SDK's ninja.exe now imports
only kernel32 and the api-ms-win-crt sets (the bootstrap's needed
msvcp140/vcruntime140).
…1915)

LLVM's configure links test programs through try_compile, whose inner
projects re-initialize CMAKE_<LANG>_STANDARD_LIBRARIES from the platform
module (gdi32, winspool, comdlg32) unless named in
CMAKE_TRY_COMPILE_PLATFORM_VARIABLES: its libstdc++ version check then
failed on the missing libraries and reported "libstdc++ version must be at
least 7.4".
…ds the libc headers; clangMain helper evaluator-safe (#1915)

Found building the windows-gnu SDK on the Windows VM: cmake.exe links
crypt32, secur32, iphlpapi and powrprof (in-box DLLs); llvm-windres
preprocesses cmake's .rc files with no sysroot, so CMAKE_RC_FLAGS names the
libc's include dir; sdk_clang_main_archive probed with with_fs_file_exists,
which the comptime evaluator cannot call.
userenv, rpcrt4, wldap32 and normaliz join the import libraries (CMake's
bundled curl, libuv and system probes), and windows-gnu CMake builds link
Visual Studio's default library set less what the SDK does not carry
(gdi32, winspool, comdlg32) instead of none: cmcldeps calls CoTaskMemFree
and reads FOLDERID_LocalAppData. :sdk-windows-libc through :sdk-cmake is
green; the SDK's cmake, ninja, clang and lld-link import only in-box DLLs.
… command-line limit is said (fixes #1916)

posix_run_argv kept argv in a fixed [256]*const u8 and returned -1, with
nothing printed, for a command of 256 or more arguments (rt/darwin_aarch64.w,
linux_x86_64.w, linux_aarch64.w: `if argc <= 0 or argc >= 256: return -1`;
posix_fill_argv stopped at 255). The table is now mapped to argc + 1
entries before the fork. On Windows the 32767-unit command line is the OS's
own limit; exceeding it now prints why before the spawn fails.

behav_1916_process_run_many_args runs itself with 300 arguments: the
installed compiler prints `run returned -1`; stage1 prints the child's
count and ok.
…x) read (fixes #1925)

build_cache_graph_key hashed build.w, build/*.w, std.build, the compiler and
with.toml, but not the variables build(ctx) read with BuildCtx.env_input.
A graph evaluated under one SDK_OUTPUT_PREFIX (or none) was served under
another: the runner, which re-evaluates build(ctx), wrote the new paths while
the driver checked the cached declarations ("did not produce declared
output" on the Windows VM). The key now includes the current value of every
variable build.w.effects recorded, and a fresh evaluation is written under
the key of what it just read.

bs_check_build_cache_tracks_env_input (the project selfhost cases) builds
with CACHE_ENV_DIR=first, removes out/first, builds with second: the pinned
seed fails with "did not produce declared output: .../out/first/stamp.txt";
stage1 builds out/second.
#1915)

With's windows-x86_64 objects become windows-gnu code, which calls
compiler-rt's ___chkstk_ms and references no _fltused. The pinned Windows
seed still emits MSVC-environment objects for stage1, so the weak
definitions stay until seed.lock's Windows seed emits windows-gnu; the
comment says so.
Eric (2026-09-30): "windows-gnu, i am ok changing debug info and code
generation". The native Windows x86_64 object triple (LlvmBridge
llvm_object_triple), TargetSpec's windows_x86_64 triple, the build layer's
cross triple and the driver's --target spellings are the GNU environment's;
the x86_64-pc-windows-msvc spelling is no longer accepted (it would name
code the compiler does not emit). The c_import target was already
windows-gnu, so the long double mismatch between parsed headers and emitted
code is gone. Debug info stays CodeView (dbghelp backtraces read the PDB
lld-link builds from it). windows-aarch64 stays MSVC until its slice.

WITH_ABI_VERSION 9 with a docs/spec/abi/with-abi.md history entry; the
ABI hashes are re-recorded. behav_1915_windows_target_is_gnu fails on the
installed compiler (target triple x86_64-pc-windows-msvc) and passes on
stage2; the cross-target ABI tests (c_abi_small_structs, fn_abi_callable,
c_va_list_target_abi, variadic_definition_target_abi, fn_abi_async) pass.
The archiver a `with get` source build runs wrote a symbol index for ELF
and Mach-O members only; a Windows build's COFF objects got none, and the
package's own bzip2.exe failed to link against libbz2.a ("undefined symbol:
BZ2_bzlibVersion"). extract_coff_symbols reads a COFF object's external
definitions (and commons and weak externals), indexed GNU-style as for ELF.

behav_1915_ar_indexes_coff_objects archives a windows_x86_64 object: no
index before, the symbol after.
…lchain (#1915)

Eric (2026-09-30): "with get builds packages from source in windows".
Conan Center's Windows binaries are MSVC builds that name Visual Studio's
CRT libraries and need its /GS runtime (bzip2: __security_cookie,
__GSHandlerCheck, /DEFAULTLIB:MSVCRT and OLDNAMES), which neither Windows
nor the SDK ships. On Windows:
- every package builds from source; a lock pinning a Conan binary says to
  re-run `with get`;
- cmake and ninja are the SDK's (bin/), never a host install;
- `with cc` compiles for x86_64-w64-windows-gnu against the SDK's libc
  (--sysroot), resource dir (compiler-rt), libc++/libunwind and ld.lld;
- CMake's Visual Studio default library list is replaced by the part the
  SDK carries;
- a `link:` name is found as the MinGW driver finds -l (lib<name>.a first),
  so a package's GNU-named archive links.

On the Windows VM with no Visual Studio, Kits or WITH_WINDOWS_*:
`with get c.bzip2` built bzip2 1.0.8 from source into libbz2.a, and a With
program calling BZ2_bzlibVersion through c_import("bzlib.h") printed
"bzip2 1.0.8, 13-Jul-2019". behav_1915_windows_link_finds_gnu_archive
fails on the previous compiler (could not open 'gnuarchive.lib') and
passes.
Eric (2026-09-30): "ship the notice with the release". A compiler linked
from a windows-gnu SDK carries mingw-w64's startup and support code, whose
licenses require their notices in a binary distribution. Beside the binary:
out/release/with-windows-x86_64-NOTICE.txt (COPYING.MinGW-w64-runtime.txt
from the SDK's libc, with a header naming the binary), written by
:package-windows-x86_64 (build/package.w pkg_write_windows_notice) and by the
nightly-release Windows job, which publishes it with the SDK asset
(RELEASE_EXTRA_FILES). A compiler linked from a Visual Studio-built SDK
contains none of it and ships no notice.
Eric Hartford added 2 commits September 30, 2026 04:57
windows-x86_64 now bootstraps from nightly-20260930-local-1-6cd934e82b4d
(with-windows-x86_64.exe af14aafe…), the first seed that emits
x86_64-w64-windows-gnu and links against the SDK's own C runtime, and
builds with nightly-sdk-20260930-6cd934e82b4d (a24652c5…), the SDK built
on win10 with no Visual Studio or Windows SDK. The seed is the
fixpoint-verified release compiler of 6cd934e built with that SDK
(stage2 == stage3 over all 16 units).

The seed pins are bumped by tools/bump_seed_pins.w. The Windows lanes of
nightly-release.yml and selfhost-windows.yml fetch the new SDK and no
longer locate Visual Studio or the Windows Kits; the nightly republishes
the verified SDK archive as is instead of repacking a .tar.zst.
…as std.build's does

`with build :package-llvm-sdk-windows-x86_64` failed on win10 at
sdk-contract-tests (build/sdk.w:1122, `fs.write_tar_gz(...) == 0`): the
action ran in the driver's comptime evaluator (the runner was not this
driver's generation), and the evaluator's writer
(comptime_tar_entry_name / comptime_tar_build_header) refused every name
over 100 bytes, where std.build's native writer splits it at a '/' into
the 155-byte USTAR prefix. The contract's entries under a 96-byte
directory returned 1 from the evaluator and 0 from the runner, so the
same build.w passed or failed by which worker ran it.

The evaluator's header is now std.build's tool_tar_build_header byte for
byte. Repro (a build.w whose build() writes pkg/<92 x>/a.txt): the
installed compiler fails "build(ctx) did not return a Build value";
stage1 of this commit writes, extracts and reads it back. The
cli-selfhost-build-w-tests toolfs archive fixture now carries a name
longer than 100 bytes, so the evaluator's writer is covered.
Eric Hartford added 4 commits September 30, 2026 04:57
`with run` on Windows printed "warning: no .dSYM for out/run.<n>/fo.exe:
no dsymutil of its own ... and the host's `dsymutil` exited 1" after
every link: Compilation.w ran dsymutil after any debug-info link, whatever
the target. A .dSYM is Mach-O's; a COFF binary's debug info is its PDB and
an ELF binary's is in its own sections. The step now runs only when the
target OS is macOS.
)

A fresh win10 checkout at the new pins failed `with build :deps`: "SDK
installed but missing expected archive:
.deps/llvm-22.1.6-windows-x86_64-msvc/lib/libclang.lib".
compiler_default_libclang_archive_path, the :deps marker, named
libclang.lib on every Windows host; the windows-gnu SDK ships libclang.a.
Only the Visual Studio-built windows-aarch64 SDK keeps libclang.lib.
…r passes (#1912)

Rechecked on win10 under the windows-gnu recipe with the release
compiler of 6cd934e:

- behav_variadic_definition_called_from_c.w passes: its case built by
  hand (`with cc -c harness.c`, `with build --link-object`) prints
  "60 1.75 145". The pre_d_build_runner assertion in nightly run
  36585839691 was the MSVC-era `cc` step.
- behav_variadic_definitions.w printed
  "9 10 11 -4294967284 4614500768194494477 14 ... 20": many_ints read
  each argument as i64, but its call passes int literals, which go as
  i32. Arguments 12 and 13 are the first two stack slots after the four
  register homes; the caller stores 4 bytes in each 8-byte slot and the
  upper half is what was there (0xFFFFFFFF, 0x400A0000). Reading a wider
  type than was passed is C's undefined va_arg (C11 7.16.1.1p2), which
  the other targets survived by luck. many_ints now reads i32, as its
  arguments are; with_trio keeps the i64 case with `as i64` arguments.
  On win10 the corrected test prints all eleven expected lines.

behav_1830, behav_1832 and behav_1849 were skipped on Windows because
MSVC's UCRT <stdio.h> defines snprintf inline; the windows-gnu recipe
links the bare prototype against the SDK's UCRT, and all three print
their expected output on win10, so the skips are removed.

Closes #1912.
…inux (#1914)

On win10 under the windows-gnu recipe, a project whose [link].libs names
a missing library prints lld-link's own message before "build failed":

    lld-link: error: could not open 'with_phase1_missing_lib.lib': No such file or directory
    error: build failed

The native Windows link inherited the compiler's stdio, so lld-link's
lines reached the terminal, but a linker that failed without a word left
only "build failed". It now runs through link_run_with_diagnostics like
the macOS and Linux links: the linker's output is captured and printed,
and a silent failure names the linker and its exit status. The
declarative_link_lib_missing case asserts the lld-link line on Windows.

A Windows link with no linker record and no WITH_LLVM_LD / LLVM_LD /
LLVM_PREFIX now says what it needs: the pinned SDK asset, extracted,
named by LLVM_PREFIX. That is the environment a fresh Windows checkout's
`with build :deps` needs to link its fetch helper, the remaining part of
#1914's third point, until the Windows compiler carries its own linker
and C runtime as the macOS one does. The helper's diagnostics already
reach the terminal (seed_compile_binary's second point): a fresh
checkout's :deps printed the linker-record error above its own failure.

Closes #1914.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on bdf58fe (#1931 + #1932 on main 55d094b).

  • gate rc=0 1077 s (every test ran fresh: behavior 1520, native-compile-error 1560, native-spec 210, native-phase 69, internals 57, codegen 17, comptime-diff 6, lexer 7, parser 9); battery-checks rc=0 151 s (verdicts from the gate's runs of this compiler).
  • fixpoint: stage2 == stage3 over all 16 units; drop-audit, move-audit, :no-host-toolchain green.
  • The pinned Windows seed (nightly-20260930-local-1-6cd934e82b4d) and windows-gnu SDK (nightly-sdk-20260930-6cd934e82b4d) are published; seed-driver agrees with the pins.

Wall 20.5 min: the gate ran alongside two agents' builds on the same Mac (the previous battery's gate took 548 s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant