| author | |
| committer | |
| log | 183d5f4a5312c090729823dd5ebf4500c0a5a5eb |
| tree | ee4feb6eb422a5d6b5c66103fab33e93ed74d65f |
| parent | 0e08cd63e236314750f18d28f8ede98a2188c6d2 |
5 files changed, 40 insertions(+), 0 deletions(-)
test/standalone.zig+1| ... | ... | @@ -15,6 +15,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 15 | 15 | cases.addBuildFile("test/standalone/static_c_lib/build.zig", .{}); |
| 16 | 16 | cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig", .{}); |
| 17 | 17 | cases.addBuildFile("test/standalone/link_static_lib_as_system_lib/build.zig", .{}); |
| 18 | cases.addBuildFile("test/standalone/link_common_symbols/build.zig", .{}); | |
| 18 | 19 | cases.addBuildFile("test/standalone/issue_339/build.zig", .{}); |
| 19 | 20 | cases.addBuildFile("test/standalone/issue_8550/build.zig", .{}); |
| 20 | 21 | cases.addBuildFile("test/standalone/issue_794/build.zig", .{}); |
test/standalone/link_common_symbols/a.c created+6| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | int i; | |
| 2 | int j; | |
| 3 | ||
| 4 | int add_to_i_and_j(int x) { | |
| 5 | return x + i + j; | |
| 6 | } |
test/standalone/link_common_symbols/b.c created+6| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | long i; | |
| 2 | int j = 2; | |
| 3 | ||
| 4 | void incr_i() { | |
| 5 | i++; | |
| 6 | } |
test/standalone/link_common_symbols/build.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 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.addCSourceFiles(&.{ "a.c", "b.c" }, &.{"-fcommon"}); | |
| 8 | lib_a.setBuildMode(mode); | |
| 9 | ||
| 10 | const test_exe = b.addTest("main.zig"); | |
| 11 | test_exe.setBuildMode(mode); | |
| 12 | test_exe.linkLibrary(lib_a); | |
| 13 | ||
| 14 | const test_step = b.step("test", "Test it"); | |
| 15 | test_step.dependOn(&test_exe.step); | |
| 16 | } |
test/standalone/link_common_symbols/main.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | ||
| 4 | extern fn incr_i() void; | |
| 5 | extern fn add_to_i_and_j(x: c_int) c_int; | |
| 6 | ||
| 7 | test "import C common symbols" { | |
| 8 | incr_i(); | |
| 9 | const res = add_to_i_and_j(2); | |
| 10 | try expect(res == 5); | |
| 11 | } |