|
1 | 1 | const std = @import("std"); |
2 | 2 |
|
3 | | -const module_ex1 = @import("build_c_application_with_zig_build.zig"); |
4 | | -const module_ex2 = @import("build_zig_linked_to_c.zig"); |
| 3 | +const module_c_app = @import("build_c_app.zig"); |
| 4 | +const module_zig_app = @import("build_zig_app.zig"); |
5 | 5 | const module_ex3 = @import("build_zig_c_wrapper.zig"); |
6 | | -const module_ex4 = @import("build_c_static_library_with_zig_build.zig"); |
7 | | -const module_ex5 = @import("build_c_shared_library_with_zig_build.zig"); |
8 | | -// const module_ex6 = @import("build_zig_linked_to_c_static_lib.zig"); |
9 | | -// const module_ex7 = @import("build_zig_linked_to_c_shared_lib.zig"); |
| 6 | +const module_lib_static = @import("build_c_static_lib.zig"); |
| 7 | +const module_lib_shared = @import("build_c_shared_lib.zig"); |
| 8 | +const module_zig_app_static = @import("build_zig_app_static.zig"); |
| 9 | +const module_zig_app_shared = @import("build_zig_app_shared.zig"); |
10 | 10 |
|
11 | 11 | pub fn build(b: *std.Build) void { |
12 | 12 | const target = b.standardTargetOptions(.{}); |
13 | 13 | const optimize = b.standardOptimizeOption(.{}); |
14 | 14 |
|
15 | | - // ex1 |
16 | | - const ex1 = module_ex1.build(b, target, optimize); |
17 | | - const run_ex1 = b.addRunArtifact(ex1); |
| 15 | + // c_app |
| 16 | + const c_app = module_c_app.build(b, target, optimize); |
| 17 | + const run_c_app = b.addRunArtifact(c_app); |
18 | 18 |
|
19 | | - b.installArtifact(ex1); |
| 19 | + b.installArtifact(c_app); |
20 | 20 |
|
21 | | - const run_ex1_step = b.step("ex1", "Run a C application build with Zig's build system."); |
22 | | - run_ex1_step.dependOn(&run_ex1.step); |
| 21 | + const run_c_app_step = b.step("c_app", "Run a C application build with Zig's build system."); |
| 22 | + run_c_app_step.dependOn(&run_c_app.step); |
23 | 23 |
|
24 | | - // ex2 |
25 | | - const ex2 = module_ex2.build(b, target, optimize); |
26 | | - const run_ex2 = b.addRunArtifact(ex2); |
| 24 | + // zig_app |
| 25 | + const zig_app = module_zig_app.build(b, target, optimize); |
| 26 | + const run_zig_app = b.addRunArtifact(zig_app); |
27 | 27 |
|
28 | | - b.installArtifact(ex2); |
| 28 | + b.installArtifact(zig_app); |
29 | 29 |
|
30 | | - const run_ex2_step = b.step("ex2", "Run a Zig application linked to C source code."); |
31 | | - run_ex2_step.dependOn(&run_ex2.step); |
| 30 | + const run_zig_app_step = b.step("zig_app", "Run a Zig application linked to C source code."); |
| 31 | + run_zig_app_step.dependOn(&run_zig_app.step); |
32 | 32 |
|
33 | | - // ex3 |
34 | | - const ex3 = module_ex3.build(b, target, optimize); |
35 | | - const run_ex3 = b.addRunArtifact(ex3); |
| 33 | + // lib_static |
| 34 | + const lib_static = module_lib_static.build(b, target, optimize); |
| 35 | + const install_lib_static = b.addInstallArtifact(lib_static, .{}); |
36 | 36 |
|
37 | | - b.installArtifact(ex3); |
| 37 | + b.installArtifact(lib_static); |
38 | 38 |
|
39 | | - const run_ex3_step = b.step("ex3", "Run a Zig application with an abstraction layer between the C source code."); |
40 | | - run_ex3_step.dependOn(&run_ex3.step); |
| 39 | + const install_lib_static_step = b.step("lib_static", "Create a static library from C source code."); |
| 40 | + install_lib_static_step.dependOn(&install_lib_static.step); |
41 | 41 |
|
42 | | - // ex4 |
43 | | - const ex4 = module_ex4.build(b, target, optimize); |
44 | | - const install_ex4 = b.addInstallArtifact(ex4, .{}); |
| 42 | + // lib_shared |
| 43 | + const lib_shared = module_lib_shared.build(b, target, optimize); |
| 44 | + const install_lib_shared = b.addInstallArtifact(lib_shared, .{}); |
45 | 45 |
|
46 | | - b.installArtifact(ex4); |
| 46 | + b.installArtifact(lib_shared); |
47 | 47 |
|
48 | | - const install_ex4_step = b.step("ex4", "Create a shared library file from C source code."); |
49 | | - install_ex4_step.dependOn(&install_ex4.step); |
| 48 | + const install_lib_shared_step = b.step("lib_shared", "Create a shared library from C source code."); |
| 49 | + install_lib_shared_step.dependOn(&install_lib_shared.step); |
50 | 50 |
|
51 | | - // ex5 |
52 | | - const ex5 = module_ex5.build(b, target, optimize); |
53 | | - const install_ex5 = b.addInstallArtifact(ex5, .{}); |
| 51 | + // zig_app_shared |
| 52 | + const zig_app_shared = module_zig_app_shared.build(b, target, optimize); |
| 53 | + const run_zig_app_shared = b.addInstallArtifact(zig_app_shared, .{}); |
54 | 54 |
|
55 | | - b.installArtifact(ex5); |
| 55 | + b.installArtifact(zig_app_shared); |
56 | 56 |
|
57 | | - const install_ex5_step = b.step("ex5", "Create a static library file from C source code."); |
58 | | - install_ex5_step.dependOn(&install_ex5.step); |
| 57 | + const run_zig_app_shared_step = b.step("zig_app_shared", "Run a Zig application that is linked to a shared library."); |
| 58 | + run_zig_app_shared_step.dependOn(&install_lib_shared.step); // create and install shared library |
| 59 | + run_zig_app_shared_step.dependOn(&run_zig_app_shared.step); |
59 | 60 |
|
60 | | - // ex6 |
61 | | - // const ex6 = module_ex6.build(b, target, optimize); |
62 | | - // const run_ex6 = b.addInstallArtifact(ex6, .{}); |
| 61 | + // zig_app_static |
| 62 | + const zig_app_static = module_zig_app_static.build(b, target, optimize); |
| 63 | + const run_zig_app_static = b.addInstallArtifact(zig_app_static, .{}); |
63 | 64 |
|
64 | | - // b.installArtifact(ex6); |
| 65 | + b.installArtifact(zig_app_static); |
65 | 66 |
|
66 | | - // const run_ex6_step = b.step("ex6", "Run a Zig application that is statically linked to a C library."); |
67 | | - // run_ex6_step.dependOn(&run_ex6.step); |
68 | | - |
69 | | - // ex7 |
70 | | - // const ex7 = module_ex7.build(b, target, optimize); |
71 | | - // const run_ex7 = b.addInstallArtifact(ex7, .{}); |
72 | | - |
73 | | - // b.installArtifact(ex7); |
74 | | - |
75 | | - // const run_ex7_step = b.step("ex7", "Run a Zig application that is dynamically linked to a C library."); |
76 | | - // run_ex7_step.dependOn(&run_ex7.step); |
| 67 | + const run_zig_app_static_step = b.step("zig_app_static", "Run a Zig application that is linked to a static library."); |
| 68 | + run_zig_app_static_step.dependOn(&install_lib_static.step); // create and install static library |
| 69 | + run_zig_app_static_step.dependOn(&run_zig_app_static.step); |
77 | 70 | } |
0 commit comments