Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Build CLI
run: zig build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Build CLI
run: zig build
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Build CLI
run: cd labelle-cli && zig build
Expand Down Expand Up @@ -359,7 +359,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Install system dependencies
run: |
Expand Down Expand Up @@ -693,7 +693,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

# Native libs the generated raylib desktop game compiles against
# (same set as the versions-integration job).
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path: labelle-gui
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1
- run: zig build -Doptimize=ReleaseSafe -Dcpu=baseline -Dversion=${GITHUB_REF#refs/tags/v}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
path: labelle-gui
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1
- run: zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-linux -Dversion=${GITHUB_REF#refs/tags/v}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
path: labelle-gui
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1
- run: zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-macos -Dversion=${GITHUB_REF#refs/tags/v}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
path: labelle-gui
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1
- run: zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-macos -Dversion=${GITHUB_REF#refs/tags/v}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
path: labelle-gui
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1
- run: zig build -Doptimize=ReleaseSafe -Dcpu=baseline "-Dversion=$($env:GITHUB_REF -replace 'refs/tags/v','')"
- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
# provisioning below is exercised through that CLI, not this install.
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Build CLI
shell: bash
Expand Down
18 changes: 9 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(gen_exe);

const gen_run = b.addRunArtifact(gen_exe);
if (b.args) |args| {
gen_run.addArgs(args);
}
gen_run.addPassthruArgs();
const gen_step = b.step("generate", "Generate assembler from project.labelle");
gen_step.dependOn(&gen_run.step);

Expand Down Expand Up @@ -74,20 +72,22 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
}),
});
const child_fixture_install = b.addInstallArtifact(child_fixture, .{});
const test_fixtures = b.addOptions();
test_fixtures.addOption([]const u8, "child_exe", b.getInstallPath(.bin, child_fixture.out_filename));
// Zig 0.17: install paths are not known while build.zig runs (the
// configurer is a separate process from the maker), so the fixture is
// handed over as the compile step's emitted binary rather than its
// `zig-out/bin` copy. That also makes the test depend on it directly.
test_fixtures.addOptionPath("child_exe", child_fixture.getEmittedBin());
// The source tree, for the reserved-environment-name guard
// (`config.zig`), which checks every `LABELLE_*` name the CLI spells.
test_fixtures.addOption([]const u8, "src_dir", b.pathFromRoot("src"));
test_fixtures.addOptionPathDirectory("src_dir", b.path("src"));
cli_tests.root_module.addOptions("test_fixtures", test_fixtures);
// `docs/shader-materials.md` quotes material_toolchain.zig's diagnostics
// and its Windows extension lists verbatim. The toolchain tests embed the
// doc so the quotes are asserted against the source, not maintained by
// hand (cli#389 follow-up: two stale quotes shipped in one PR).
cli_tests.root_module.addAnonymousImport("shader_materials_doc", .{ .root_source_file = b.path("docs/shader-materials.md") });
const run_cli_tests = b.addRunArtifact(cli_tests);
run_cli_tests.step.dependOn(&child_fixture_install.step);
const test_step = b.step("test", "Run CLI unit tests");
test_step.dependOn(&run_cli_tests.step);

Expand Down Expand Up @@ -192,7 +192,7 @@ pub fn build(b: *std.Build) void {
/// the shrinking migration allowlist (RFC #406, docs/rfc-package-commands.md
/// "Enforcement"). The test walks src/, so it always runs on the HOST, from
/// the repo root. Part of `zig build test`; `zig build test-guard` runs it alone.
fn addAgnosticGuard(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
fn addAgnosticGuard(b: *std.Build, test_step: *std.Build.Step, optimize: std.lang.Optimize) void {
const guard_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/agnostic_guard_test.zig"),
Expand All @@ -215,7 +215,7 @@ fn addAgnosticGuard(b: *std.Build, test_step: *std.Build.Step, optimize: std.bui
/// third-party code lives outside `src/`, so the agnostic guard does not
/// scan upstream comments — cli#471 X2): PNG/TGA/BMP decode and
/// PNG/BMP/TGA/JPEG encode, with its headers on the include path.
/// Three consumers `@cImport` those headers: `src/cli/bake.zig` (decode,
/// Three consumers call into it through `src/stb.zig`: `src/cli/bake.zig` (decode,
/// for the PNG→LRGBA prebake), `src/texpack/` (decode + encode, for
/// `labelle pack`), and `src/cli/screenshot_format.zig` (decode + encode,
/// to re-encode a `--screenshot` capture into the requested format —
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.{
.fingerprint = 0xa3d95bf7b905a401,
.name = .labelle_cli,
.version = "4.1.3",
.minimum_zig_version = "0.16.0",
.version = "5.0.0",
.minimum_zig_version = "0.17.1",
.dependencies = .{
// Issue #217: labelle-cli is a thin driver over the standalone
// labelle-assembler binary — it no longer compiles in the
Expand All @@ -12,8 +12,8 @@
// schema (src/cli/project_config.zig) and its own self-contained
// assembler-binary bootstrap (src/cli/asm_cache.zig).
.zspec = .{
.url = "https://github.com/apotema/zspec/archive/v0.9.1.tar.gz",
.hash = "zspec-0.9.1-jaKLbbX4AwBKANdetxzzWc3UTO0UY0lcJJzTagQHlt5K",
.url = "https://github.com/apotema/zspec/archive/v0.10.0.tar.gz",
.hash = "zspec-0.10.0-jaKLbbQlBABK3_qQJn5tDMF0wbJmepYdXFQug35tOur4",
},
// `labelle pack` (#214) decodes/encodes PNG via the vendored stb
// C sources in src/cli/ (stb_image*.h + stb_image_impl.c), wired
Expand Down
7 changes: 7 additions & 0 deletions docs/provider-local-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ system integrations; providers must support this mode. Dependencies must be
prepared beforehand in the Labelle Zig package cache. Build scripts are
trusted executable package code, not sandboxed processes.

The tool is built with a global compiler cache of its own
(`<LABELLE_HOME>/zig-provider-tool-cache`), not the one game builds share:
Zig 0.17.1 panics under `--system` when a lazy dependency is absent from the
package directory while its tarball sits in the global cache, and the shared
cache holds every game's tarballs. The tool itself still runs with the shared
`ZIG_GLOBAL_CACHE_DIR`.

Zig owns caching of source, imported modules, compiler, host and options. The
runner always evaluates the named install step; it does not use a shallow
timestamp check to skip dependency validation. Unchanged compiled objects are
Expand Down
8 changes: 4 additions & 4 deletions src/agnostic_guard_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ const Scan = struct {
self.dirty[i] = true;
return; // a platform in the name keeps the entry on its own
}
const msg = try std.fmt.allocPrint(self.gpa, "src/{s}: '{s}' in path {s}", .{ path, word, finding_note });
const msg = try self.gpa.print("src/{s}: '{s}' in path {s}", .{ path, word, finding_note });
try self.offenders.append(self.gpa, msg);
}
var line_no: usize = 0;
Expand All @@ -366,17 +366,17 @@ const Scan = struct {
self.dirty[i] = true;
return; // one hit keeps the entry; no need to read on
}
const msg = try std.fmt.allocPrint(self.gpa, "src/{s}:{d}: '{s}' {s}", .{ path, line_no, word, finding_note });
const msg = try self.gpa.print("src/{s}:{d}: '{s}' {s}", .{ path, line_no, word, finding_note });
try self.offenders.append(self.gpa, msg);
}
}
}

/// A symlink the guard cannot scan: always a finding, allowlist or not.
fn linkFinding(self: *Scan, path: []const u8, comptime fmt: []const u8, args: anytype) !void {
const what = try std.fmt.allocPrint(self.gpa, fmt, args);
const what = try self.gpa.print(fmt, args);
defer self.gpa.free(what);
const msg = try std.fmt.allocPrint(self.gpa, "src/{s}: {s} {s}", .{ path, what, finding_note });
const msg = try self.gpa.print("src/{s}: {s} {s}", .{ path, what, finding_note });
try self.offenders.append(self.gpa, msg);
}

Expand Down
32 changes: 16 additions & 16 deletions src/astc/astcenc_bin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn candidateNames(os: std.Target.Os.Tag, arch: std.Target.Cpu.Arch) []const

/// `https://.../<version>/astcenc-<version>-<suffix>.zip`. Caller owns the slice.
pub fn releaseUrl(allocator: std.mem.Allocator, version: []const u8, suffix: []const u8) ![]u8 {
return std.fmt.allocPrint(allocator, "{s}/{s}/astcenc-{s}-{s}.zip", .{ release_base_override orelse RELEASE_BASE, version, version, suffix });
return allocator.print("{s}/{s}/astcenc-{s}-{s}.zip", .{ release_base_override orelse RELEASE_BASE, version, version, suffix });
}

/// `<cache_root>/astcenc/<version>` — the archive extracts its own `bin/...`
Expand All @@ -77,7 +77,7 @@ pub fn versionDir(allocator: std.mem.Allocator, cache_root: []const u8, version:
/// First candidate binary that exists under `<ver_dir>/bin/`, or null. Caller
/// owns the returned slice.
fn resolveExisting(allocator: std.mem.Allocator, ver_dir: []const u8) !?[]u8 {
for (candidateNames(builtin.os.tag, builtin.cpu.arch)) |name| {
for (candidateNames(builtin.target.os.tag, builtin.target.cpu.arch)) |name| {
const p = try std.fs.path.join(allocator, &.{ ver_dir, "bin", name });
if (util.fileExists(p)) return p;
allocator.free(p);
Expand All @@ -104,7 +104,7 @@ pub fn ensure(allocator: std.mem.Allocator, cache_root: []const u8, version: []c

if (try resolveExisting(allocator, ver_dir)) |p| return p;

const suffix = assetSuffix(builtin.os.tag, builtin.cpu.arch) catch {
const suffix = assetSuffix(builtin.target.os.tag, builtin.target.cpu.arch) catch {
std.debug.print("labelle: no prebuilt astcenc for this platform; install astcenc {s} under {s}/bin/\n", .{ version, ver_dir });
return error.AstcencUnavailable;
};
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn ensure(allocator: std.mem.Allocator, cache_root: []const u8, version: []c
// extract would fail only for those users. The absolute path always hits the
// libarchive-backed system tar. If SystemRoot is unset it tries the stock
// C:\Windows\System32\tar.exe, then bare `tar` (`unsetRootTar`).
const extracted = if (builtin.os.tag == .windows) blk: {
const extracted = if (builtin.target.os.tag == .windows) blk: {
const tar_exe = windowsTarPath(allocator) catch |err| switch (err) {
// The bare-`tar` fallback exists ONLY for an unset/invalid
// SystemRoot+windir (the same cases `envVarOwnedOptional` collapses
Expand Down Expand Up @@ -172,7 +172,7 @@ pub fn ensure(allocator: std.mem.Allocator, cache_root: []const u8, version: []c
defer allocator.free(staged_bin);
// Executable BEFORE publishing: once the version dir exists another
// labelle may run the binary straight away.
if (builtin.os.tag != .windows) {
if (builtin.target.os.tag != .windows) {
if (cwd.openFile(io, staged_bin, .{})) |f| {
defer f.close(io);
f.setPermissions(io, .fromMode(0o755)) catch {};
Expand Down Expand Up @@ -224,7 +224,7 @@ fn windowsTarPath(allocator: std.mem.Allocator) ![]u8 {
else => return err,
};
defer allocator.free(root);
return std.fmt.allocPrint(allocator, "{s}\\System32\\tar.exe", .{root});
return allocator.print("{s}\\System32\\tar.exe", .{root});
}

/// The tar to use when SystemRoot/windir are unset: the stock
Expand Down Expand Up @@ -291,22 +291,22 @@ const ConcurrentEnsure = struct {
defer a.free(fwd);
std.mem.replaceScalar(u8, fwd, '\\', '/');
return if (fwd.len > 0 and fwd[0] == '/')
std.fmt.allocPrint(a, "file://{s}", .{fwd})
a.print("file://{s}", .{fwd})
else
std.fmt.allocPrint(a, "file:///{s}", .{fwd});
a.print("file:///{s}", .{fwd});
}

/// Zip `<src>/bin` into `zip_path`: bsdtar on Windows/macOS, `zip` on
/// Linux (GNU tar cannot write zips). Null if no tool is available.
fn makeZip(a: std.mem.Allocator, src: []const u8, zip_path: []const u8) !bool {
if (builtin.os.tag == .windows) {
if (builtin.target.os.tag == .windows) {
const tar_exe = windowsTarPath(a) catch try unsetRootTar(a);
defer a.free(tar_exe);
return runOk(a, &.{ tar_exe, "-a", "-cf", zip_path, "-C", src, "bin" });
}
if (builtin.os.tag == .macos) return runOk(a, &.{ "tar", "-a", "-cf", zip_path, "-C", src, "bin" });
if (builtin.target.os.tag == .macos) return runOk(a, &.{ "tar", "-a", "-cf", zip_path, "-C", src, "bin" });
// `zip` stores paths relative to its cwd; -j would flatten, so cd via sh.
const script = try std.fmt.allocPrint(a, "cd '{s}' && zip -q -r '{s}' bin", .{ src, zip_path });
const script = try a.print("cd '{s}' && zip -q -r '{s}' bin", .{ src, zip_path });
defer a.free(script);
return runOk(a, &.{ "sh", "-c", script });
}
Expand All @@ -330,9 +330,9 @@ test "astcenc ensure: parallel installs into one labelle home all succeed with a
const io = util_io();
const cwd = std.Io.Dir.cwd();
const version = ConcurrentEnsure.version;
const suffix = assetSuffix(builtin.os.tag, builtin.cpu.arch) catch return error.SkipZigTest;
const suffix = assetSuffix(builtin.target.os.tag, builtin.target.cpu.arch) catch return error.SkipZigTest;
if (!runOk(a, &.{ "curl", "--version" })) return error.SkipZigTest;
if (builtin.os.tag == .linux and !runOk(a, &.{ "unzip", "-v" })) return error.SkipZigTest;
if (builtin.target.os.tag == .linux and !runOk(a, &.{ "unzip", "-v" })) return error.SkipZigTest;

var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
Expand All @@ -349,15 +349,15 @@ test "astcenc ensure: parallel installs into one labelle home all succeed with a
const payload = try a.alloc(u8, 2 << 20);
defer a.free(payload);
for (payload, 0..) |*b, i| b.* = @truncate(i *% 2654435761 >> 5);
for (candidateNames(builtin.os.tag, builtin.cpu.arch)) |name| {
for (candidateNames(builtin.target.os.tag, builtin.target.cpu.arch)) |name| {
const p = try std.fs.path.join(a, &.{ src_bin, name });
defer a.free(p);
try cwd.writeFile(io, .{ .sub_path = p, .data = payload });
}
const rel_ver = try std.fs.path.join(a, &.{ root, "rel", version });
defer a.free(rel_ver);
try cwd.createDirPath(io, rel_ver);
const zip_name = try std.fmt.allocPrint(a, "astcenc-{s}-{s}.zip", .{ version, suffix });
const zip_name = try a.print("astcenc-{s}-{s}.zip", .{ version, suffix });
defer a.free(zip_name);
const zip_path = try std.fs.path.join(a, &.{ rel_ver, zip_name });
defer a.free(zip_path);
Expand All @@ -381,7 +381,7 @@ test "astcenc ensure: parallel installs into one labelle home all succeed with a
// Every candidate is complete (no truncated binary from a racing extract).
const ver_dir = try versionDir(a, home, version);
defer a.free(ver_dir);
for (candidateNames(builtin.os.tag, builtin.cpu.arch)) |name| {
for (candidateNames(builtin.target.os.tag, builtin.target.cpu.arch)) |name| {
const p = try std.fs.path.join(a, &.{ ver_dir, "bin", name });
defer a.free(p);
const got = try cwd.readFileAlloc(io, p, a, .limited(8 << 20));
Expand Down
26 changes: 16 additions & 10 deletions src/astc/capabilities.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,47 @@ pub fn parse(gpa: std.mem.Allocator, bytes: []const u8, target: []const u8) !Sel
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
const a = arena.allocator();
const source = try a.dupeZ(u8, bytes);
const source = try a.dupeSentinel(u8, bytes, 0);
defer a.free(source);
var ast = try std.zig.Ast.parse(a, source, .zon);
var ast = try std.zig.Ast.parse(a, source, .{ .mode = .zon });
defer ast.deinit(a);
if (ast.errors.len != 0) return error.InvalidTextureCapabilities;
var zoir = try std.zig.ZonGen.generate(a, ast, .{ .parse_str_lits = false });
defer zoir.deinit(a);
if (zoir.hasCompileErrors()) return error.InvalidTextureCapabilities;
const root = switch (std.zig.Zoir.Node.Index.root.get(zoir)) {
const root = switch (std.zig.Zoir.Node.Index.root.get(&zoir)) {
.struct_literal => |fields| fields,
.empty_literal => return .{},
else => return error.InvalidTextureCapabilities,
};
var result: Selection = .{};
var seen = false;
for (root.names, 0..) |name, i| {
if (!std.mem.eql(u8, name.get(zoir), "texture_caps")) continue;
if (!std.mem.eql(u8, name.get(&zoir), "texture_caps")) continue;
if (seen) return error.InvalidTextureCapabilities;
seen = true;
const targets = switch (root.vals.at(@intCast(i)).get(zoir)) {
const targets = switch (root.vals.at(@intCast(i)).get(&zoir)) {
.struct_literal => |fields| fields,
.empty_literal => return result,
else => return error.InvalidTextureCapabilities,
};
for (targets.names, 0..) |key, j| {
const target_name = key.get(zoir);
const target_name = key.get(&zoir);
for (targets.names[0..j]) |previous| {
if (std.mem.eql(u8, previous.get(zoir), target_name)) return error.InvalidTextureCapabilities;
if (std.mem.eql(u8, previous.get(&zoir), target_name)) return error.InvalidTextureCapabilities;
}
const value = std.zon.parse.fromZoirNodeAlloc(Target, a, ast, zoir, targets.vals.at(@intCast(j)), null, .{}) catch |err| {
var diagnostics: std.zon.parse.Diagnostics = undefined;
const value = std.zon.parse.fromZoir(Target, .{
.arena = a,
.ast = &ast,
.zoir = &zoir,
.node = targets.vals.at(@intCast(j)),
.diagnostics = &diagnostics,
}) catch |err| {
if (err == error.OutOfMemory) return err;
return error.InvalidTextureCapabilities;
};
defer std.zon.parse.free(a, value);
var caps: convert.BackendCaps = .{ .blocks = .initEmpty(), .default_block = value.astc.default_block };
var caps: convert.BackendCaps = .{ .blocks = .empty, .default_block = value.astc.default_block };
for (value.astc.blocks) |block| {
if (caps.blocks.contains(block)) return error.InvalidTextureCapabilities;
caps.blocks.insert(block);
Expand Down
Loading
Loading