Skip to content

Windows compiler is self-contained: its own linker and C runtime (no LLVM_PREFIX on a fresh machine); VS-free SDK release job; stale Windows skips removed (#1915, work in progress) - #1937

Merged
ehartford merged 10 commits into
mainfrom
win-self-contained
Sep 30, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Follow-ups to #1931 under D81: the Windows compiler carries lld's COFF flavor and the SDK's C runtime so a fresh Windows checkout runs :seed → :deps → build with nothing preset; sdk-release.yml builds the windows-gnu SDK without Visual Studio; skip-on: windows markers written for MSVC headers removed where the tests pass (fixed where they don't). Work in progress; commits land as each step works. Draft.

Eric Hartford added 10 commits September 30, 2026 05:47
…, with no Visual Studio (#1915, D81)

The windows-x86_64 job fetched the v0.15.1 Visual Studio-built SDK
(.tar.zst), located Visual Studio and the Windows Kits with vswhere,
exported their include and library directories and mt.exe, and the
source-sdk action could seed missing tools from the runner's LLVM,
Chocolatey or Visual Studio's Ninja. None of that builds the windows-gnu
SDK, and D81 forbids all of it.

The job now fetches the SDK sdk.lock pins (nightly-sdk-20260930-6cd934e82b4d,
digest-checked), whose clang, clang++, lld-link, ld.lld, llvm-ar,
llvm-ranlib, cmake and ninja bootstrap the next SDK (build/sdk.w
sdk_bootstrap_set), as the SDK was built on win10. In the source-sdk
action, windows-x86_64 checks exactly that set, never seeds from the
runner (a pinned SDK that cannot bootstrap fails the lane, naming
sdk.lock), and builds with `:dev` and stage 1 without Visual Studio's
INCLUDE, LIB or mt.exe. windows-aarch64 keeps its Visual Studio recipe
until its own slice. Checked on win10: the pinned SDK passes the action's
usability test for all eight tools.
…1915, D81)

A Windows compiler linked nothing without an SDK named: a fresh checkout's
`with build :deps` could not link its fetch helper, and `with.exe` alone
could not build hi.w. It now carries what a build needs, as the macOS
compiler carries lld and its sysroot:

- lld's drivers (coff, mingw, elf, wasm, macho) are linked into a Windows
  compiler built against a windows-gnu SDK (build/compiler.w
  comp_sdk_lld_flavors; an /include line pulls each driver's member in),
  and LLVM's dlltool as `with __dlltool` (src/compiler/DlltoolDriver.w,
  comp_dlltool_link_lines, the embedded_dlltool_linked fact).
- The SDK's libc/windows, lib/clang/<major> (clang's headers and
  compiler-rt's builtins), bin/cmake.exe, bin/ninja.exe and share/cmake-<v>
  are the gzip-compressed `windows_sysroot` blob (build/sdk.w
  run_windows_sysroot_action, :windows-sysroot; 22.5 MB, 157 MB unpacked),
  unpacked into the user's cache on first use (EmbeddedSysroot
  embedded_windows_sysroot_dir; TarExtract reads the blob in memory).
- With no SDK named (no link record, no WITH_LLVM_LD / LLVM_LD /
  LLVM_PREFIX), a native Windows link is `with __ld -flavor link` over that
  toolchain (Link.w link_stage_windows_native_link_plan; the Windows link
  command now takes the toolchain directory, not an lld path); c_import,
  `with cc` and `with get` read the same directory
  (link_stage_windows_sdk_dir), `with cc` hands clang the compiler itself
  as ld.lld.exe (a link in the cache, else a copy keyed by the stamped self
  id), and the SDK tools `with get` runs are the carried cmake and ninja.
- A native Windows object is probed for undefined symbols in-process
  (Link.w link_stage_coff_undefined_symbols, regular and /bigobj COFF): no
  llvm-nm.
- `with get`'s import libraries use `with cc -E` and `with __dlltool`.
- :no-host-toolchain's Windows half empties LLVM_PREFIX, WITH_LLVM_LD,
  LLVM_LD and HOME and gives the compiler a fresh cache: it now proves the
  release compiler builds and runs its fixtures from what it carries.

Evidence on win10, release compiler of this tree (153 MB), in an
environment with only SYSTEMROOT, TEMP, a fresh LOCALAPPDATA and PATH =
C:\Windows\System32;C:\Windows (no HOME, no LLVM_PREFIX, no SDK):
`with build hi.w`, a c_import("stdio.h") program and `with cc c.c` build
and run; `with __windows-import-libs` writes gdi32/winmm/opengl32/user32;
`with init` + `with get c.raylib` + `with build` of the raylib spiral UAT
fixture builds spiral.exe (not run). :no-host-toolchain passes its three
Windows fixtures. :fixpoint: stage2 == stage3 over all 16 units. A fresh
clone of main 9adac70 plus this change, with this compiler as src/main and
no HOME or LLVM_PREFIX, ran `:deps`, `build` and `:fixpoint` green (with
the next commit's HOME fallback; before it, the pcre2 .wo install resolved
under "/.local"). The compiler is a new Windows seed candidate; it is not
published.
…#1915)

A fresh Windows checkout built in an environment without HOME (cmd.exe
and PowerShell set none; Git Bash does) failed at pcre2-wo-install-o:
"output escapes project root without install prefix:
/.local/with-wo/pcre2/windows_x86_64-.../pcre2.o". build/wo.w put the .wo
store at $HOME/.local/with-wo, and the driver expands an install
destination's `$HOME/` from HOME alone.

Both now take the home directory as $HOME, else on Windows %USERPROFILE%
with '\' as '/' (build/wo.w wo_home; src/BuildGraphSupport.w
build_graph_home_dir). On win10 a fresh clone built with no HOME,
USERPROFILE=W:\fresh2-home and no LLVM_PREFIX: `:deps`, `build` and
`:fixpoint` green.
…ain, three name the real gap (#1915)

Swept every `skip-on: windows` whose reason was MSVC's CRT or Windows Kit
headers. Each was run on win10 with the release compiler of the previous
commit in an environment with no SDK, Visual Studio or HOME (its carried
toolchain, mingw-w64's headers and UCRT), output compared with the test's
expect-stdout:

Pass, skip removed: behav_1820_c_import_integer_suffix (limits.h),
behav_1831_c_import_unprototyped_call (jn), behav_1919_extern_beside_std_fn
(unlink), behav_c_import_borrows_annotation and
behav_c_import_owns_borrows_deprecated (<dirent.h>),
behav_c_import_owning_wrapper_fopen (tmpfile/fdopen/dup), and
spec_ss16_ffi_and_c_import (limits.h).

Still Windows-only failures, reason rewritten to what is actually absent:
strndup (behav_c_import_owning_wrapper_strndup) and dirfd
(behav_c_import_borrow_param_readdir, behav_c_facade_libc_system_headers)
are POSIX functions neither UCRT nor mingw-w64's runtime defines — not a
Visual Studio artifact; lld reports them undefined.

behav_migrate_assert_macro stays skipped (#1140) and is the next commit.
… are system headers (#1915, in progress)

behav_migrate_assert_macro on win10 failed first with "migrate: parse
error: 'string.h' file not found": `with migrate` never set the
windows-gnu target and sysroot c_import sets (compiler.Frontend), so the
migrator's clang had no system include path. run_migrate_command now sets
them as the frontend does.

It then failed with "untranslatable function '__debugbreak': bailed at
GCCAsmStmt at .../libc/windows/include/_mingw.h": the migrator skips
declarations in system headers by path (ClangBridge
cimport_location_path_is_system), and the Windows C runtime's include/
matched none of its patterns. A header under the sysroot this parse names
is now a system header.

State: the test still fails, now in the user's own code: "untranslatable
function 'check_macros': bailed at CStyleCastExpr at input.c:8:71" —
mingw-w64's assert() expands to `(void) ((!!(e)) || (_assert(#e, __FILE__,
__LINE__),0))`, a shape the migrator does not lower yet (Darwin's and
glibc's reporters are modeled). Its skip (#1140) stays until that lands.
…yte (#1915)

An action's archive depended on which worker ran it: std.build's native
ToolFs.write_tar_gz deflates (zlib, default level, window bits 15 + 16,
memLevel 8, default strategy), the driver's comptime evaluator wrote
stored blocks. On win10 the Windows toolchain blob (:windows-sysroot) was
22.5 MB from the runner and would have been 157 MB from the evaluator,
which a driver whose runner is not this tree's generation falls back to.

The evaluator now compresses through std.zlib's compress_gzip with the
same parameters. One-shot and streamed deflate give identical bytes: a
3,000,000-byte input compressed both ways (the native writer's 64 KB
chunks, Z_NO_FLUSH then Z_FINISH) is 1,189,521 bytes each, equal byte for
byte. The stored-block writer and its CRC helpers are gone.

Repro: a build.w whose build() writes a tar.gz and asserts the first
deflate block is not stored (BTYPE != 0): the installed compiler fails
("build(ctx) did not return a Build value"); stage1 of this commit
passes. The cli-selfhost-build-w-tests toolfs archive fixture now asserts
the same.
… is false; std.libc models _assert (#1915, in progress)

mingw-w64's assert.h expands to (void) ((!!(e)) || (_assert(#e, __FILE__,
__LINE__), 0)). The migrator now lowers a discarded && / || as a guarded
statement (b's effects under a's truth, or its negation) instead of
dropping it, and recognizes a (Unit) C-style cast as void. std.libc gains
_assert beside __assert_rtn / __assert_fail, reporting the same way (no
function name, which mingw-w64 does not pass).

State: type-checks (with check src/main.w: ok); not yet proven on win10 by
a migrated test — committed at Eric's request mid-step.
Proven on win10 with the release compiler of the previous commit, in an
environment with no SDK, Visual Studio or HOME: `with migrate` of the
test's input.c lowers mingw-w64's
`(void) ((!!(e)) || (_assert(#e, __FILE__, __LINE__), 0))` to
`if not (e): _assert(...)` (std.libc's portable reporter), the migrated
module builds, check_macros() returns 12, the stringification wrappers
hold, and fail_assert() aborts: the test prints "ok". Two faults were on
the way, both fixed in ff95562: a (void) cast whose type translates to
`Unit` was not recognized as a discard (ci_cursor_is_void_cstyle_cast),
so the statement went through value lowering and stored a value after the
noreturn call ("error: unreachable code"); and a discarded `||` / `&&`
dropped its right operand's effects. The skip (#1140: UCRT's assert.h
expands to _wassert) described Visual Studio's headers, which no longer
exist in the toolchain.
behav_c_facade_resource_libc_dup_close ("POSIX dup/close") passes on win10
with the Windows seed candidate (31b57d91…) in an environment with no SDK
or Visual Studio — mingw-w64's runtime provides dup and close — so its skip
is removed. behav_c_import_borrow_param_readdir (the behavior copy; the
d_acceptance one was reworded earlier) still fails on dirfd alone
("lld-link: error: undefined symbol: dirfd"): its reason now says that,
not MSVCRT.
windows-x86_64 now bootstraps from nightly-20260930-local-2-bd6e00d1dee6
(with-windows-x86_64.exe 31b57d91…), the release compiler of
win-self-contained bd6e00d: it carries lld, dlltool, the SDK's C runtime,
clang's resource directory and cmake/ninja, so a fresh Windows checkout
needs no SDK, HOME or LLVM_PREFIX to run :deps and build. Built on win10
from a fresh clone by the previous seed with sdk.lock's windows-gnu SDK;
stage2 == stage3 over all 16 units. Workflow seed pins bumped by
tools/bump_seed_pins.w; :seed-driver agrees.
@ehartford
ehartford added this pull request to stack #1940 September 30, 2026 13:05
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top d55a6aa (seed-driven, with run tools/battery.w): gate rc=0, battery-checks rc=0 wall=373s. First run on 202b11e was RED (behavior-tests: behav_c_import_opaque_member_receiver — empty void C body emitted as -> Unit: with no body); fixed in d55a6aa with regression test behav_c_import_empty_void_body.w.

@ehartford
ehartford marked this pull request as ready for review September 30, 2026 14:48
@ehartford
ehartford merged commit 7dd9532 into main Sep 30, 2026
@ehartford
ehartford deleted the win-self-contained branch September 30, 2026 16:02
ehartford pushed a commit that referenced this pull request Oct 3, 2026
…is no home (#1884)

The issue's case, Windows without HOME, became the USERPROFILE fallback in
build/wo.w wo_home with #1937, after the issue's main. Two parts were
left. With no home at all (HOME unset, and USERPROFILE too on Windows)
the store still became `/.local/with-wo` and the build failed late, after
stage1 and stage2, as an install escaping the project root: on main,
`HOME= with build --graph` exits 0 and plans every wo artifact under
/.local/with-wo. And the green store (build.w green_store_install_path,
build/retention.w ret_green_store_path), `:install-user` (src/main.w)
and the driver's test-verdict and build-runner stores read HOME alone.

build/compiler.w comp_home_dir is now the one rule for the build layer:
$HOME, else %USERPROFILE% on Windows, else Diagnostics.error naming the
variables and the overrides (WITH_WO_DIR, WITH_GREEN_DIR) at graph time;
comp_home_lookup gives "" for a caller that only asks whether an explicit
store lies beneath it, and comp_home_dir_env is the action-time reading.
The driver's stores and :install-user use build_graph_home_dir (the same
rule), and :install-user refuses with no home.

test/behavior/behav_1884_build_layer_no_home.w evaluates this repo's
graph with no home and expects the refusal (rc 0 with a /.local/with-wo
plan on main). test/behavior/behav_1884_windows_install_home_unset.w
(Windows) pins the fallback: a `$HOME/` install with HOME emptied lands
under %USERPROFILE%.
ehartford pushed a commit that referenced this pull request Oct 3, 2026
…is no home (#1884)

The issue's case, Windows without HOME, became the USERPROFILE fallback in
build/wo.w wo_home with #1937, after the issue's main. Two parts were
left. With no home at all (HOME unset, and USERPROFILE too on Windows)
the store still became `/.local/with-wo` and the build failed late, after
stage1 and stage2, as an install escaping the project root: on main,
`HOME= with build --graph` exits 0 and plans every wo artifact under
/.local/with-wo. And the green store (build.w green_store_install_path,
build/retention.w ret_green_store_path), `:install-user` (src/main.w)
and the driver's test-verdict and build-runner stores read HOME alone.

build/compiler.w comp_home_dir is now the one rule for the build layer:
$HOME, else %USERPROFILE% on Windows, else Diagnostics.error naming the
variables and the overrides (WITH_WO_DIR, WITH_GREEN_DIR) at graph time;
comp_home_lookup gives "" for a caller that only asks whether an explicit
store lies beneath it, and comp_home_dir_env is the action-time reading.
The driver's stores and :install-user use build_graph_home_dir (the same
rule), and :install-user refuses with no home.

test/behavior/behav_1884_build_layer_no_home.w evaluates this repo's
graph with no home and expects the refusal (rc 0 with a /.local/with-wo
plan on main). test/behavior/behav_1884_windows_install_home_unset.w
(Windows) pins the fallback: a `$HOME/` install with HOME emptied lands
under %USERPROFILE%.
ehartford added a commit that referenced this pull request Oct 3, 2026
… args refused in Sema (#1954); raw source locations (#1953); in-root wo store (#1885); hex of narrow signed ints (#1907); HOME-less build (#1884); Windows copy_tree/list_files_text don't follow junctions (#1952) (#1978)

* POSIX remove_tree strips trailing separators before classifying the top path: remove_tree("link/") removed the link's target (#1951)

lstat("link/") resolves the link, so rt_remove_tree saw the target as a
directory, emptied it, and rmdir("link/") removed the target itself; the
link was left dangling and keep.txt was gone (rt/darwin_aarch64.w:539,
and the same lines in rt/linux_x86_64.w and rt/linux_aarch64.w). The entry
now copies the path without its trailing separators and walks that; a
child path never ends in one (rt_path_join). Windows already strips before
its reparse-point query (#1863).

test/behavior/behav_1951_remove_tree_symlink_trailing_slash.w: a symlink
to a directory removed with one and two trailing slashes, a tree holding a
symlink removed with a trailing slash, and a plain directory with one; the
target's file survives each. Red on main's compiler (the target directory
was removed), green on the rebuilt stage1.

* Sema refuses Vec.range with anything but one range argument: v.range(0, 1) crashed the compiler at build (#1954)

The issue's repro is `v.range(0, 1)`: two integers where the method takes
one range. Sema typed the call (check was silent), and the VEC_RANGE
lowering read the range's element type off the first argument
(src/CodegenDispatch.w:10470 wl_struct_get_type_at on an i64; lldb frame
#1 under LLVMStructGetTypeAtIndex, EXC_BAD_ACCESS at 0x0). `len()` and
`is_empty()` on a VecRange from `v.range(start..end)` build and run on
main; the crash was in the misspelled constructor, not in len.

check_method_call_parts now checks `range` beside split_at: exactly one
argument, of range type, else a diagnostic naming the spelling.
test/compile_errors/err_1954_vec_range_two_args.w and
err_1954_vec_range_int_arg.w pin the two diagnostics (check passed both on
main); test/behavior/behav_1954_vecrange_len_is_empty.w pins len() and
is_empty() over a VecRange.

* A compiler-synthesized string constant is raw: a panic location no longer reads the path's backslashes as escapes (#1953)

MirBuilder.source_location_operand (src/MirLower.w:3092) interned
`path:line:col` as a plain CK_STR, and every consumer decodes a plain
CK_STR as a source literal (CodegenDispatch str_const_text ->
decode_string_escapes; cc_string_literal_payload; comptime), so
`W:\review-1863\test\behavior\x.w` printed as `W:` CR `eview-1863` TAB
`estbehaviorx.w`. lower_synthesized_str_lit interns compiler-made text
with the raw-literal prefix the Parser gives a raw literal, which all
three decoders already honor; the location, `__FILE__` and the function
name go through it.

test/behavior/behav_1953_panic_location_backslash_path.w (Windows): runs
the compiler on a program under TEMP\...\t\r\b\boom.w and expects its
`__FILE__` and its panic location byte for byte.

* An absolute install destination beneath the project root is contained, not an escape (#1885)

build_graph_path_project_contained refused every absolute path
(src/BuildGraphSupport.w:151), so WITH_WO_DIR spelled as an absolute
in-root path (`C:/dev/wt/out/with-wo`) failed the wo install targets with
"output escapes project root". It now takes the root: an absolute path
that is the root or lies beneath it (separators normalized; case folded
on Windows) is checked as the relative path it names, anything else is
still refused. build_graph_validate_target_containment takes the root
from the dispatcher.

The issue's second half, the old store path persisting after unsetting
WITH_WO_DIR, is #1925's graph-cache env fingerprint, which landed after
the issue's main (355c20b): a removed variable hashes as empty and
re-plans. The fixture pins both: an absolute in-root store installs (red
on main's compiler with the escape message), the variable removed
re-plans to the default store, and an absolute store outside the project
is still refused.

* A narrow integer under a hex, binary or octal spec prints its own bits: i8 -2 under :x is fe (#1907)

The issue's u8 cases were fixed by #1922 (Sema's signedness reaches the
formatter, so an unsigned value zero-extends). A narrow signed value was
still sign-extended to 64 bits before with_fmt_int_spec (rt/rt_core.w)
formatted it, so `i8` -2 printed `fffffffffffffffe` under :x, :b, :o,
:X and :#x. f-strings reach the formatter through FMT_BUF_WRITE_FMT
(with_fmt_buf_write_i64_spec), a format call through FMT_SPEC; both now
pass Sema's bit width of the value in flags bits 24-31
(CodegenDispatch mir_int_spec_flags; CCodegen int_spec_flags_text for the
C backend), and with_fmt_int_spec masks a bit-pattern base to that width.
Decimal is unchanged: a negative decimal still prints '-' and its
magnitude.

test/behavior/behav_1907_hex_spec_own_width.w: the issue's u8 lines, u16
and u32, and i8/i16/i32/i64 -2 under x, 02x, #x, b, o and X. Red on the
first stage1 of this branch (fffffffffffffffe for i8), green after.
--emit-c passes the same width bits.

* One home resolver for the build's stores, and a loud stop when there is no home (#1884)

The issue's case, Windows without HOME, became the USERPROFILE fallback in
build/wo.w wo_home with #1937, after the issue's main. Two parts were
left. With no home at all (HOME unset, and USERPROFILE too on Windows)
the store still became `/.local/with-wo` and the build failed late, after
stage1 and stage2, as an install escaping the project root: on main,
`HOME= with build --graph` exits 0 and plans every wo artifact under
/.local/with-wo. And the green store (build.w green_store_install_path,
build/retention.w ret_green_store_path), `:install-user` (src/main.w)
and the driver's test-verdict and build-runner stores read HOME alone.

build/compiler.w comp_home_dir is now the one rule for the build layer:
$HOME, else %USERPROFILE% on Windows, else Diagnostics.error naming the
variables and the overrides (WITH_WO_DIR, WITH_GREEN_DIR) at graph time;
comp_home_lookup gives "" for a caller that only asks whether an explicit
store lies beneath it, and comp_home_dir_env is the action-time reading.
The driver's stores and :install-user use build_graph_home_dir (the same
rule), and :install-user refuses with no home.

test/behavior/behav_1884_build_layer_no_home.w evaluates this repo's
graph with no home and expects the refusal (rc 0 with a /.local/with-wo
plan on main). test/behavior/behav_1884_windows_install_home_unset.w
(Windows) pins the fallback: a `$HOME/` install with HOME emptied lands
under %USERPROFILE%.

* Windows copy_tree and list_files_text treat a junction or directory symlink as the link: neither walks into its target (#1952)

win_copy_tree_w and win_list_files_walk classified each entry with
GetFileAttributesW (rt/windows_x86_64.w win_is_dir), which calls a
junction a directory, so list_files_text listed the junction's target and
copy_tree copied it, from outside the tree. #1863 fixed remove_tree the
same way; the three walkers now share it: win_top_entry classifies the top
path (the reparse tag from its own FindFirstFileW entry, trailing
separators left off), and each child is classified by its listing entry
with win_is_link (reparse point + name-surrogate bit).
list_files_text lists a link as a leaf, the link itself, as the lstat
walk lists a symlink on POSIX. copy_tree copies a file link as the file
it names (POSIX open() follows one) and refuses a directory link with -21
(EISDIR), as the POSIX copy fails on a directory symlink (verified on the
Mac: copy_tree over a tree holding a dir symlink returns -21). Same change
in rt/windows_aarch64.w; the two files' walker code is identical.

test/behavior/behav_1952_windows_walkers_junctions.w (Windows), mirroring
behav_fs_remove_tree_windows_junctions.w. On win10 with the pinned seed
(nightly-20260930-local-2-bd6e00d1dee6): fails at line 58, the listing
holds the junction's target. With this branch's stage1 (:dev on win10):
passes, as do behav_fs_remove_tree_windows_junctions,
behav_fs_list_files_file_path and behav_fs_windows_unicode_names.

* p7_abs takes a drive-letter path as absolute: a Windows case directory was joined onto the root twice (#1885)

pre_d_build_runner's p7_abs treated only a leading '/' as absolute, so on
Windows p7_abs(p7_join(case_dir, ...)) spelled W:\root/W:\root/out/...
and behav_1885_in_root_store_and_env_replan.w failed on win10 with that
path in the escape message. A leading '/' or '\', or a drive letter and a
separator, is absolute. With it the #1885 fixture passes on win10 with
the branch stage1, the issue's case: an absolute drive-letter store
inside the project root.

* path_absolute_test: build_graph_path_project_contained takes the project root (#1885)

456f18f0 made containment relative to the root: an absolute path beneath
it is contained, so the predicate is now (root, path). The three cases keep
their intent under root `/root` (C:/elsewhere/x.w and /elsewhere/x.w
escape, src/x.w is contained), and the case #1885 made legal is added:
/root/out/x.w is contained.

Test: the previous file no longer compiles on stage1 ("expects 2
argument(s), found 1", the battery red); this one prints ok.

---------

Co-authored-by: Eric Hartford <[email protected]>
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