From c145c561186705a85db6fb18ab3f4733915f4a38 Mon Sep 17 00:00:00 2001 From: Khang Nguyen Duy Date: Sat, 17 Oct 2026 14:01:06 +0700 Subject: [PATCH 1/2] flatten analysis test build steps into build.zig 92d5bbf removed tests/ from build.zig.zon, but add_analysis_cases.zig is imported with @import() in build.zig, causing configure error: ``` error: adding build_root zig-pkg/zls-0.17.0-dev-rmm5fgEnHAB2MTEid91hbT8mVqvuEYQvtOXQDfX7lqN2/tests/add_analysis_cases.zig to cache failed: FileSystemFailure ``` Flatten the file into build.zig directly, since all the paths used in that file are all relative to build.zig anyway and I see little benefit in extracting it in its own file. Fixes: 92d5bbf (exclude unnecessary build steps and files when being a dependency) --- build.zig | 70 ++++++++++++++++++++++++++++++++++- tests/add_analysis_cases.zig | 72 ------------------------------------ 2 files changed, 69 insertions(+), 73 deletions(-) delete mode 100644 tests/add_analysis_cases.zig diff --git a/build.zig b/build.zig index c475a5646..da01c7e63 100644 --- a/build.zig +++ b/build.zig @@ -258,7 +258,7 @@ pub fn build(b: *Build) !void { const test_analysis_step = b.step("test-analysis", "Run all the analysis tests"); // Create run steps - @import("tests/add_analysis_cases.zig").addCases(b, target, optimize, test_analysis_step, test_filters); + addAnalysisCases(b, target, optimize, test_analysis_step, test_filters); const run_tests = b.addRunArtifact(tests); const run_src_tests = b.addRunArtifact(src_tests); @@ -742,3 +742,71 @@ const Build = blk: { } break :blk std.Build; }; + +fn addAnalysisCases( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.lang.OptimizeMode, + test_step: *std.Build.Step, + test_filters: []const []const u8, +) void { + const cases_path = "tests/analysis"; + + const check_exe = b.addExecutable(.{ + .name = "analysis_check", + .root_module = b.createModule(.{ + .root_source_file = b.path("tests/analysis_check.zig"), + .target = target, + .optimize = optimize, + .imports = &.{ + .{ .name = "zls", .module = b.modules.get("zls").? }, + }, + }), + }); + + b.dependOnDirectoryContents(b.path(cases_path)); + + var dir = b.root.openDir(b.graph.io, cases_path, .{ .iterate = true }) catch |err| + std.debug.panic("failed to open '{f}': {}", .{ b.path(cases_path), err }); + defer dir.close(b.graph.io); + + var it = dir.iterate(); + + while (true) { + const entry = it.next(b.graph.io) catch |err| + std.debug.panic("failed to walk directory '{f}': {}", .{ b.path(cases_path), err }) orelse break; + + if (entry.kind != .file) continue; + if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.name), ".zig")) continue; + + for (test_filters) |test_filter| { + if (std.mem.find(u8, entry.name, test_filter) != null) break; + } else if (test_filters.len > 0) continue; + + const run_check = std.Build.Step.Run.create(b, b.fmt("run analysis on {s}", .{entry.name})); + run_check.producer = check_exe; + + run_check.addArtifactArg(check_exe); + if (target.query.eql(b.graph.host.query)) { + run_check.addArg("--zig-exe-path"); + run_check.addFileArg(.zig_exe); + } + run_check.setPreopen("/lib", .zig_lib); + if (!target.result.cpu.arch.isWasm()) { + run_check.addArg("--zig-lib-path"); + run_check.addDirectoryArg(.zig_lib); + } + + const input_file = b.path(cases_path).path(b, entry.name); + if (!target.result.cpu.arch.isWasm()) { + run_check.addFileArg(input_file); + } else { + // pass a relative file path when running with wasmtime + run_check.setCwd(b.path(cases_path)); + run_check.addArg(entry.name); + run_check.addFileInput(input_file); + } + + test_step.dependOn(&run_check.step); + } +} diff --git a/tests/add_analysis_cases.zig b/tests/add_analysis_cases.zig deleted file mode 100644 index d1f3b9ab9..000000000 --- a/tests/add_analysis_cases.zig +++ /dev/null @@ -1,72 +0,0 @@ -//! This file is imported by `../build.zig` to add code analysis tests to the build system. -//! See the `./analysis` subdirectory. - -const std = @import("std"); - -pub fn addCases( - b: *std.Build, - target: std.Build.ResolvedTarget, - optimize: std.lang.OptimizeMode, - test_step: *std.Build.Step, - test_filters: []const []const u8, -) void { - const cases_path = "tests/analysis"; - - const check_exe = b.addExecutable(.{ - .name = "analysis_check", - .root_module = b.createModule(.{ - .root_source_file = b.path("tests/analysis_check.zig"), - .target = target, - .optimize = optimize, - .imports = &.{ - .{ .name = "zls", .module = b.modules.get("zls").? }, - }, - }), - }); - - b.dependOnDirectoryContents(b.path(cases_path)); - - var dir = b.root.openDir(b.graph.io, cases_path, .{ .iterate = true }) catch |err| - std.debug.panic("failed to open '{f}': {}", .{ b.path(cases_path), err }); - defer dir.close(b.graph.io); - - var it = dir.iterate(); - - while (true) { - const entry = it.next(b.graph.io) catch |err| - std.debug.panic("failed to walk directory '{f}': {}", .{ b.path(cases_path), err }) orelse break; - - if (entry.kind != .file) continue; - if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.name), ".zig")) continue; - - for (test_filters) |test_filter| { - if (std.mem.find(u8, entry.name, test_filter) != null) break; - } else if (test_filters.len > 0) continue; - - const run_check = std.Build.Step.Run.create(b, b.fmt("run analysis on {s}", .{entry.name})); - run_check.producer = check_exe; - - run_check.addArtifactArg(check_exe); - if (target.query.eql(b.graph.host.query)) { - run_check.addArg("--zig-exe-path"); - run_check.addFileArg(.zig_exe); - } - run_check.setPreopen("/lib", .zig_lib); - if (!target.result.cpu.arch.isWasm()) { - run_check.addArg("--zig-lib-path"); - run_check.addDirectoryArg(.zig_lib); - } - - const input_file = b.path(cases_path).path(b, entry.name); - if (!target.result.cpu.arch.isWasm()) { - run_check.addFileArg(input_file); - } else { - // pass a relative file path when running with wasmtime - run_check.setCwd(b.path(cases_path)); - run_check.addArg(entry.name); - run_check.addFileInput(input_file); - } - - test_step.dependOn(&run_check.step); - } -} From e7e576adb7e95719ac19cb05caea4e5d76c581ef Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sat, 17 Oct 2026 17:54:26 +0200 Subject: [PATCH 2/2] build: move `addAnalysisCases` function --- build.zig | 136 +++++++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/build.zig b/build.zig index da01c7e63..d07905062 100644 --- a/build.zig +++ b/build.zig @@ -634,6 +634,74 @@ fn release(b: *Build, release_artifacts: []const *Build.Step.Compile, released_z release_step.dependOn(&install_metadata.step); } +fn addAnalysisCases( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.lang.OptimizeMode, + test_step: *std.Build.Step, + test_filters: []const []const u8, +) void { + const cases_path = "tests/analysis"; + + const check_exe = b.addExecutable(.{ + .name = "analysis_check", + .root_module = b.createModule(.{ + .root_source_file = b.path("tests/analysis_check.zig"), + .target = target, + .optimize = optimize, + .imports = &.{ + .{ .name = "zls", .module = b.modules.get("zls").? }, + }, + }), + }); + + b.dependOnDirectoryContents(b.path(cases_path)); + + var dir = b.root.openDir(b.graph.io, cases_path, .{ .iterate = true }) catch |err| + std.debug.panic("failed to open '{f}': {}", .{ b.path(cases_path), err }); + defer dir.close(b.graph.io); + + var it = dir.iterate(); + + while (true) { + const entry = it.next(b.graph.io) catch |err| + std.debug.panic("failed to walk directory '{f}': {}", .{ b.path(cases_path), err }) orelse break; + + if (entry.kind != .file) continue; + if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.name), ".zig")) continue; + + for (test_filters) |test_filter| { + if (std.mem.find(u8, entry.name, test_filter) != null) break; + } else if (test_filters.len > 0) continue; + + const run_check = std.Build.Step.Run.create(b, b.fmt("run analysis on {s}", .{entry.name})); + run_check.producer = check_exe; + + run_check.addArtifactArg(check_exe); + if (target.query.eql(b.graph.host.query)) { + run_check.addArg("--zig-exe-path"); + run_check.addFileArg(.zig_exe); + } + run_check.setPreopen("/lib", .zig_lib); + if (!target.result.cpu.arch.isWasm()) { + run_check.addArg("--zig-lib-path"); + run_check.addDirectoryArg(.zig_lib); + } + + const input_file = b.path(cases_path).path(b, entry.name); + if (!target.result.cpu.arch.isWasm()) { + run_check.addFileArg(input_file); + } else { + // pass a relative file path when running with wasmtime + run_check.setCwd(b.path(cases_path)); + run_check.addArg(entry.name); + run_check.addFileInput(input_file); + } + + test_step.dependOn(&run_check.step); + } +} + const Build = blk: { @setEvalBranchQuota(10_000); @@ -742,71 +810,3 @@ const Build = blk: { } break :blk std.Build; }; - -fn addAnalysisCases( - b: *std.Build, - target: std.Build.ResolvedTarget, - optimize: std.lang.OptimizeMode, - test_step: *std.Build.Step, - test_filters: []const []const u8, -) void { - const cases_path = "tests/analysis"; - - const check_exe = b.addExecutable(.{ - .name = "analysis_check", - .root_module = b.createModule(.{ - .root_source_file = b.path("tests/analysis_check.zig"), - .target = target, - .optimize = optimize, - .imports = &.{ - .{ .name = "zls", .module = b.modules.get("zls").? }, - }, - }), - }); - - b.dependOnDirectoryContents(b.path(cases_path)); - - var dir = b.root.openDir(b.graph.io, cases_path, .{ .iterate = true }) catch |err| - std.debug.panic("failed to open '{f}': {}", .{ b.path(cases_path), err }); - defer dir.close(b.graph.io); - - var it = dir.iterate(); - - while (true) { - const entry = it.next(b.graph.io) catch |err| - std.debug.panic("failed to walk directory '{f}': {}", .{ b.path(cases_path), err }) orelse break; - - if (entry.kind != .file) continue; - if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.name), ".zig")) continue; - - for (test_filters) |test_filter| { - if (std.mem.find(u8, entry.name, test_filter) != null) break; - } else if (test_filters.len > 0) continue; - - const run_check = std.Build.Step.Run.create(b, b.fmt("run analysis on {s}", .{entry.name})); - run_check.producer = check_exe; - - run_check.addArtifactArg(check_exe); - if (target.query.eql(b.graph.host.query)) { - run_check.addArg("--zig-exe-path"); - run_check.addFileArg(.zig_exe); - } - run_check.setPreopen("/lib", .zig_lib); - if (!target.result.cpu.arch.isWasm()) { - run_check.addArg("--zig-lib-path"); - run_check.addDirectoryArg(.zig_lib); - } - - const input_file = b.path(cases_path).path(b, entry.name); - if (!target.result.cpu.arch.isWasm()) { - run_check.addFileArg(input_file); - } else { - // pass a relative file path when running with wasmtime - run_check.setCwd(b.path(cases_path)); - run_check.addArg(entry.name); - run_check.addFileInput(input_file); - } - - test_step.dependOn(&run_check.step); - } -}