build: convert to being a module

This commit is contained in:
torque 2023-08-21 23:30:31 -07:00
parent 9a4c80861c
commit ef185bc975
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
2 changed files with 17 additions and 23 deletions

View File

@ -8,15 +8,8 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// const nats = b.addModule("nats", .{
// .source_file = .{ .path = "source/nats.zig" },
// });
const nats = b.addExecutable(.{
.name = "nats_test",
.root_source_file = .{ .path = "src/nats.zig" },
.target = target,
.optimize = optimize,
const nats = b.addModule("nats", .{
.source_file = .{ .path = "src/nats.zig" },
});
const nats_c = nats_build.nats_c_lib(
@ -24,18 +17,17 @@ pub fn build(b: *std.Build) void {
.{ .name = "nats-c", .target = target, .optimize = optimize },
);
nats.linkLibrary(nats_c);
b.installArtifact(nats);
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/nats.zig" },
const tests = b.addTest(.{
.root_source_file = .{ .path = "tests/main.zig" },
.target = target,
.optimize = optimize,
});
main_tests.linkLibrary(nats_c);
tests.addModule("nats", nats);
tests.linkLibrary(nats_c);
const run_main_tests = b.addRunArtifact(main_tests);
b.installArtifact(tests);
const run_main_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_main_tests.step);
}

View File

@ -19,31 +19,33 @@ pub fn nats_c_lib(
.optimize = options.optimize,
});
lib.disable_sanitize_c = true;
const cflags = [_][]const u8{
"-fno-sanitize=undefined",
};
lib.linkLibC();
lib.addCSourceFiles(&common_sources, &.{"-fno-sanitize=undefined"});
lib.addCSourceFiles(&common_sources, &cflags);
lib.addIncludePath(.{ .path = nats_src_prefix ++ "include" });
// if building with streaming support
// lib.addIncludePath(.{ .path = nats_src_prefix ++ "stan" });
// lib.addCSourceFiles(&streaming_sources, &.{"-fno-sanitize=undefined"});
// lib.addCSourceFiles(&streaming_sources, &cflags);
const tinfo = lib.target_info.target;
switch (tinfo.os.tag) {
.windows => {
lib.addCSourceFiles(&win_sources, &.{"-fno-sanitize=undefined"});
lib.addCSourceFiles(&win_sources, &cflags);
if (tinfo.abi != .msvc) {
lib.addCSourceFiles(&.{"src/win-crosshack.c"}, &.{"-fno-sanitize=undefined"});
lib.addCSourceFiles(&.{"src/win-crosshack.c"}, &cflags);
}
lib.defineCMacro("_WIN32", null);
lib.linkSystemLibrary("ws2_32");
},
.macos => {
lib.addCSourceFiles(&unix_sources, &.{"-fno-sanitize=undefined"});
lib.addCSourceFiles(&unix_sources, &cflags);
lib.defineCMacro("DARWIN", null);
},
else => {
lib.addCSourceFiles(&unix_sources, &.{"-fno-sanitize=undefined"});
lib.addCSourceFiles(&unix_sources, &cflags);
lib.defineCMacro("_GNU_SOURCE", null);
lib.defineCMacro("LINUX", null);
// may need to link pthread and rt. Not sure if those are inluded with linkLibC