authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-02 01:10:34-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-02 01:10:34-04:00
logfed8d9054ca2cf8aca9c3583177ffd0263fc76ac
treef1bd00cca3c4ad175132dca756711acea6ae957d
parent8ef24461a0016062e0ca20d1a152dd82fac511ab
parent8db1490b8a36155d85a2d5741f97984ff583cfde
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19267 from PanSashko/compile-dup-mod

Fix adding module arguments for Step.Compile

6 files changed, 69 insertions(+), 3 deletions(-)

lib/std/Build/Step/Compile.zig+13-3
...@@ -989,10 +989,10 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking...@@ -989,10 +989,10 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
989 return path;989 return path;
990}990}
991991
992fn make(step: *Step, prog_node: std.Progress.Node) !void {992fn getZigArgs(compile: *Compile) ![][]const u8 {
993 const step = &compile.step;
993 const b = step.owner;994 const b = step.owner;
994 const arena = b.allocator;995 const arena = b.allocator;
995 const compile: *Compile = @fieldParentPtr("step", step);
996996
997 var zig_args = ArrayList([]const u8).init(arena);997 var zig_args = ArrayList([]const u8).init(arena);
998 defer zig_args.deinit();998 defer zig_args.deinit();
...@@ -1298,6 +1298,7 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {...@@ -1298,6 +1298,7 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
1298 // We need to emit the --mod argument here so that the above link objects1298 // We need to emit the --mod argument here so that the above link objects
1299 // have the correct parent module, but only if the module is part of1299 // have the correct parent module, but only if the module is part of
1300 // this compilation.1300 // this compilation.
1301 if (!my_responsibility) continue;
1301 if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| {1302 if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| {
1302 const module_cli_name = cli_named_modules.names.keys()[module_cli_index];1303 const module_cli_name = cli_named_modules.names.keys()[module_cli_index];
1303 try dep.module.appendZigProcessFlags(&zig_args, step);1304 try dep.module.appendZigProcessFlags(&zig_args, step);
...@@ -1724,7 +1725,16 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {...@@ -1724,7 +1725,16 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
1724 try zig_args.append(resolved_args_file);1725 try zig_args.append(resolved_args_file);
1725 }1726 }
17261727
1727 const maybe_output_bin_path = step.evalZigProcess(zig_args.items, prog_node) catch |err| switch (err) {1728 return try zig_args.toOwnedSlice();
1729}
1730
1731fn make(step: *Step, prog_node: std.Progress.Node) !void {
1732 const b = step.owner;
1733 const compile: *Compile = @fieldParentPtr("step", step);
1734
1735 const zig_args = try getZigArgs(compile);
1736
1737 const maybe_output_bin_path = step.evalZigProcess(zig_args, prog_node) catch |err| switch (err) {
1728 error.NeedCompileErrorCheck => {1738 error.NeedCompileErrorCheck => {
1729 assert(compile.expect_errors != null);1739 assert(compile.expect_errors != null);
1730 try checkCompileErrors(compile);1740 try checkCompileErrors(compile);
test/standalone/build.zig.zon+3
...@@ -86,6 +86,9 @@...@@ -86,6 +86,9 @@
86 .dirname = .{86 .dirname = .{
87 .path = "dirname",87 .path = "dirname",
88 },88 },
89 .dep_duplicate_module = .{
90 .path = "dep_duplicate_module",
91 },
89 .empty_env = .{92 .empty_env = .{
90 .path = "empty_env",93 .path = "empty_env",
91 },94 },
test/standalone/dep_duplicate_module/build.zig created+32
...@@ -0,0 +1,32 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
6
7 const mod = b.addModule("mod", .{
8 .root_source_file = b.path("mod.zig"),
9 .target = target,
10 .optimize = optimize,
11 });
12
13 const lib = b.addStaticLibrary(.{
14 .name = "lib",
15 .root_source_file = b.path("lib.zig"),
16 .target = target,
17 .optimize = optimize,
18 });
19 lib.root_module.addImport("mod", mod);
20
21 const exe = b.addExecutable(.{
22 .name = "app",
23 .root_source_file = b.path("main.zig"),
24 .target = target,
25 .optimize = optimize,
26 });
27
28 exe.root_module.addImport("mod", mod);
29 exe.root_module.linkLibrary(lib);
30
31 b.installArtifact(exe);
32}
test/standalone/dep_duplicate_module/lib.zig created+6
...@@ -0,0 +1,6 @@
1const std = @import("std");
2const mod = @import("mod");
3
4export fn work(x: u32) u32 {
5 return mod.double(x);
6}
test/standalone/dep_duplicate_module/main.zig created+8
...@@ -0,0 +1,8 @@
1const std = @import("std");
2const mod = @import("mod");
3
4extern fn work(x: u32) u32;
5
6pub fn main() !void {
7 _ = work(mod.half(25));
8}
test/standalone/dep_duplicate_module/mod.zig created+7
...@@ -0,0 +1,7 @@
1pub fn double(v: u32) u32 {
2 return v * 2;
3}
4
5pub fn half(v: u32) u32 {
6 return v / 2;
7}