Skip to content

Commit b80a4ae

Browse files
committed
lib: implement addLibraryPathSpecial
This commit adds `addLibraryPathSpecial` for `Build.Module` and `Build.Step.Compile`. Like `addLibraryPath` but for `[]const u8`. `addRPathSpecial` is also added for `Build.Step.Compile` for completeness. This is needed to implement the new test in ziglang#19818.
1 parent 1cc388d commit b80a4ae

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

lib/compiler/build_runner.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,10 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
14961496

14971497
.config_header_step => |other| step.dependOn(&other.step),
14981498
};
1499-
for (mod.lib_paths.items) |lp| lp.addStepDependencies(step);
1499+
for (mod.lib_paths.items) |lib_path| switch (lib_path) {
1500+
.lazy_path => |lp| lp.addStepDependencies(step),
1501+
.special => {},
1502+
};
15001503
for (mod.rpaths.items) |rpath| switch (rpath) {
15011504
.lazy_path => |lp| lp.addStepDependencies(step),
15021505
.special => {},

lib/std/Build/Module.zig

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dwarf_format: ?std.dwarf.Format,
1212

1313
c_macros: std.ArrayListUnmanaged([]const u8),
1414
include_dirs: std.ArrayListUnmanaged(IncludeDir),
15-
lib_paths: std.ArrayListUnmanaged(LazyPath),
15+
lib_paths: std.ArrayListUnmanaged(LibraryPath),
1616
rpaths: std.ArrayListUnmanaged(RPath),
1717
frameworks: std.StringArrayHashMapUnmanaged(LinkFrameworkOptions),
1818
link_objects: std.ArrayListUnmanaged(LinkObject),
@@ -41,6 +41,11 @@ export_symbol_names: []const []const u8 = &.{},
4141
/// Use `getGraph` instead of accessing this field directly.
4242
cached_graph: Graph = .{ .modules = &.{}, .names = &.{} },
4343

44+
pub const LibraryPath = union(enum) {
45+
lazy_path: LazyPath,
46+
special: []const u8,
47+
};
48+
4449
pub const RPath = union(enum) {
4550
lazy_path: LazyPath,
4651
special: []const u8,
@@ -513,7 +518,12 @@ pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void {
513518

514519
pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void {
515520
const b = m.owner;
516-
m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM");
521+
m.lib_paths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM");
522+
}
523+
524+
pub fn addLibraryPathSpecial(m: *Module, bytes: []const u8) void {
525+
const b = m.owner;
526+
m.lib_paths.append(b.allocator, .{ .special = b.dupe(bytes) }) catch @panic("OOM");
517527
}
518528

519529
pub fn addRPath(m: *Module, directory_path: LazyPath) void {
@@ -611,10 +621,16 @@ pub fn appendZigProcessFlags(
611621
try zig_args.appendSlice(m.c_macros.items);
612622

613623
try zig_args.ensureUnusedCapacity(2 * m.lib_paths.items.len);
614-
for (m.lib_paths.items) |lib_path| {
615-
zig_args.appendAssumeCapacity("-L");
616-
zig_args.appendAssumeCapacity(lib_path.getPath2(b, asking_step));
617-
}
624+
for (m.lib_paths.items) |lib_path| switch (lib_path) {
625+
.lazy_path => |lp| {
626+
zig_args.appendAssumeCapacity("-L");
627+
zig_args.appendAssumeCapacity(lp.getPath2(b, asking_step));
628+
},
629+
.special => |bytes| {
630+
zig_args.appendAssumeCapacity("-L");
631+
zig_args.appendAssumeCapacity(bytes);
632+
},
633+
};
618634

619635
try zig_args.ensureUnusedCapacity(2 * m.rpaths.items.len);
620636
for (m.rpaths.items) |rpath| switch (rpath) {

lib/std/Build/Step/Compile.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,18 @@ pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
942942
compile.root_module.addLibraryPath(directory_path);
943943
}
944944

945+
pub fn addLibraryPathSpecial(compile: *Compile, bytes: []const u8) void {
946+
compile.root_module.addLibraryPathSpecial(bytes);
947+
}
948+
945949
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
946950
compile.root_module.addRPath(directory_path);
947951
}
948952

953+
pub fn addRPathSpecial(compile: *Compile, bytes: []const u8) void {
954+
compile.root_module.addRPathSpecial(bytes);
955+
}
956+
949957
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
950958
compile.root_module.addSystemFrameworkPath(directory_path);
951959
}

0 commit comments

Comments
 (0)