Fix being unusable as library

main
copygirl 1 month ago
parent 0ad372207b
commit f48a6884ca
  1. 31
      build.zig

@ -4,39 +4,36 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
_ = b.addModule("flecs-zig-ble", .{ const module = b.addModule("flecs-zig-ble", .{
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = .{ .path = "src/main.zig" },
}); });
module.addIncludePath(.{ .path = "libs/flecs" });
const lib = b.addStaticLibrary(.{ const lib = b.addStaticLibrary(.{
.name = "flecs-zig-ble", .name = "flecs-zig-ble",
.root_source_file = .{ .path = "src/main.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
setupFlecs(lib);
lib.installHeader("libs/flecs/flecs.h", "flecs.h"); lib.linkLibC();
lib.addCSourceFile(.{
.file = .{ .path = "libs/flecs/flecs.c" },
.flags = &.{"-fno-sanitize=undefined"},
});
b.installArtifact(lib); b.installArtifact(lib);
if (lib.rootModuleTarget().os.tag == .windows) {
lib.linkSystemLibrary("ws2_32");
}
const main_tests = b.addTest(.{ const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = .{ .path = "src/main.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
setupFlecs(main_tests); main_tests.linkLibrary(lib);
main_tests.addIncludePath(.{ .path = "libs/flecs" });
const run_main_tests = b.addRunArtifact(main_tests); const run_main_tests = b.addRunArtifact(main_tests);
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step); test_step.dependOn(&run_main_tests.step);
} }
fn setupFlecs(step: *std.Build.Step.Compile) void {
step.linkLibC();
step.addIncludePath(.{ .path = "libs/flecs" });
step.addCSourceFile(.{
.file = .{ .path = "libs/flecs/flecs.c" },
.flags = &.{"-fno-sanitize=undefined"},
});
if (step.rootModuleTarget().os.tag == .windows) {
step.linkSystemLibrary("ws2_32");
}
}

Loading…
Cancel
Save