authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:36-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:27:16-04:00
logde297890e399b83fe99182cc2f223117099f35b2
tree91b4578e819e08a3392f2aa9dad54de2fbd71bd2
parent7be8e660acaa56d2be110d59b058ff2a31b05e23

test/link: add emit-static-lib


3 files changed, 61 insertions(+), 3 deletions(-)

test/link.zig+39-1
......@@ -1,4 +1,4 @@
1pub fn addCases(ctx: *@import("tests.zig").LinkContext) void {
1pub fn addCases(ctx: *LinkContext) void {
22 if (ctx.includeTest("exports-static")) |prefix| {
33 const lib = ctx.addLibrary(.static, .{
44 .name = "lib",
......@@ -23,8 +23,46 @@ pub fn addCases(ctx: *@import("tests.zig").LinkContext) void {
2323 }, .{});
2424 }
2525
26 if (ctx.includeTest("emit-static-lib")) |prefix| {
27 const obj1 = ctx.addObject(.{
28 .name = "obj1",
29 .use_llvm = true,
30 .use_lld = true,
31 .c_source_bytes =
32 \\int foo1 = 1;
33 \\int foo2 = 2;
34 \\int fooBar() {
35 \\ return foo1 + foo2;
36 \\}
37 ,
38 });
39 const obj2 = ctx.addObject(.{
40 .name = "this_is_a_long_name",
41 .zig_source_bytes =
42 \\fn weakFoo() callconv(.c) usize {
43 \\ return 42;
44 \\}
45 \\export var strong_foo: usize = 100;
46 \\comptime {
47 \\ @export(&weakFoo, .{ .name = "weakFoo", .linkage = .weak });
48 \\ @export(&strong_foo, .{ .name = "strong_foo_alias", .linkage = .strong });
49 \\}
50 ,
51 });
2652
53 const lib = ctx.addLibrary(.static, .{ .name = "lib" });
54 lib.root_module.addObject(obj1);
55 lib.root_module.addObject(obj2);
2756
57 ctx.verifyObjdump(prefix, lib, &.{
58 "-s",
59 "--elements=file-type",
60 "--symbols",
61 "--only-symbol=foo",
62 "--only-symbol=Foo",
63 }, .{});
64 }
2865}
2966
67const LinkContext = @import("tests.zig").LinkContext;
3068const std = @import("std");
test/link/snapshots/emit-static-lib.lib.dmp created+9
......@@ -0,0 +1,9 @@
1lib.lib: COFF archive
2lib.lib(obj1.obj): COFF object
3xxxx 00000000 1 NULL() EXTERNAL | fooBar
4xxxx 00000000 2 NULL EXTERNAL | foo1
5xxxx 00000004 2 NULL EXTERNAL | foo2
6lib.lib(this_is_a_long_name.obj): COFF object
7xxxx 00000000 4 NULL() EXTERNAL | weakFoo
8xxxx 00000000 2 NULL EXTERNAL | strong_foo_alias
9xxxx 00000000 2 NULL EXTERNAL | strong_foo
test/src/Link.zig+13-2
......@@ -30,8 +30,17 @@ pub fn addLibrary(
3030 .linkage = linkage,
3131 .name = overlay.name,
3232 .root_module = self.createModule(overlay),
33 .use_llvm = self.use_llvm,
34 .use_lld = self.use_lld,
33 .use_llvm = overlay.use_llvm orelse self.use_llvm,
34 .use_lld = overlay.use_lld orelse self.use_lld,
35 });
36}
37
38pub fn addObject(self: *const Link, overlay: OverlayOptions) *Step.Compile {
39 return self.b.addObject(.{
40 .name = overlay.name,
41 .root_module = self.createModule(overlay),
42 .use_llvm = overlay.use_llvm orelse self.use_llvm,
43 .use_lld = overlay.use_lld orelse self.use_lld,
3544 });
3645}
3746
......@@ -169,6 +178,8 @@ const OverlayOptions = struct {
169178 zig_source_file: ?std.Build.LazyPath = null,
170179 pic: ?bool = null,
171180 strip: ?bool = null,
181 use_llvm: ?bool = null,
182 use_lld: ?bool = null,
172183};
173184
174185const std = @import("std");