| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test it"); |
| 5 | b.default_step = test_step; |
| 6 | |
| 7 | const optimize: std.builtin.Optimize = .debug; |
| 8 | |
| 9 | const obj = b.addObject(.{ |
| 10 | .name = "exports", |
| 11 | .root_module = b.createModule(.{ |
| 12 | .root_source_file = b.path("exports.zig"), |
| 13 | .target = b.graph.host, |
| 14 | .optimize = optimize, |
| 15 | }), |
| 16 | }); |
| 17 | const shared = b.addLibrary(.{ |
| 18 | .linkage = .dynamic, |
| 19 | .name = "shared", |
| 20 | .root_module = b.createModule(.{ |
| 21 | .root_source_file = null, |
| 22 | .target = b.graph.host, |
| 23 | .optimize = optimize, |
| 24 | .link_libc = true, |
| 25 | }), |
| 26 | }); |
| 27 | if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)"); |
| 28 | shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); |
| 29 | const test_exe = b.addTest(.{ .root_module = b.createModule(.{ |
| 30 | .root_source_file = b.path("main.zig"), |
| 31 | .target = b.graph.host, |
| 32 | .optimize = optimize, |
| 33 | }) }); |
| 34 | test_exe.root_module.addObject(obj); |
| 35 | test_exe.root_module.linkLibrary(shared); |
| 36 | |
| 37 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 38 | } |