authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:20:06-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:27:18-04:00
logf5a911290e97435a09d46113551e07ace7367641
tree4f71d642de265e02921427f72eb0c7cdf00c0b99
parent323a3edafe0ac3e3b101db87188fe9ace1d9c388

test/link: add explicit lib name test


1 files changed, 58 insertions(+), 0 deletions(-)

test/link.zig+58
......@@ -277,6 +277,64 @@ pub fn addCases(ctx: *LinkContext) void {
277277 });
278278 }
279279 }
280
281 if (ctx.includeTest("explicit-extern-lib-name")) |case| {
282 // TODO: Lld.zig does not look at explicit inputs to resolve explicit extern lib names
283 if (ctx.use_llvm) return;
284
285 const lib1 = case.addLibrary(.dynamic, .{
286 .name = "lib1",
287 .name_target = false,
288 .zig_source_bytes =
289 \\export fn foo() u8 {
290 \\ return 43;
291 \\}
292 ,
293 });
294
295 const lib2 = case.addLibrary(.dynamic, .{
296 .name = "lib2",
297 .name_target = false,
298 .zig_source_bytes =
299 \\export fn foo() u8 {
300 \\ return 42;
301 \\}
302 ,
303 });
304
305 const lib3 = case.addLibrary(.static, .{
306 .name = "lib3",
307 .zig_source_bytes =
308 \\extern fn foo() u8;
309 \\export fn callFoo() u8 {
310 \\ return foo();
311 \\}
312 ,
313 });
314
315 const exe = case.addExecutable(.{
316 .name = "test",
317 .zig_source_bytes =
318 \\extern "explicit-extern-lib-name-lib2" fn foo() u8;
319 \\extern fn callFoo() u8;
320 \\pub fn main() !u8 {
321 \\ return foo() + callFoo();
322 \\}
323 ,
324 });
325 exe.root_module.linkLibrary(lib1);
326 exe.root_module.linkLibrary(lib2);
327 // exe.root_module.addLibraryPath(.{
328 // .generated = .{
329 // .index = lib2.getEmittedBin().generated.index,
330 // .up = 1,
331 // },
332 // });
333 exe.root_module.linkLibrary(lib3);
334
335 const run = case.addRunArtifact(exe);
336 run.addCheck(.{ .expect_term = .{ .exited = 84 } });
337 }
280338}
281339
282340const LinkContext = @import("tests.zig").LinkContext;