| author | |
| committer | |
| log | de297890e399b83fe99182cc2f223117099f35b2 |
| tree | 91b4578e819e08a3392f2aa9dad54de2fbd71bd2 |
| parent | 7be8e660acaa56d2be110d59b058ff2a31b05e23 |
3 files changed, 61 insertions(+), 3 deletions(-)
test/link.zig+39-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | pub fn addCases(ctx: *@import("tests.zig").LinkContext) void { | 1 | pub fn addCases(ctx: *LinkContext) void { |
| 2 | if (ctx.includeTest("exports-static")) |prefix| { | 2 | if (ctx.includeTest("exports-static")) |prefix| { |
| 3 | const lib = ctx.addLibrary(.static, .{ | 3 | const lib = ctx.addLibrary(.static, .{ |
| 4 | .name = "lib", | 4 | .name = "lib", |
| ... | @@ -23,8 +23,46 @@ pub fn addCases(ctx: *@import("tests.zig").LinkContext) void { | ... | @@ -23,8 +23,46 @@ pub fn addCases(ctx: *@import("tests.zig").LinkContext) void { |
| 23 | }, .{}); | 23 | }, .{}); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 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 | }); | ||
| 26 | 52 | ||
| 53 | const lib = ctx.addLibrary(.static, .{ .name = "lib" }); | ||
| 54 | lib.root_module.addObject(obj1); | ||
| 55 | lib.root_module.addObject(obj2); | ||
| 27 | 56 | ||
| 57 | ctx.verifyObjdump(prefix, lib, &.{ | ||
| 58 | "-s", | ||
| 59 | "--elements=file-type", | ||
| 60 | "--symbols", | ||
| 61 | "--only-symbol=foo", | ||
| 62 | "--only-symbol=Foo", | ||
| 63 | }, .{}); | ||
| 64 | } | ||
| 28 | } | 65 | } |
| 29 | 66 | ||
| 67 | const LinkContext = @import("tests.zig").LinkContext; | ||
| 30 | const std = @import("std"); | 68 | const std = @import("std"); |
test/link/snapshots/emit-static-lib.lib.dmp created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | lib.lib: COFF archive | ||
| 2 | lib.lib(obj1.obj): COFF object | ||
| 3 | xxxx 00000000 1 NULL() EXTERNAL | fooBar | ||
| 4 | xxxx 00000000 2 NULL EXTERNAL | foo1 | ||
| 5 | xxxx 00000004 2 NULL EXTERNAL | foo2 | ||
| 6 | lib.lib(this_is_a_long_name.obj): COFF object | ||
| 7 | xxxx 00000000 4 NULL() EXTERNAL | weakFoo | ||
| 8 | xxxx 00000000 2 NULL EXTERNAL | strong_foo_alias | ||
| 9 | xxxx 00000000 2 NULL EXTERNAL | strong_foo | ||
test/src/Link.zig+13-2| ... | @@ -30,8 +30,17 @@ pub fn addLibrary( | ... | @@ -30,8 +30,17 @@ pub fn addLibrary( |
| 30 | .linkage = linkage, | 30 | .linkage = linkage, |
| 31 | .name = overlay.name, | 31 | .name = overlay.name, |
| 32 | .root_module = self.createModule(overlay), | 32 | .root_module = self.createModule(overlay), |
| 33 | .use_llvm = self.use_llvm, | 33 | .use_llvm = overlay.use_llvm orelse self.use_llvm, |
| 34 | .use_lld = self.use_lld, | 34 | .use_lld = overlay.use_lld orelse self.use_lld, |
| 35 | }); | ||
| 36 | } | ||
| 37 | |||
| 38 | pub 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, | ||
| 35 | }); | 44 | }); |
| 36 | } | 45 | } |
| 37 | 46 | ||
| ... | @@ -169,6 +178,8 @@ const OverlayOptions = struct { | ... | @@ -169,6 +178,8 @@ const OverlayOptions = struct { |
| 169 | zig_source_file: ?std.Build.LazyPath = null, | 178 | zig_source_file: ?std.Build.LazyPath = null, |
| 170 | pic: ?bool = null, | 179 | pic: ?bool = null, |
| 171 | strip: ?bool = null, | 180 | strip: ?bool = null, |
| 181 | use_llvm: ?bool = null, | ||
| 182 | use_lld: ?bool = null, | ||
| 172 | }; | 183 | }; |
| 173 | 184 | ||
| 174 | const std = @import("std"); | 185 | const std = @import("std"); |