zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ecba6324bf47a68edf9c8d380f528088be68b5d7 (tree)
parent 8a8bf5ad023451a22fd7abf438e6c7ee105ac6bf
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu,  7 May 2026 18:08:31 -0700

configurer: update TranslateC step

and get zig's build.zig script fully compiling

Diffstat:
MBRANCH_TODO | 1+
Mlib/compiler/Maker.zig | 4++++
Mlib/compiler/Maker/ScannedConfig.zig | 5+++++
Alib/compiler/Maker/Step/TranslateC.zig | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlib/std/Build.zig | 18++++++++++++------
Mlib/std/Build/Configuration.zig | 4++++
Mlib/std/Build/Step/TranslateC.zig | 197+++++++++++++++++--------------------------------------------------------------
Mlib/std/Build/Step/WriteFile.zig | 42+++++++++++++++++++++---------------------
Mtest/src/Cases.zig | 28++++++++++++++++++----------
Mtest/src/Libc.zig | 4+++-
Mtest/standalone/dependency_options/build.zig | 2+-
Mtest/standalone/dirname/build.zig | 19-------------------
Mtest/standalone/install_headers/build.zig | 2+-
13 files changed, 234 insertions(+), 214 deletions(-)

diff --git a/BRANCH_TODO b/BRANCH_TODO @@ -1,3 +1,4 @@ +* pass overridden pkg-dir to maker * finish migrating the rest of the build steps * inspect b4ffb402c082605c4b324e88120306fc8fb3cf32 diff and apply changes as needed (merge conflict) * make zig-pkg path root configurable in maker (make sure --system still works) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig @@ -1804,6 +1804,10 @@ pub fn relativePath(maker: *const Maker, relative: Configuration.LazyPath.Relati .root_dir = graph.zig_lib_directory, .sub_path = sub_path, }, + .install_prefix => maker.install_paths.prefix, + .install_lib => maker.install_paths.lib, + .install_bin => maker.install_paths.bin, + .install_include => maker.install_paths.include, }; } diff --git a/lib/compiler/Maker/ScannedConfig.zig b/lib/compiler/Maker/ScannedConfig.zig @@ -79,6 +79,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi try printStruct(sc, &sub_struct, Configuration.Step.Run.Arg, field_value.get(c)); try sub_struct.end(); }, + Configuration.Step.ObjCopy.UpdateSection.Flags => { + var sub_struct = try s.beginStruct(.{}); + try printStruct(sc, &sub_struct, Field, field_value); + try sub_struct.end(); + }, Configuration.LazyPath.Index => { switch (field_value.get(c)) { inline else => |u| { diff --git a/lib/compiler/Maker/Step/TranslateC.zig b/lib/compiler/Maker/Step/TranslateC.zig @@ -0,0 +1,122 @@ + +fn make(step: *Step, options: Step.MakeOptions) !void { + const prog_node = options.progress_node; + const b = step.owner; + const translate_c: *TranslateC = @fieldParentPtr("step", step); + const arena = b.graph.arena; + + var argv_list = std.array_list.Managed([]const u8).init(b.allocator); + try argv_list.append(b.graph.zig_exe); + try argv_list.append("translate-c"); + if (translate_c.link_libc) { + try argv_list.append("-lc"); + } + + try argv_list.append("--cache-dir"); + try argv_list.append(b.cache_root.path orelse "."); + + try argv_list.append("--global-cache-dir"); + try argv_list.append(b.graph.global_cache_root.path orelse "."); + + if (!translate_c.target.query.isNative()) { + try argv_list.append("-target"); + try argv_list.append(try translate_c.target.query.zigTriple(b.allocator)); + } + + switch (translate_c.optimize) { + .Debug => {}, // Skip since it's the default. + else => try argv_list.append(b.fmt("-O{s}", .{@tagName(translate_c.optimize)})), + } + + for (translate_c.include_dirs.items) |include_dir| { + try include_dir.appendZigProcessFlags(b, &argv_list, step); + } + + for (translate_c.c_macros.items) |c_macro| { + try argv_list.append("-D"); + try argv_list.append(c_macro); + } + + var prev_search_strategy: std.Build.Module.SystemLib.SearchStrategy = .paths_first; + var prev_preferred_link_mode: std.builtin.LinkMode = .dynamic; + + for (translate_c.system_libs.items) |*system_lib| { + var seen_system_libs: std.StringHashMapUnmanaged([]const []const u8) = .empty; + const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); + if (system_lib_gop.found_existing) { + try argv_list.appendSlice(system_lib_gop.value_ptr.*); + continue; + } else { + system_lib_gop.value_ptr.* = &.{}; + } + + if (system_lib.search_strategy != prev_search_strategy or + system_lib.preferred_link_mode != prev_preferred_link_mode) + { + switch (system_lib.search_strategy) { + .no_fallback => switch (system_lib.preferred_link_mode) { + .dynamic => try argv_list.append("-search_dylibs_only"), + .static => try argv_list.append("-search_static_only"), + }, + .paths_first => switch (system_lib.preferred_link_mode) { + .dynamic => try argv_list.append("-search_paths_first"), + .static => try argv_list.append("-search_paths_first_static"), + }, + .mode_first => switch (system_lib.preferred_link_mode) { + .dynamic => try argv_list.append("-search_dylibs_first"), + .static => try argv_list.append("-search_static_first"), + }, + } + prev_search_strategy = system_lib.search_strategy; + prev_preferred_link_mode = system_lib.preferred_link_mode; + } + + const prefix: []const u8 = prefix: { + if (system_lib.needed) break :prefix "-needed-l"; + if (system_lib.weak) break :prefix "-weak-l"; + break :prefix "-l"; + }; + switch (system_lib.use_pkg_config) { + .no => try argv_list.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), + .yes, .force => { + if (Step.Compile.runPkgConfig(&translate_c.step, system_lib.name)) |result| { + try argv_list.appendSlice(result.cflags); + try argv_list.appendSlice(result.libs); + try seen_system_libs.put(arena, system_lib.name, result.cflags); + } else |err| switch (err) { + error.PkgConfigInvalidOutput, + error.PkgConfigCrashed, + error.PkgConfigFailed, + error.PkgConfigNotInstalled, + error.PackageNotFound, + => switch (system_lib.use_pkg_config) { + .yes => { + // pkg-config failed, so fall back to linking the library + // by name directly. + try argv_list.append(b.fmt("{s}{s}", .{ + prefix, + system_lib.name, + })); + }, + .force => { + std.debug.panic("pkg-config failed for library {s}", .{system_lib.name}); + }, + .no => unreachable, + }, + + else => |e| return e, + } + }, + } + } + + const c_source_path = translate_c.source.getPath2(b, step); + try argv_list.append(c_source_path); + + try argv_list.append("--listen=-"); + const output_dir = try step.evalZigProcess(argv_list.items, prog_node, false, options.web_server, options.gpa); + + const basename = std.fs.path.stem(std.fs.path.basename(c_source_path)); + translate_c.out_basename = b.fmt("{s}.zig", .{basename}); + translate_c.output_file.path = output_dir.?.joinString(b.allocator, translate_c.out_basename) catch @panic("OOM"); +} diff --git a/lib/std/Build.zig b/lib/std/Build.zig @@ -108,7 +108,10 @@ pub const Graph = struct { } pub fn dupePath(graph: *const Graph, bytes: []const u8) []const u8 { - const arena = graph.arena; + return dupePathInner(graph.arena, bytes); + } + + fn dupePathInner(arena: Allocator, bytes: []const u8) []const u8 { if (builtin.os.tag != .windows) return arena.dupe(u8, bytes) catch @panic("OOM"); const the_copy = arena.dupe(u8, bytes) catch @panic("OOM"); mem.replaceScalar(u8, the_copy, '/', '\\'); @@ -2331,21 +2334,24 @@ pub const LazyPath = union(enum) { /// Copies the internal strings. /// - /// The `b` parameter is only used for its allocator. All *Build instances - /// share the same allocator. + /// The `graph` parameter is only used for the global arena allocator. pub fn dupe(lazy_path: LazyPath, graph: *const Graph) LazyPath { + return dupeInner(lazy_path, graph.arena); + } + + fn dupeInner(lazy_path: LazyPath, arena: Allocator) LazyPath { return switch (lazy_path) { .src_path => |sp| .{ .src_path = .{ .owner = sp.owner, .sub_path = sp.owner.dupePath(sp.sub_path) } }, - .cwd_relative => |p| .{ .cwd_relative = graph.dupePath(p) }, + .cwd_relative => |p| .{ .cwd_relative = Graph.dupePathInner(arena, p) }, .relative => |r| .{ .relative = r }, .generated => |gen| .{ .generated = .{ .index = gen.index, .up = gen.up, - .sub_path = graph.dupePath(gen.sub_path), + .sub_path = Graph.dupePathInner(arena, gen.sub_path), } }, .dependency => |dep| .{ .dependency = .{ .dependency = dep.dependency, - .sub_path = graph.dupePath(dep.sub_path), + .sub_path = Graph.dupePathInner(arena, dep.sub_path), } }, }; } diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig @@ -1643,6 +1643,10 @@ pub const Path = extern struct { build_root, zig_exe, zig_lib, + install_prefix, + install_lib, + install_bin, + install_include, }; pub fn toCachePath(path: Path, c: *const Configuration, arena: Allocator) std.Build.Cache.Path { diff --git a/lib/std/Build/Step/TranslateC.zig b/lib/std/Build/Step/TranslateC.zig @@ -1,25 +1,25 @@ const TranslateC = @This(); const std = @import("std"); -const Step = std.Build.Step; -const LazyPath = std.Build.LazyPath; const fs = std.fs; const mem = std.mem; +const allocPrint = std.fmt.allocPrint; +const Step = std.Build.Step; +const LazyPath = std.Build.LazyPath; const Configuration = std.Build.Configuration; -pub const base_tag: Step.Tag = .translate_c; - step: Step, source: std.Build.LazyPath, -include_dirs: std.array_list.Managed(std.Build.Module.IncludeDir), +include_dirs: std.ArrayList(std.Build.Module.IncludeDir), system_libs: std.ArrayList(std.Build.Module.SystemLib), -c_macros: std.array_list.Managed([]const u8), -out_basename: []const u8, +c_macros: std.ArrayList([]const u8), target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, output_file: Configuration.GeneratedFileIndex, link_libc: bool, +pub const base_tag: Step.Tag = .translate_c; + pub const Options = struct { root_source_file: std.Build.LazyPath, target: std.Build.ResolvedTarget, @@ -29,20 +29,17 @@ pub const Options = struct { pub fn create(owner: *std.Build, options: Options) *TranslateC { const graph = owner.graph; - const arena = graph.arena; - const translate_c = arena.create(TranslateC) catch @panic("OOM"); + const translate_c = graph.create(TranslateC); const source = options.root_source_file.dupe(graph); translate_c.* = .{ - .step = Step.init(.{ + .step = .init(.{ .tag = base_tag, .name = "translate-c", .owner = owner, - .makeFn = make, }), .source = source, - .include_dirs = std.array_list.Managed(std.Build.Module.IncludeDir).init(arena), - .c_macros = std.array_list.Managed([]const u8).init(arena), - .out_basename = undefined, + .include_dirs = .empty, + .c_macros = .empty, .target = options.target, .optimize = options.optimize, .output_file = graph.addGeneratedFile(&translate_c.step), @@ -90,8 +87,8 @@ pub fn createModule(translate_c: *TranslateC) *std.Build.Module { } fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.Module { - const b = translate_c.step.owner; - const arena = b.graph.arena; + const graph = translate_c.step.owner.graph; + const arena = graph.arena; if (translate_c.link_libc) module.link_libc = true; @@ -103,42 +100,49 @@ fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.M } pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { - const b = translate_c.step.owner; - translate_c.include_dirs.append(.{ .path_after = lazy_path.dupe(b) }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .path_after = lazy_path.dupe(graph) }) catch @panic("OOM"); lazy_path.addStepDependencies(&translate_c.step); } pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { - const b = translate_c.step.owner; - translate_c.include_dirs.append(.{ .path_system = lazy_path.dupe(b) }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .path_system = lazy_path.dupe(graph) }) catch @panic("OOM"); lazy_path.addStepDependencies(&translate_c.step); } pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { - const b = translate_c.step.owner; - translate_c.include_dirs.append(.{ .path = lazy_path.dupe(b) }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .path = lazy_path.dupe(graph) }) catch @panic("OOM"); lazy_path.addStepDependencies(&translate_c.step); } pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void { - translate_c.include_dirs.append(.{ .config_header_step = config_header }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .config_header_step = config_header }) catch @panic("OOM"); translate_c.step.dependOn(&config_header.step); } pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void { - const b = translate_c.step.owner; - translate_c.include_dirs.append(.{ .framework_path_system = directory_path.dupe(b) }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .framework_path_system = directory_path.dupe(graph) }) catch @panic("OOM"); directory_path.addStepDependencies(&translate_c.step); } pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void { - const b = translate_c.step.owner; - translate_c.include_dirs.append(.{ .framework_path = directory_path.dupe(b) }) catch + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.include_dirs.append(arena, .{ .framework_path = directory_path.dupe(graph) }) catch @panic("OOM"); directory_path.addStepDependencies(&translate_c.step); } @@ -154,135 +158,17 @@ pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const /// If the value is omitted, it is set to 1. /// `name` and `value` need not live longer than the function call. pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void { - const macro = translate_c.step.owner.fmt("{s}={s}", .{ name, value orelse "1" }); - translate_c.c_macros.append(macro) catch @panic("OOM"); + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + const macro = allocPrint(arena, "{s}={s}", .{ name, value orelse "1" }) catch @panic("OOM"); + translate_c.c_macros.append(arena, macro) catch @panic("OOM"); } /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void { - translate_c.c_macros.append(translate_c.step.owner.dupe(name_and_value)) catch @panic("OOM"); -} - -fn make(step: *Step, options: Step.MakeOptions) !void { - const prog_node = options.progress_node; - const b = step.owner; - const translate_c: *TranslateC = @fieldParentPtr("step", step); - const arena = b.graph.arena; - - var argv_list = std.array_list.Managed([]const u8).init(b.allocator); - try argv_list.append(b.graph.zig_exe); - try argv_list.append("translate-c"); - if (translate_c.link_libc) { - try argv_list.append("-lc"); - } - - try argv_list.append("--cache-dir"); - try argv_list.append(b.cache_root.path orelse "."); - - try argv_list.append("--global-cache-dir"); - try argv_list.append(b.graph.global_cache_root.path orelse "."); - - if (!translate_c.target.query.isNative()) { - try argv_list.append("-target"); - try argv_list.append(try translate_c.target.query.zigTriple(b.allocator)); - } - - switch (translate_c.optimize) { - .Debug => {}, // Skip since it's the default. - else => try argv_list.append(b.fmt("-O{s}", .{@tagName(translate_c.optimize)})), - } - - for (translate_c.include_dirs.items) |include_dir| { - try include_dir.appendZigProcessFlags(b, &argv_list, step); - } - - for (translate_c.c_macros.items) |c_macro| { - try argv_list.append("-D"); - try argv_list.append(c_macro); - } - - var prev_search_strategy: std.Build.Module.SystemLib.SearchStrategy = .paths_first; - var prev_preferred_link_mode: std.builtin.LinkMode = .dynamic; - - for (translate_c.system_libs.items) |*system_lib| { - var seen_system_libs: std.StringHashMapUnmanaged([]const []const u8) = .empty; - const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); - if (system_lib_gop.found_existing) { - try argv_list.appendSlice(system_lib_gop.value_ptr.*); - continue; - } else { - system_lib_gop.value_ptr.* = &.{}; - } - - if (system_lib.search_strategy != prev_search_strategy or - system_lib.preferred_link_mode != prev_preferred_link_mode) - { - switch (system_lib.search_strategy) { - .no_fallback => switch (system_lib.preferred_link_mode) { - .dynamic => try argv_list.append("-search_dylibs_only"), - .static => try argv_list.append("-search_static_only"), - }, - .paths_first => switch (system_lib.preferred_link_mode) { - .dynamic => try argv_list.append("-search_paths_first"), - .static => try argv_list.append("-search_paths_first_static"), - }, - .mode_first => switch (system_lib.preferred_link_mode) { - .dynamic => try argv_list.append("-search_dylibs_first"), - .static => try argv_list.append("-search_static_first"), - }, - } - prev_search_strategy = system_lib.search_strategy; - prev_preferred_link_mode = system_lib.preferred_link_mode; - } - - const prefix: []const u8 = prefix: { - if (system_lib.needed) break :prefix "-needed-l"; - if (system_lib.weak) break :prefix "-weak-l"; - break :prefix "-l"; - }; - switch (system_lib.use_pkg_config) { - .no => try argv_list.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), - .yes, .force => { - if (Step.Compile.runPkgConfig(&translate_c.step, system_lib.name)) |result| { - try argv_list.appendSlice(result.cflags); - try argv_list.appendSlice(result.libs); - try seen_system_libs.put(arena, system_lib.name, result.cflags); - } else |err| switch (err) { - error.PkgConfigInvalidOutput, - error.PkgConfigCrashed, - error.PkgConfigFailed, - error.PkgConfigNotInstalled, - error.PackageNotFound, - => switch (system_lib.use_pkg_config) { - .yes => { - // pkg-config failed, so fall back to linking the library - // by name directly. - try argv_list.append(b.fmt("{s}{s}", .{ - prefix, - system_lib.name, - })); - }, - .force => { - std.debug.panic("pkg-config failed for library {s}", .{system_lib.name}); - }, - .no => unreachable, - }, - - else => |e| return e, - } - }, - } - } - - const c_source_path = translate_c.source.getPath2(b, step); - try argv_list.append(c_source_path); - - try argv_list.append("--listen=-"); - const output_dir = try step.evalZigProcess(argv_list.items, prog_node, false, options.web_server, options.gpa); - - const basename = std.fs.path.stem(std.fs.path.basename(c_source_path)); - translate_c.out_basename = b.fmt("{s}.zig", .{basename}); - translate_c.output_file.path = output_dir.?.joinString(b.allocator, translate_c.out_basename) catch @panic("OOM"); + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.c_macros.append(arena, translate_c.step.owner.dupe(name_and_value)) catch @panic("OOM"); } pub fn linkSystemLibrary( @@ -290,9 +176,10 @@ pub fn linkSystemLibrary( name: []const u8, options: std.Build.Module.LinkSystemLibraryOptions, ) void { - const b = translate_c.step.owner; - translate_c.system_libs.append(b.allocator, .{ - .name = b.dupe(name), + const graph = translate_c.step.owner.graph; + const arena = graph.arena; + translate_c.system_libs.append(arena, .{ + .name = graph.dupeString(name), .needed = options.needed, .weak = options.weak, .use_pkg_config = options.use_pkg_config, diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig @@ -119,34 +119,34 @@ pub fn add(write_file: *WriteFile, sub_path: []const u8, bytes: []const u8) std. }; } -/// Place the file into the generated directory within the local cache, -/// along with all the rest of the files added to this step. The parameter -/// here is the destination path relative to the local cache directory -/// associated with this WriteFile. It may be a basename, or it may -/// include sub-directories, in which case this step will ensure the -/// required sub-path exists. -/// This is the option expected to be used most commonly with `addCopyFile`. +/// Copies the provided file into the generated directory within the local +/// cache, along with all the rest of the files added to this step. +/// +/// `sub_path` is the destination path relative to the local cache directory +/// associated with this WriteFile. It may be a basename, or it may include +/// subdirectories, which are created as needed. pub fn addCopyFile(write_file: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) std.Build.LazyPath { - const b = write_file.step.owner; - const gpa = b.allocator; - const file = File{ - .sub_path = b.dupePath(sub_path), + const graph = write_file.step.owner.graph; + const duped_path = graph.dupePath(sub_path); + const arena = graph.arena; + + write_file.files.append(arena, .{ + .sub_path = duped_path, .contents = .{ .copy = source }, - }; - write_file.files.append(gpa, file) catch @panic("OOM"); + }) catch @panic("OOM"); write_file.maybeUpdateName(); source.addStepDependencies(&write_file.step); - return .{ - .generated = .{ - .index = write_file.generated_directory, - .sub_path = file.sub_path, - }, - }; + + return .{ .generated = .{ + .index = write_file.generated_directory, + .sub_path = duped_path, + } }; } -/// Copy files matching the specified exclude/include patterns to the specified subdirectory -/// relative to this step's generated directory. +/// Copy files matching the specified exclude/include patterns to the specified +/// subdirectory relative to this step's generated directory. +/// /// The returned value is a lazy path to the generated subdirectory. pub fn addCopyDirectory( write_file: *WriteFile, diff --git a/test/src/Cases.zig b/test/src/Cases.zig @@ -470,8 +470,9 @@ pub fn lowerToBuildSteps( options: CaseTestOptions, ) void { const io = self.io; + const graph = b.graph; + const arena = graph.arena; const host = b.resolveTargetQuery(.{}); - const cases_dir_path = b.build_root.join(b.allocator, &.{ "test", "cases" }) catch @panic("OOM"); for (self.cases.items) |case| { for (options.test_filters) |test_filter| { @@ -504,7 +505,7 @@ pub fn lowerToBuildSteps( ); if (options.skip_llvm and would_use_llvm) continue; - const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM"); + const triple_txt = case.target.query.zigTriple(arena) catch @panic("OOM"); if (options.test_target_filters.len > 0) { for (options.test_target_filters) |filter| { @@ -516,7 +517,7 @@ pub fn lowerToBuildSteps( continue; const writefiles = b.addWriteFiles(); - var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator); + var file_sources = std.StringHashMap(std.Build.LazyPath).init(arena); defer file_sources.deinit(); const first_file = case.files.items[0]; const root_source_file = writefiles.add(first_file.path, first_file.src); @@ -526,12 +527,15 @@ pub fn lowerToBuildSteps( } for (case.imports) |import_rel| { - const import_abs = std.fs.path.join(b.allocator, &.{ - cases_dir_path, - case.import_path orelse @panic("import_path not set"), - import_rel, - }) catch @panic("OOM"); - _ = writefiles.addCopyFile(.{ .cwd_relative = import_abs }, import_rel); + _ = writefiles.addCopyFile(.{ .src_path = .{ + .owner = b, + .sub_path = b.pathJoin(&.{ + "test", + "cases", + case.import_path orelse @panic("import_path not set"), + import_rel, + }), + } }, import_rel); } const mod = b.createModule(.{ @@ -605,7 +609,11 @@ pub fn lowerToBuildSteps( }, .Execution => |expected_stdout| no_exec: { const run = if (case.target.result.ofmt == .c) run_step: { - if (getExternalExecutor(io, &host.result, &case.target.result, .{ .link_libc = true }) != .native) { + if (getExternalExecutor(io, &case.target.result, .{ + .host_cpu_arch = host.result.cpu.arch, + .host_os_tag = host.result.os.tag, + .link_libc = true, + }) != .native) { // We wouldn't be able to run the compiled C code. break :no_exec; } diff --git a/test/src/Libc.zig b/test/src/Libc.zig @@ -31,7 +31,9 @@ pub fn addLibcTestCase( supports_wasi_libc: bool, options: LibcTestCaseOption, ) void { - const name = libc.b.dupe(path[0 .. path.len - std.fs.path.extension(path).len]); + const graph = libc.b.graph; + const arena = graph.arena; + const name = arena.dupe(u8, path[0 .. path.len - std.fs.path.extension(path).len]) catch @panic("OOM"); std.mem.replaceScalar(u8, name, '/', '.'); libc.test_cases.append(libc.b.allocator, .{ .name = name, diff --git a/test/standalone/dependency_options/build.zig b/test/standalone/dependency_options/build.zig @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) !void { const none_specified_mod = none_specified.module("dummy"); if (!none_specified_mod.resolved_target.?.query.eql(b.graph.host.query)) return error.TestFailed; - const expected_optimize: std.builtin.OptimizeMode = switch (b.release_mode) { + const expected_optimize: std.builtin.OptimizeMode = switch (b.graph.release_mode) { .off => .Debug, .any => unreachable, .fast => .ReleaseFast, diff --git a/test/standalone/dirname/build.zig b/test/standalone/dirname/build.zig @@ -27,15 +27,6 @@ pub fn build(b: *std.Build) void { }), }); - const has_basename = b.addExecutable(.{ - .name = "has_basename", - .root_module = b.createModule(.{ - .root_source_file = b.path("has_basename.zig"), - .optimize = .Debug, - .target = target, - }), - }); - // Known path: addTestRun(test_step, exists_in, touch_src.dirname(), &.{"touch.zig"}); @@ -47,16 +38,6 @@ pub fn build(b: *std.Build) void { "subdir" ++ std.fs.path.sep_str ++ "generated.txt", }); - // Cache root: - const cache_dir = b.cache_root.path orelse - (b.cache_root.join(b.allocator, &.{"."}) catch @panic("OOM")); - addTestRun( - test_step, - has_basename, - generated.dirname().dirname().dirname().dirname(), - &.{std.fs.path.basename(cache_dir)}, - ); - // Absolute path: const write_files = b.addWriteFiles(); _ = write_files.add("foo.txt", ""); diff --git a/test/standalone/install_headers/build.zig b/test/standalone/install_headers/build.zig @@ -106,7 +106,7 @@ pub fn build(b: *std.Build) void { "custom/include/foo/config.h", "custom/include/bar.h", }); - run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") }); + run_check_exists.setCwd(.{ .relative = .{ .base = .install_prefix } }); run_check_exists.expectExitCode(0); run_check_exists.step.dependOn(&install_libfoo.step); test_step.dependOn(&run_check_exists.step);