File tree 7 files changed +47
-0
lines changed
standalone/link_interdependent_static_c_libs
7 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -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" );
Original file line number Diff line number Diff line change
1
+ #include "a.h"
2
+ int32_t add (int32_t a , int32_t b ) {
3
+ return a + b ;
4
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdint.h>
2
+ int32_t add (int32_t a , int32_t b );
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ #include <stdint.h>
2
+ int32_t sub (int32_t a , int32_t b );
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments