mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
Add standalone test for common symbols
This commit is contained in:
parent
0e08cd63e2
commit
183d5f4a53
@ -15,6 +15,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||
cases.addBuildFile("test/standalone/static_c_lib/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/link_static_lib_as_system_lib/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/link_common_symbols/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/issue_339/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/issue_8550/build.zig", .{});
|
||||
cases.addBuildFile("test/standalone/issue_794/build.zig", .{});
|
||||
|
||||
6
test/standalone/link_common_symbols/a.c
Normal file
6
test/standalone/link_common_symbols/a.c
Normal file
@ -0,0 +1,6 @@
|
||||
int i;
|
||||
int j;
|
||||
|
||||
int add_to_i_and_j(int x) {
|
||||
return x + i + j;
|
||||
}
|
||||
6
test/standalone/link_common_symbols/b.c
Normal file
6
test/standalone/link_common_symbols/b.c
Normal file
@ -0,0 +1,6 @@
|
||||
long i;
|
||||
int j = 2;
|
||||
|
||||
void incr_i() {
|
||||
i++;
|
||||
}
|
||||
16
test/standalone/link_common_symbols/build.zig
Normal file
16
test/standalone/link_common_symbols/build.zig
Normal file
@ -0,0 +1,16 @@
|
||||
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.addCSourceFiles(&.{ "a.c", "b.c" }, &.{"-fcommon"});
|
||||
lib_a.setBuildMode(mode);
|
||||
|
||||
const test_exe = b.addTest("main.zig");
|
||||
test_exe.setBuildMode(mode);
|
||||
test_exe.linkLibrary(lib_a);
|
||||
|
||||
const test_step = b.step("test", "Test it");
|
||||
test_step.dependOn(&test_exe.step);
|
||||
}
|
||||
11
test/standalone/link_common_symbols/main.zig
Normal file
11
test/standalone/link_common_symbols/main.zig
Normal file
@ -0,0 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
|
||||
extern fn incr_i() void;
|
||||
extern fn add_to_i_and_j(x: c_int) c_int;
|
||||
|
||||
test "import C common symbols" {
|
||||
incr_i();
|
||||
const res = add_to_i_and_j(2);
|
||||
try expect(res == 5);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user