Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1be6dc0
Windows: a platform layer and host builds that pass
BobClawblaw Oct 12, 2026
e5bb3bc
Windows: CUDA kernels, the native server and the GPU suites on sm_89
BobClawblaw Oct 12, 2026
1f87b27
Windows: pull into the hub cache, HOME, and the whole test step
BobClawblaw Oct 12, 2026
996a50f
Windows: build notes, strip before install, formatting
BobClawblaw Oct 12, 2026
aac93d2
Default port 8888
BobClawblaw Oct 12, 2026
81f5576
qwen3_5: serve Qwen3.5-2B on CUDA
BobClawblaw Oct 13, 2026
3ace97e
qwen3_5: serve Qwen3.8-27B on CUDA, one arena for a model's device me…
BobClawblaw Oct 14, 2026
6b85f22
qwen3_5: replay each decode shape as a CUDA graph
BobClawblaw Oct 14, 2026
b19e0d7
qwen3_5: DFlash2 drafts for Qwen3.8-27B on CUDA
BobClawblaw Oct 14, 2026
288ba03
qwen3_5: tree drafts on CUDA, the kept path replayed from a log
BobClawblaw Oct 14, 2026
61fc2bf
docs: the Qwen hybrids on CUDA in the Windows page and the README
BobClawblaw Oct 14, 2026
6aaf241
qwen3_5, platform: comments on one line
BobClawblaw Oct 14, 2026
8107ee2
Windows: checkpoint reads skip the page cache
BobClawblaw Oct 14, 2026
693533e
Windows: the signal handler type allows address 1, for aarch64
BobClawblaw Oct 14, 2026
f53ae20
docs: Windows as a target in the README and the Windows page
BobClawblaw Oct 14, 2026
e875ee2
CI: the host unit tests on Windows
BobClawblaw Oct 14, 2026
38ecce5
qwen3_5: the drafter reads TF_TIMING through the platform layer
BobClawblaw Oct 14, 2026
1817823
qwen3_5: the drafter takes a prompt longer than its tap ring
BobClawblaw Oct 14, 2026
b811a3b
qwen3_5 cuda: prompt chunks past 32 rows see the right keys, and tree…
BobClawblaw Oct 14, 2026
0a0856b
Windows: the server goldens and the Cortheon fuzz step on Windows hosts
BobClawblaw Oct 14, 2026
ccd06b9
cuda: cuBLASLt opens by its Windows DLL name
BobClawblaw Oct 14, 2026
045abbd
Windows: writes on an O_APPEND descriptor land at the end whole
BobClawblaw Oct 14, 2026
bdfeb84
golden check: a request-log mismatch names the first differing line
BobClawblaw Oct 14, 2026
39de039
lane core and native CUDA host for two-rank families with a vision to…
BobClawblaw Oct 14, 2026
153d6b4
golden check: the request log compares with LF endings on either side
BobClawblaw Oct 14, 2026
22d92e4
lane host: a warm pass that steps aside is not launched after its can…
BobClawblaw Oct 15, 2026
ef73ec3
tf_video: the includes back under its one-line header
BobClawblaw Oct 15, 2026
cc5d9d1
vision inputs: a server without --vision refuses image parts in the f…
BobClawblaw Oct 15, 2026
aaed024
qwen_image.formatSeconds: t * 10 rounded in integers, not f128, so te…
BobClawblaw Oct 15, 2026
9e6dfcd
lane host: a set-up job's kept entry stays pinned until its restore r…
BobClawblaw Oct 15, 2026
8570e06
qwen3_5: attention chunks follow each row's own keys, not the forward…
BobClawblaw Oct 15, 2026
5e1c3fe
qwen3_5: the DFlash2 config's divisors must be positive, and staging …
BobClawblaw Oct 15, 2026
52b82fc
prompt cache: an entry removed while pinned is dead to lookups and fr…
BobClawblaw Oct 15, 2026
92c9ef4
Merge branch 'pr-853' into qwen35-vision
BobClawblaw Oct 15, 2026
73f06f1
qwen3_5: image rows and M-RoPE positions in the CUDA forward
BobClawblaw Oct 15, 2026
a10b4de
qwen3_5: the vision tower on CUDA, and --vision on the Qwen engine
BobClawblaw Oct 15, 2026
ac94f8f
tf-qwen35-cuda: vision and mrope checks
BobClawblaw Oct 15, 2026
7ad45b6
native/cuda: drop the doc comment learnBytes left behind on toGib
BobClawblaw Oct 15, 2026
3217063
CI on #885: the server's image paths build on Windows; lean and a tra…
BobClawblaw Oct 15, 2026
55c47f9
tf-qwen35-cuda vision: the tower's rows bounded, exit 1 outside them
BobClawblaw Oct 15, 2026
5296eb1
tf-qwen35-cuda: one-line comments within 120 columns (the lean check)
BobClawblaw Oct 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Windows: pull into the hub cache, HOME, and the whole test step
- pull: where Windows refuses the snapshot's symlink, the snapshot path
  becomes a hard link to its blob (CreateHardLinkW through `sys.c.link`):
  no extra space, and learning already refuses linked shards. Link
  failures are logged with their reason.
- HOME falls back to USERPROFILE (Windows sets no HOME) for the hub cache
  and every libc getenv("HOME").
- Tests read optional fixture variables through `platform.getenv`;
  std.process.Environ.getPosix does not build on Windows.
- The learned-state symlink tests skip on Windows (symlinks need
  privilege); `sys.c.symlink` asks for an unprivileged one.

zig build test passes on x86_64-windows.
  • Loading branch information
BobClawblaw committed Oct 14, 2026
commit 1f87b27911f942eaf4171c4544ae8b80cfc8fc83
2 changes: 1 addition & 1 deletion zig/src/cli/hub.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn cacheDir(a: Allocator, env: ?*const std.process.Environ.Map, override: ?[
}
}.f;
if (get(env, "HF_HUB_CACHE")) |c| return c;
const home = get(env, "HOME") orelse "";
const home = get(env, "HOME") orelse get(env, "USERPROFILE") orelse ""; // Windows sets USERPROFILE, not HOME
if (get(env, "HF_HOME")) |h| return std.fs.path.join(a, &.{ h, "hub" });
return std.fs.path.join(a, &.{ home, ".cache", "huggingface", "hub" });
}
Expand Down
18 changes: 17 additions & 1 deletion zig/src/cli/pull_file.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! One file from the hub into the blob store: range resume, size and sha256 checks, retries, and its snapshot link.
const std = @import("std");
const platform = @import("sys");
const Allocator = std.mem.Allocator;

/// One file the hub's tree lists for the revision: LFS files carry their sha256, small files their git blob sha1.
Expand Down Expand Up @@ -143,7 +144,22 @@ pub fn linkIntoSnapshot(a: Allocator, io: std.Io, snapshot_dir: []const u8, path
if (std.fs.path.dirname(link_path)) |parent| try std.Io.Dir.cwd().createDirPath(io, parent);
std.Io.Dir.cwd().deleteFile(io, link_path) catch {};
const target = try std.fs.path.join(a, &.{ "..", "..", "blobs", blob_name });
std.Io.Dir.cwd().symLink(io, target, link_path, .{}) catch return error.SymLinkFailed;
std.Io.Dir.cwd().symLink(io, target, link_path, .{}) catch |err| {
// Windows grants symlinks only with Developer Mode or elevation (and refuses some): a hard link to the blob,
// which costs no space (huggingface_hub copies instead); learning refuses linked shards either way
if (@import("builtin").os.tag != .windows) {
std.log.err("cannot link {s} to its blob: {t}", .{ link_path, err });
return error.SymLinkFailed;
}
const repo_dir = std.fs.path.dirname(std.fs.path.dirname(snapshot_dir) orelse return error.SymLinkFailed) orelse return error.SymLinkFailed;
const blob = try std.fs.path.joinZ(a, &.{ repo_dir, "blobs", blob_name });
const linked = try a.dupeSentinel(u8, link_path, 0);
_ = platform.c.unlink(linked); // the refused symlink can leave an empty file behind
if (platform.c.link(blob, linked) != 0) {
std.log.err("cannot link {s} to its blob: {t}", .{ link_path, platform.c.errno(-1) });
return error.SymLinkFailed;
}
};
}

test "a hub tree path stays inside the snapshot: relative, without . or .. segments" {
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/admission_test.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! 32 to 128 streams: what fits at 8k and 32k context, prompt rows a round, and 32 toy streams joining while others decode.
const std = @import("std");
const platform = @import("sys");
const node = @import("node.zig");
const plan = @import("plan.zig");
const budget = @import("budget.zig");
Expand Down Expand Up @@ -115,7 +116,7 @@ test "32 toy streams join while others decode, prompt chunks in the same rounds:
}

test "the admission tables for CLUSTER.md (TF_CLUSTER_REPORT=1)" {
if (std.testing.environ.getPosix("TF_CLUSTER_REPORT") == null) return error.SkipZigTest;
if (platform.getenv("TF_CLUSTER_REPORT") == null) return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/cli_test.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The cluster commands end to end on fake hosts: init, check, status, serve with in-process bring-up, and node.
const std = @import("std");
const platform = @import("sys");
const cli = @import("cli.zig");
const fixtures = @import("probe_fixtures.zig");

Expand Down Expand Up @@ -86,7 +87,7 @@ const studios =
;

test "check plans K3 from its config and Hub file list and names the raise a low node needs; serve stops before launching" {
const dir = std.testing.environ.getPosix("TF_K3_DIR") orelse return error.SkipZigTest;
const dir = platform.getenv("TF_K3_DIR") orelse return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/cost_test.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! K3 and GLM-5.3 rounds on four 512 GiB Studios at 1 to 128 rows: dedup, caches, collectives, and the MLA split.
const std = @import("std");
const platform = @import("sys");
const node = @import("node.zig");
const model = @import("model.zig");
const estimate = @import("estimate.zig");
Expand Down Expand Up @@ -66,7 +67,7 @@ test "GLM-5.3 in FP8 reads far less a token than K3, and 128 streams at 32k cont
}

test "the cost tables for CLUSTER.md (TF_CLUSTER_REPORT=1)" {
if (std.testing.environ.getPosix("TF_CLUSTER_REPORT") == null) return error.SkipZigTest;
if (platform.getenv("TF_CLUSTER_REPORT") == null) return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/estimate.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! A checkpoint's tensor table from its config and the Hub's file list, so a cluster can be planned before the weights land.
const std = @import("std");
const platform = @import("sys");
const checkpoint = @import("checkpoint.zig");
const model = @import("model.zig");
const roles = @import("roles.zig");
Expand Down Expand Up @@ -282,7 +283,7 @@ test "the K3 table matches every shard size to within its header" {
}

test "the real K3 file list (TF_K3_DIR): 96 files, 1.561 TB, every header under 0.01% of its file" {
const dir = std.testing.environ.getPosix("TF_K3_DIR") orelse return error.SkipZigTest;
const dir = platform.getenv("TF_K3_DIR") orelse return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/model.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! A model's shape from its config.json (text_config when nested): what the planner and the memory budgets need.
const std = @import("std");
const platform = @import("sys");

pub const Attention = enum(u8) { gqa, mla, linear };

Expand Down Expand Up @@ -257,7 +258,7 @@ test "GLM-5.3: every layer MLA with a 2,048-token indexer, 75 MoE layers, one MT
}

test "the real K3 config (TF_K3_DIR) parses to the literal" {
const dir = std.testing.environ.getPosix("TF_K3_DIR") orelse return error.SkipZigTest;
const dir = platform.getenv("TF_K3_DIR") orelse return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/plan_test.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Kimi K3 on four 512 GiB M3 Ultras: the default layout, layouts from a config, determinism, and refusals.
const std = @import("std");
const platform = @import("sys");
const node = @import("node.zig");
const model = @import("model.zig");
const estimate = @import("estimate.zig");
Expand Down Expand Up @@ -34,7 +35,7 @@ pub fn k3(a: std.mem.Allocator) !checkpoint.Checkpoint {
const size: u64 = if (i == 0) 2_341_216_112 else if (i < s.layers) (if (kda) 16_990_911_504 else 16_567_501_776) else if (i == s.layers) 4_697_664_072 else if (i == s.layers + 1) 92_289_328 else 802_448_352;
f.* = .{ .name = try std.fmt.allocPrint(a, "model-{d:0>5}-of-{d:0>6}.safetensors", .{ i + 1, s.layers + 3 }), .size = size };
}
if (std.testing.environ.getPosix("TF_K3_DIR")) |dir| {
if (platform.getenv("TF_K3_DIR")) |dir| {
const text = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, try std.fs.path.join(a, &.{ dir, "files.tsv" }), a, .limited(1 << 20));
files = try estimate.manifest(a, text);
}
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/status.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! What `tensorfold cluster status` and `check` print: nodes, links, memory, the placement per rank, costs and load progress.
const std = @import("std");
const platform = @import("sys");
const node = @import("node.zig");
const topology = @import("topology.zig");
const plan_mod = @import("plan.zig");
Expand Down Expand Up @@ -99,7 +100,7 @@ test "the K3 status on four Studios prints every rank, fits, and the round costs
try placement(&out.writer, &p, needs, fs);
try costs(&out.writer, &p, needs, &s, 8192);
const text = try a.dupe(u8, out.written());
if (std.testing.environ.getPosix("TF_CLUSTER_REPORT") != null) {
if (platform.getenv("TF_CLUSTER_REPORT") != null) {
std.debug.print("\n{s}\n", .{text});
const others = [_]struct { []const u8, plan_mod.Options }{
.{ "experts split by tensor parallelism", .{ .layout = .{ .tensor = 4, .expert = 1 } } },
Expand Down
3 changes: 2 additions & 1 deletion zig/src/cluster/topology.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The cluster's wiring from every node's ports: which port reaches which node, at what rate, and the graph's shape.
const std = @import("std");
const platform = @import("sys");
const node = @import("node.zig");

/// One cable: node `a`'s port to node `b`'s port (indices into the node list and their port lists).
Expand Down Expand Up @@ -134,7 +135,7 @@ test "four Macs with six cables form a mesh; three cables a chain or a star; a c
}

test "the lent cluster's real probes (TF_CLUSTER_PROBES): four M3 Ultras in a full mesh at 80 Gb/s" {
const root = std.testing.environ.getPosix("TF_CLUSTER_PROBES") orelse return error.SkipZigTest;
const root = platform.getenv("TF_CLUSTER_PROBES") orelse return error.SkipZigTest;
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
Expand Down
13 changes: 7 additions & 6 deletions zig/src/core/exlr8_oracle_test.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! EXLR8 decoding against fixtures the reference loader (MIT) wrote outside the tree: layers 0, 3, 40, 78, vocab.

const std = @import("std");
const platform = @import("sys");
const codec = @import("exlr8_codec.zig");
const ex = @import("exlr8_experts.zig");
const dense = @import("exlr8_dense.zig");
Expand Down Expand Up @@ -169,7 +170,7 @@ const Layers = struct {
};

test "expert halves of layers 3, 40 and 78: stored checksums, the reference's tiles and W bits" {
const root = std.testing.environ.getPosix("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const root = platform.getenv("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const gpa = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
Expand All @@ -193,7 +194,7 @@ test "expert halves of layers 3, 40 and 78: stored checksums, the reference's ti
h.suh(suh[0..h.rows()]);
h.svh(svh[0..h.cols()]);
try checkSamples(codes, h.rows(), h.cols(), suh[0..h.rows()], svh[0..h.cols()], unit.w_samples, false, &stats);
if (std.testing.environ.getPosix("TF_EXLR8_ORACLE_FULL")) |full| try wholeHalf(full, unit, codes, h, suh[0..h.rows()], svh[0..h.cols()]);
if (platform.getenv("TF_EXLR8_ORACLE_FULL")) |full| try wholeHalf(full, unit, codes, h, suh[0..h.rows()], svh[0..h.cols()]);
}
stats.print("expert halves");
}
Expand Down Expand Up @@ -233,7 +234,7 @@ fn wholeHalf(dir: []const u8, unit: Unit, codes: []const u8, h: ex.Half, suh: []
}

test "every half of every stored width verifies, as the reference's --verify counts them" {
const root = std.testing.environ.getPosix("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const root = platform.getenv("TF_EXLR8_DIR") orelse return error.SkipZigTest;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const fx = try load(arena.allocator());
Expand All @@ -260,7 +261,7 @@ test "every half of every stored width verifies, as the reference's --verify cou
}

test "dense and vocabulary files: records, checksums, every format bit for bit, plain tensors as shipped" {
const root = std.testing.environ.getPosix("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const root = platform.getenv("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const gpa = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
Expand Down Expand Up @@ -331,7 +332,7 @@ fn denseBits(m: dense.Matrix, unit: DenseUnit) !void {
}

test "the eight manifests parse to the reference's widths, and every width they ask of a present layer is stored" {
const root = std.testing.environ.getPosix("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const root = platform.getenv("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const gpa = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
Expand Down Expand Up @@ -371,7 +372,7 @@ test "the eight manifests parse to the reference's widths, and every width they
}

test "every present release file matches its published sha256 and size" {
const root = std.testing.environ.getPosix("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const root = platform.getenv("TF_EXLR8_DIR") orelse return error.SkipZigTest;
const gpa = std.testing.allocator;
var checked: usize = 0;
for ([_][]const u8{ "experts", "dense" }) |sub| {
Expand Down
3 changes: 3 additions & 0 deletions zig/src/core/learned_part_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test "orphan temporary pressure cannot evict an older valid learned state" {
}

test "owned-name links and directories stay untouched and foreign directories are not traversed" {
if (@import("builtin").os.tag == .windows) return error.SkipZigTest; // symlinks need privilege on Windows
const a = std.testing.allocator;
var buf: [128]u8 = undefined;
const root = try scratch(&buf, "types");
Expand Down Expand Up @@ -123,6 +124,7 @@ test "owned-name links and directories stay untouched and foreign directories ar
}

test "an identity-directory symlink refuses open and preserves foreign payloads" {
if (@import("builtin").os.tag == .windows) return error.SkipZigTest; // symlinks need privilege on Windows
const a = std.testing.allocator;
var buf: [128]u8 = undefined;
const root = try scratch(&buf, "identity-link");
Expand All @@ -145,6 +147,7 @@ test "an identity-directory symlink refuses open and preserves foreign payloads"
}

test "an explicitly configured root alias still cleans only its real identity children" {
if (@import("builtin").os.tag == .windows) return error.SkipZigTest; // symlinks need privilege on Windows
const a = std.testing.allocator;
var buf: [128]u8 = undefined;
const root = try scratch(&buf, "root-target");
Expand Down
5 changes: 5 additions & 0 deletions zig/src/platform/sys.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub const posix = if (windows) @import("win_posix.zig") else std.posix;

pub const DynLib = if (windows) WinDynLib else std.DynLib;

/// An environment variable's value, through libc (std.process.Environ.getPosix does not build on Windows).
pub fn getenv(name: [*:0]const u8) ?[:0]const u8 {
return std.mem.span(c.getenv(name) orelse return null);
}

/// The CUDA driver's file name: nvcuda.dll comes with the display driver on Windows.
pub const cuda_driver = if (windows) "nvcuda.dll" else "libcuda.so.1";

Expand Down
41 changes: 40 additions & 1 deletion zig/src/platform/win_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ extern "kernel32" fn Sleep(ms: u32) callconv(.winapi) void;
extern "kernel32" fn GetDiskFreeSpaceExW(dir: [*:0]const u16, avail: ?*u64, total: ?*u64, free: ?*u64) callconv(.winapi) BOOL;
extern "kernel32" fn GetTempPathW(len: u32, buf: [*]u16) callconv(.winapi) u32;
extern "kernel32" fn GetModuleFileNameW(module: ?HANDLE, buf: [*]u16, len: u32) callconv(.winapi) u32;
extern "kernel32" fn CreateHardLinkW(new: [*:0]const u16, existing: [*:0]const u16, security: ?*anyopaque) callconv(.winapi) BOOL;
extern "kernel32" fn CreateSymbolicLinkW(link: [*:0]const u16, target: [*:0]const u16, flags: u32) callconv(.winapi) u8;
extern "kernel32" fn CloseHandle(h: HANDLE) callconv(.winapi) BOOL;

extern "c" fn _errno() *c_int;
Expand All @@ -129,7 +131,16 @@ extern "c" fn _getpid() c_int;
extern "c" fn _isatty(fd: c_int) c_int;
extern "c" fn _fstat64(fd: c_int, st: *Stat64) c_int;
extern "c" fn _putenv_s(name: [*:0]const u8, value: [*:0]const u8) c_int;
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
const ucrt = struct {
extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
};

/// libc's getenv, except that HOME, which Windows does not set, falls back to USERPROFILE.
pub fn getenv(name: [*:0]const u8) ?[*:0]u8 {
if (ucrt.getenv(name)) |v| return v;
if (std.mem.eql(u8, std.mem.span(name), "HOME")) return ucrt.getenv("USERPROFILE");
return null;
}
pub extern "c" fn fopen(path: [*:0]const u8, mode: [*:0]const u8) ?*std.c.FILE;
pub extern "c" fn fwrite(ptr: [*]const u8, size: usize, n: usize, f: *std.c.FILE) usize;
pub extern "c" fn fclose(f: *std.c.FILE) c_int;
Expand Down Expand Up @@ -422,6 +433,16 @@ pub fn rename(from: [*:0]const u8, to: [*:0]const u8) c_int {
return 0;
}

/// POSIX link: `new` names the same file as `old` (same volume).
pub fn link(old: [*:0]const u8, new: [*:0]const u8) c_int {
var a: Wide = undefined;
var b: Wide = undefined;
const wa = wide(&a, std.mem.span(old)) orelse return -1;
const wb = wide(&b, std.mem.span(new)) orelse return -1;
if (CreateHardLinkW(wb, wa, null) == 0) return fail(lastError());
return 0;
}

pub fn access(path: [*:0]const u8, mode: c_int) c_int {
var buf: Wide = undefined;
return _waccess(wide(&buf, std.mem.span(path)) orelse return -1, mode & 6);
Expand Down Expand Up @@ -575,3 +596,21 @@ pub fn fchmodat(dir: fd_t, path: [*:0]const u8, mode: mode_t, flags: u32) c_int
_ = .{ dir, path, mode, flags };
return 0;
}

/// Symbolic links need Developer Mode or elevation on Windows; this asks for an unprivileged one.
pub fn symlink(target: [*:0]const u8, path: [*:0]const u8) c_int {
var a: Wide = undefined;
var b: Wide = undefined;
const wt = wide(&a, std.mem.span(target)) orelse return -1;
const wp = wide(&b, std.mem.span(path)) orelse return -1;
const attrs = GetFileAttributesW(wt);
const dir: u32 = if (attrs != 0xFFFF_FFFF and attrs & 0x10 != 0) 0x1 else 0;
if (CreateSymbolicLinkW(wp, wt, dir | 0x2) == 0) return fail(lastError()); // ALLOW_UNPRIVILEGED_CREATE
return 0;
}

/// Reading a link's target needs its reparse data; nothing on Windows asks for it yet.
pub fn readlink(path: [*:0]const u8, buf: [*]u8, len: usize) isize {
_ = .{ path, buf, len };
return fail(.NOSYS);
}
2 changes: 1 addition & 1 deletion zig/src/server/hub.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn isDir(io: std.Io, path: []const u8) bool {

/// The checkpoint directory for ``model``, or null with ``problem`` set (no downloads: the cache must hold it).
pub fn resolve(a: Allocator, io: std.Io, environ: ?*const std.process.Environ.Map, model: []const u8, problem: *[]const u8) !?[]const u8 {
const home = if (environ) |e| e.get("HOME") orelse "" else "";
const home = if (environ) |e| e.get("HOME") orelse e.get("USERPROFILE") orelse "" else ""; // Windows sets USERPROFILE
const expanded = if (std.mem.startsWith(u8, model, "~/")) try std.fs.path.join(a, &.{ home, model[2..] }) else model;
if (isDir(io, expanded)) return expanded;
if (!isRepoId(model)) {
Expand Down