| author | |
| committer | |
| log | 65e4725aba5947a86c12c775b05a31cc1c08cfab |
| tree | 453c192c679a4f0ae61722db10d14175b15b11ea |
| parent | a5bbc66f10339cb2e17ef996ef097b696980595a |
Tests a scenario where the linker line has the following:
```
main.o libA.a libB.a
```
where `main.o` pulls a symbol from `libB.a`, which in turn is
dependent on a symbol from `libA.a`.7 files changed, 47 insertions(+), 0 deletions(-)
test/standalone.zig+1| ... | ... | @@ -16,6 +16,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 16 | 16 | cases.addBuildFile("test/standalone/mix_o_files/build.zig"); |
| 17 | 17 | cases.addBuildFile("test/standalone/global_linkage/build.zig"); |
| 18 | 18 | cases.addBuildFile("test/standalone/static_c_lib/build.zig"); |
| 19 | cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig"); | |
| 19 | 20 | cases.addBuildFile("test/standalone/issue_339/build.zig"); |
| 20 | 21 | cases.addBuildFile("test/standalone/issue_794/build.zig"); |
| 21 | 22 | cases.addBuildFile("test/standalone/issue_5825/build.zig"); |
test/standalone/link_interdependent_static_c_libs/a.c created+4| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | #include "a.h" | |
| 2 | int32_t add(int32_t a, int32_t b) { | |
| 3 | return a + b; | |
| 4 | } |
test/standalone/link_interdependent_static_c_libs/a.h created+2| ... | ... | @@ -0,0 +1,2 @@ |
| 1 | #include <stdint.h> | |
| 2 | int32_t add(int32_t a, int32_t b); |
test/standalone/link_interdependent_static_c_libs/b.c created+6| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | #include "a.h" | |
| 2 | #include "b.h" | |
| 3 | ||
| 4 | int32_t sub(int32_t a, int32_t b) { | |
| 5 | return add(a, -1 * b); | |
| 6 | } |
test/standalone/link_interdependent_static_c_libs/b.h created+2| ... | ... | @@ -0,0 +1,2 @@ |
| 1 | #include <stdint.h> | |
| 2 | int32_t sub(int32_t a, int32_t b); |
test/standalone/link_interdependent_static_c_libs/build.zig created+24| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | const Builder = @import("std").build.Builder; | |
| 2 | ||
| 3 | pub fn build(b: *Builder) void { | |
| 4 | const mode = b.standardReleaseOptions(); | |
| 5 | ||
| 6 | const lib_a = b.addStaticLibrary("a", null); | |
| 7 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | |
| 8 | lib_a.setBuildMode(mode); | |
| 9 | lib_a.addIncludeDir("."); | |
| 10 | ||
| 11 | const lib_b = b.addStaticLibrary("b", null); | |
| 12 | lib_b.addCSourceFile("b.c", &[_][]const u8{}); | |
| 13 | lib_b.setBuildMode(mode); | |
| 14 | lib_b.addIncludeDir("."); | |
| 15 | ||
| 16 | const test_exe = b.addTest("main.zig"); | |
| 17 | test_exe.setBuildMode(mode); | |
| 18 | test_exe.linkLibrary(lib_a); | |
| 19 | test_exe.linkLibrary(lib_b); | |
| 20 | test_exe.addIncludeDir("."); | |
| 21 | ||
| 22 | const test_step = b.step("test", "Test it"); | |
| 23 | test_step.dependOn(&test_exe.step); | |
| 24 | } |
test/standalone/link_interdependent_static_c_libs/main.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const c = @cImport(@cInclude("b.h")); | |
| 4 | ||
| 5 | test "import C sub" { | |
| 6 | const result = c.sub(2, 1); | |
| 7 | expect(result == 1); | |
| 8 | } |