diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-06-17 19:58:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-17 19:58:10 +0100 |
| commit | 850655f06b7dd8dc6e637d4980e6b7f9ac1b43d9 (patch) | |
| tree | abb99b964747f48c7233d24dc0255e8e610185e3 /lib | |
| parent | 8aab222ffbde5bfc141b23b2553b2887cf1a3ae3 (diff) | |
| parent | f3c0555975053a6d3ffd9bc239b732658aebe5d6 (diff) | |
| download | zig-850655f06b7dd8dc6e637d4980e6b7f9ac1b43d9.tar.gz zig-850655f06b7dd8dc6e637d4980e6b7f9ac1b43d9.zip | |
Merge pull request #24205 from mlugg/misc-build-stuff
`std.Build`: some miscelleanous bits
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Build/Cache/Path.zig | 4 | ||||
| -rw-r--r-- | lib/std/Build/Module.zig | 50 | ||||
| -rw-r--r-- | lib/std/Build/Step/ConfigHeader.zig | 21 |
3 files changed, 34 insertions, 41 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig index a14c6cd7a4..8822fb64be 100644 --- a/lib/std/Build/Cache/Path.zig +++ b/lib/std/Build/Cache/Path.zig @@ -30,9 +30,11 @@ pub fn join(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Pat pub fn resolvePosix(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Path { if (sub_path.len == 0) return p; + const new_sub_path = try fs.path.resolvePosix(arena, &.{ p.sub_path, sub_path }); return .{ .root_dir = p.root_dir, - .sub_path = try fs.path.resolvePosix(arena, &.{ p.sub_path, sub_path }), + // Use "" instead of "." to represent `root_dir` itself. + .sub_path = if (std.mem.eql(u8, new_sub_path, ".")) "" else new_sub_path, }; } diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 757f51f933..12b55a8c29 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -173,39 +173,25 @@ pub const IncludeDir = union(enum) { zig_args: *std.ArrayList([]const u8), asking_step: ?*Step, ) !void { - switch (include_dir) { - .path => |include_path| { - try zig_args.appendSlice(&.{ "-I", include_path.getPath2(b, asking_step) }); + const flag: []const u8, const lazy_path: LazyPath = switch (include_dir) { + // zig fmt: off + .path => |lp| .{ "-I", lp }, + .path_system => |lp| .{ "-isystem", lp }, + .path_after => |lp| .{ "-idirafter", lp }, + .framework_path => |lp| .{ "-F", lp }, + .framework_path_system => |lp| .{ "-iframework", lp }, + .config_header_step => |ch| .{ "-I", ch.getOutputDir() }, + .other_step => |comp| .{ "-I", comp.installed_headers_include_tree.?.getDirectory() }, + // zig fmt: on + .embed_path => |lazy_path| { + // Special case: this is a single arg. + const resolved = lazy_path.getPath3(b, asking_step); + const arg = b.fmt("--embed-dir={}", .{resolved}); + return zig_args.append(arg); }, - .path_system => |include_path| { - try zig_args.appendSlice(&.{ "-isystem", include_path.getPath2(b, asking_step) }); - }, - .path_after => |include_path| { - try zig_args.appendSlice(&.{ "-idirafter", include_path.getPath2(b, asking_step) }); - }, - .framework_path => |include_path| { - try zig_args.appendSlice(&.{ "-F", include_path.getPath2(b, asking_step) }); - }, - .framework_path_system => |include_path| { - try zig_args.appendSlice(&.{ "-iframework", include_path.getPath2(b, asking_step) }); - }, - .other_step => |other| { - if (other.generated_h) |header| { - try zig_args.appendSlice(&.{ "-isystem", std.fs.path.dirname(header.getPath()).? }); - } - if (other.installed_headers_include_tree) |include_tree| { - try zig_args.appendSlice(&.{ "-I", include_tree.generated_directory.getPath() }); - } - }, - .config_header_step => |config_header| { - const full_file_path = config_header.output_file.getPath(); - const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; - try zig_args.appendSlice(&.{ "-I", header_dir_path }); - }, - .embed_path => |embed_path| { - try zig_args.append(try std.mem.concat(b.allocator, u8, &.{ "--embed-dir=", embed_path.getPath2(b, asking_step) })); - }, - } + }; + const resolved_str = try lazy_path.getPath3(b, asking_step).toString(b.graph.arena); + return zig_args.appendSlice(&.{ flag, resolved_str }); } }; diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 6bfda7667b..967e1edd05 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -39,7 +39,8 @@ pub const Value = union(enum) { step: Step, values: std.StringArrayHashMap(Value), -output_file: std.Build.GeneratedFile, +/// This directory contains the generated file under the name `include_path`. +generated_dir: std.Build.GeneratedFile, style: Style, max_bytes: usize, @@ -99,7 +100,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { .max_bytes = options.max_bytes, .include_path = include_path, .include_guard_override = options.include_guard_override, - .output_file = .{ .step = &config_header.step }, + .generated_dir = .{ .step = &config_header.step }, }; return config_header; @@ -115,9 +116,15 @@ pub fn addValues(config_header: *ConfigHeader, values: anytype) void { } } -pub fn getOutput(config_header: *ConfigHeader) std.Build.LazyPath { - return .{ .generated = .{ .file = &config_header.output_file } }; +pub fn getOutputDir(ch: *ConfigHeader) std.Build.LazyPath { + return .{ .generated = .{ .file = &ch.generated_dir } }; } +pub fn getOutputFile(ch: *ConfigHeader) std.Build.LazyPath { + return ch.getOutputDir().path(ch.step.owner, ch.include_path); +} + +/// Deprecated; use `getOutputFile`. +pub const getOutput = getOutputFile; fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) !void { switch (@typeInfo(T)) { @@ -234,9 +241,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { if (try step.cacheHit(&man)) { const digest = man.final(); - config_header.output_file.path = try b.cache_root.join(arena, &.{ - "o", &digest, config_header.include_path, - }); + config_header.generated_dir.path = try b.cache_root.join(arena, &.{ "o", &digest }); return; } @@ -262,7 +267,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { }); }; - config_header.output_file.path = try b.cache_root.join(arena, &.{sub_path}); + config_header.generated_dir.path = try b.cache_root.join(arena, &.{ "o", &digest }); try man.writeManifest(); } |
