mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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`.
This commit is contained in:
parent
a5bbc66f10
commit
65e4725aba
7 changed files with 47 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
|||
cases.addBuildFile("test/standalone/mix_o_files/build.zig");
|
||||
cases.addBuildFile("test/standalone/global_linkage/build.zig");
|
||||
cases.addBuildFile("test/standalone/static_c_lib/build.zig");
|
||||
cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig");
|
||||
cases.addBuildFile("test/standalone/issue_339/build.zig");
|
||||
cases.addBuildFile("test/standalone/issue_794/build.zig");
|
||||
cases.addBuildFile("test/standalone/issue_5825/build.zig");
|
||||
|
|
|
|||
4
test/standalone/link_interdependent_static_c_libs/a.c
Normal file
4
test/standalone/link_interdependent_static_c_libs/a.c
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "a.h"
|
||||
int32_t add(int32_t a, int32_t b) {
|
||||
return a + b;
|
||||
}
|
||||
2
test/standalone/link_interdependent_static_c_libs/a.h
Normal file
2
test/standalone/link_interdependent_static_c_libs/a.h
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#include <stdint.h>
|
||||
int32_t add(int32_t a, int32_t b);
|
||||
6
test/standalone/link_interdependent_static_c_libs/b.c
Normal file
6
test/standalone/link_interdependent_static_c_libs/b.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "a.h"
|
||||
#include "b.h"
|
||||
|
||||
int32_t sub(int32_t a, int32_t b) {
|
||||
return add(a, -1 * b);
|
||||
}
|
||||
2
test/standalone/link_interdependent_static_c_libs/b.h
Normal file
2
test/standalone/link_interdependent_static_c_libs/b.h
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#include <stdint.h>
|
||||
int32_t sub(int32_t a, int32_t b);
|
||||
24
test/standalone/link_interdependent_static_c_libs/build.zig
Normal file
24
test/standalone/link_interdependent_static_c_libs/build.zig
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const Builder = @import("std").build.Builder;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const lib_a = b.addStaticLibrary("a", null);
|
||||
lib_a.addCSourceFile("a.c", &[_][]const u8{});
|
||||
lib_a.setBuildMode(mode);
|
||||
lib_a.addIncludeDir(".");
|
||||
|
||||
const lib_b = b.addStaticLibrary("b", null);
|
||||
lib_b.addCSourceFile("b.c", &[_][]const u8{});
|
||||
lib_b.setBuildMode(mode);
|
||||
lib_b.addIncludeDir(".");
|
||||
|
||||
const test_exe = b.addTest("main.zig");
|
||||
test_exe.setBuildMode(mode);
|
||||
test_exe.linkLibrary(lib_a);
|
||||
test_exe.linkLibrary(lib_b);
|
||||
test_exe.addIncludeDir(".");
|
||||
|
||||
const test_step = b.step("test", "Test it");
|
||||
test_step.dependOn(&test_exe.step);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const c = @cImport(@cInclude("b.h"));
|
||||
|
||||
test "import C sub" {
|
||||
const result = c.sub(2, 1);
|
||||
expect(result == 1);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue