Skip to content

Commit 65e4725

Browse files
committed
Add standalone test for interdep C archives
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`.
1 parent a5bbc66 commit 65e4725

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

test/standalone.zig

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
1616
cases.addBuildFile("test/standalone/mix_o_files/build.zig");
1717
cases.addBuildFile("test/standalone/global_linkage/build.zig");
1818
cases.addBuildFile("test/standalone/static_c_lib/build.zig");
19+
cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig");
1920
cases.addBuildFile("test/standalone/issue_339/build.zig");
2021
cases.addBuildFile("test/standalone/issue_794/build.zig");
2122
cases.addBuildFile("test/standalone/issue_5825/build.zig");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "a.h"
2+
int32_t add(int32_t a, int32_t b) {
3+
return a + b;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <stdint.h>
2+
int32_t add(int32_t a, int32_t b);
Original file line numberDiff line numberDiff line change
@@ -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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <stdint.h>
2+
int32_t sub(int32_t a, int32_t b);
Original file line numberDiff line numberDiff line change
@@ -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+
}
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)