Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const opt_use_shared = b.option(bool, "shared", "Make shared (default: false)") orelse false;
_ = b.addModule("root", .{
.root_source_file = b.path("src/zflecs.zig"),
});

const flecs = if (opt_use_shared) b.addSharedLibrary(.{
.name = "flecs",
.target = target,
.optimize = optimize,
}) else b.addStaticLibrary(.{
.name = "flecs",
const module = b.addModule("root", .{
.root_source_file = b.path("src/zflecs.zig"),
.target = target,
.optimize = optimize,
});
flecs.linkLibC();
flecs.addIncludePath(b.path("libs/flecs"));
flecs.addCSourceFile(.{
module.addIncludePath(b.path("libs/flecs"));
module.addCSourceFile(.{
.file = b.path("libs/flecs/flecs.c"),
.flags = &.{
"-fno-sanitize=undefined",
Expand All @@ -29,24 +21,32 @@ pub fn build(b: *std.Build) void {
if (opt_use_shared) "-DFLECS_SHARED" else "",
},
});
b.installArtifact(flecs);

const lib = b.addLibrary(.{
.name = "flecs",
.linkage = if (opt_use_shared) .dynamic else .static,
.root_module = module,
});
lib.linkLibC();
b.installArtifact(lib);

if (target.result.os.tag == .windows) {
flecs.linkSystemLibrary("ws2_32");
lib.linkSystemLibrary("ws2_32");
}
const test_step = b.step("test", "Run zflecs tests");

const tests = b.addTest(.{
.name = "zflecs-tests",
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.linkLibC();
tests.addIncludePath(b.path("libs/flecs"));
tests.linkLibrary(lib);
tests.linkLibC();
b.installArtifact(tests);

tests.linkLibrary(flecs);

test_step.dependOn(&b.addRunArtifact(tests).step);
}
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .zflecs,
.fingerprint = 0xb539547bca77f3d4,
.version = "0.2.0-dev",
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.15.1",
.paths = .{
"build.zig",
"build.zig.zon",
Expand Down
23 changes: 8 additions & 15 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ test "zflecs.basic" {
const Eats = struct {};
const Apples = struct {};

fn move(it: *ecs.iter_t) callconv(.C) void {
fn move(it: *ecs.iter_t) callconv(.c) void {
const p = ecs.field(it, Position, 0).?;
const v = ecs.field(it, Velocity, 1).?;

Expand Down Expand Up @@ -477,27 +477,20 @@ test "zflecs.struct-dtor-hook" {
defer _ = ecs.fini(world);

const Chat = struct {
messages: std.ArrayList([]const u8),

pub fn init(allocator: std.mem.Allocator) @This() {
return @This(){
.messages = std.ArrayList([]const u8).init(allocator),
};
}

pub fn dtor(self: @This()) void {
self.messages.deinit();
messages: std.ArrayList([]const u8) = .{},
pub fn dtor(self: *@This()) void {
self.messages.deinit(std.testing.allocator);
}
};

ecs.COMPONENT(world, Chat);
{
var system_desc = ecs.system_desc_t{};
system_desc.callback = struct {
pub fn chatSystem(it: *ecs.iter_t) callconv(.C) void {
pub fn chatSystem(it: *ecs.iter_t) callconv(.c) void {
const chat_components = ecs.field(it, Chat, 0).?;
for (0..it.count()) |i| {
chat_components[i].messages.append("some words hi") catch @panic("whomp");
chat_components[i].messages.append(std.testing.allocator, "some words hi") catch @panic("whomp");
}
}
}.chatSystem;
Expand All @@ -506,7 +499,7 @@ test "zflecs.struct-dtor-hook" {
}

const chat_entity = ecs.new_entity(world, "Chat entity");
_ = ecs.set(world, chat_entity, Chat, Chat.init(std.testing.allocator));
_ = ecs.set(world, chat_entity, Chat, Chat{});

_ = ecs.progress(world, 0);

Expand All @@ -517,7 +510,7 @@ test "zflecs.struct-dtor-hook" {
// commented out since the cleanup is never called to free the ArrayList
// memory.
}
fn module(world: *ecs.world_t) callconv(.C) void {
fn module(world: *ecs.world_t) callconv(.c) void {
var desc = ecs.component_desc_t{ .entity = 0, .type = .{ .size = 0, .alignment = 0 } };
_ = ecs.module_init(world, "SimpleModule", &desc);

Expand Down
Loading
Loading