Skip to content

Commit d4f97b7

Browse files
committed
Upgrade to Zig 0.15.1
1 parent 45dbf2c commit d4f97b7

File tree

5 files changed

+98
-106
lines changed

5 files changed

+98
-106
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn move_system(positions: []Position, velocities: []const Velocity) void {
3737
//Optionally, systems can receive the components iterator (usually not necessary)
3838
fn move_system_with_it(it: *ecs.iter_t, positions: []Position, velocities: []const Velocity) void {
3939
const type_str = ecs.table_str(it.world, it.table).?;
40-
std.debug.print("Move entities with [{s}]\n", .{type_str});
40+
std.log.info("Move entities with [{s}]\n", .{type_str});
4141
defer ecs.os.free(type_str);
4242
4343
for (positions, velocities) |*p, v| {
@@ -68,7 +68,7 @@ pub fn main() !void {
6868
_ = ecs.progress(world, 0);
6969
7070
const p = ecs.get(world, bob, Position).?;
71-
std.debug.print("Bob's position is ({d}, {d})\n", .{ p.x, p.y });
71+
std.log.info("Bob's position is ({d}, {d})\n", .{ p.x, p.y });
7272
}
7373
```
7474

build.zig

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ pub fn build(b: *std.Build) void {
44
const optimize = b.standardOptimizeOption(.{});
55
const target = b.standardTargetOptions(.{});
66
const opt_use_shared = b.option(bool, "shared", "Make shared (default: false)") orelse false;
7-
_ = b.addModule("root", .{
8-
.root_source_file = b.path("src/zflecs.zig"),
9-
});
107

11-
const flecs = if (opt_use_shared) b.addSharedLibrary(.{
12-
.name = "flecs",
13-
.target = target,
14-
.optimize = optimize,
15-
}) else b.addStaticLibrary(.{
16-
.name = "flecs",
8+
const module = b.addModule("root", .{
9+
.root_source_file = b.path("src/zflecs.zig"),
1710
.target = target,
1811
.optimize = optimize,
1912
});
20-
flecs.linkLibC();
21-
flecs.addIncludePath(b.path("libs/flecs"));
22-
flecs.addCSourceFile(.{
13+
module.addIncludePath(b.path("libs/flecs"));
14+
module.addCSourceFile(.{
2315
.file = b.path("libs/flecs/flecs.c"),
2416
.flags = &.{
2517
"-fno-sanitize=undefined",
@@ -29,24 +21,32 @@ pub fn build(b: *std.Build) void {
2921
if (opt_use_shared) "-DFLECS_SHARED" else "",
3022
},
3123
});
32-
b.installArtifact(flecs);
24+
25+
const lib = b.addLibrary(.{
26+
.name = "flecs",
27+
.linkage = if (opt_use_shared) .dynamic else .static,
28+
.root_module = module,
29+
});
30+
lib.linkLibC();
31+
b.installArtifact(lib);
3332

3433
if (target.result.os.tag == .windows) {
35-
flecs.linkSystemLibrary("ws2_32");
34+
lib.linkSystemLibrary("ws2_32");
3635
}
3736
const test_step = b.step("test", "Run zflecs tests");
3837

3938
const tests = b.addTest(.{
4039
.name = "zflecs-tests",
41-
.root_source_file = b.path("src/tests.zig"),
42-
.target = target,
43-
.optimize = optimize,
40+
.root_module = b.createModule(.{
41+
.root_source_file = b.path("src/tests.zig"),
42+
.target = target,
43+
.optimize = optimize,
44+
}),
4445
});
45-
tests.linkLibC();
4646
tests.addIncludePath(b.path("libs/flecs"));
47+
tests.linkLibrary(lib);
48+
tests.linkLibC();
4749
b.installArtifact(tests);
4850

49-
tests.linkLibrary(flecs);
50-
5151
test_step.dependOn(&b.addRunArtifact(tests).step);
5252
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .zflecs,
33
.fingerprint = 0xb539547bca77f3d4,
44
.version = "0.2.0-dev",
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.1",
66
.paths = .{
77
"build.zig",
88
"build.zig.zon",

src/tests.zig

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ test "zflecs.basic" {
285285
const Eats = struct {};
286286
const Apples = struct {};
287287

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

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

479479
const Chat = struct {
480-
messages: std.ArrayList([]const u8),
481-
482-
pub fn init(allocator: std.mem.Allocator) @This() {
483-
return @This(){
484-
.messages = std.ArrayList([]const u8).init(allocator),
485-
};
486-
}
487-
488-
pub fn dtor(self: @This()) void {
489-
self.messages.deinit();
480+
messages: std.ArrayList([]const u8) = .{},
481+
pub fn dtor(self: *@This()) void {
482+
self.messages.deinit(std.testing.allocator);
490483
}
491484
};
492485

493486
ecs.COMPONENT(world, Chat);
494487
{
495488
var system_desc = ecs.system_desc_t{};
496489
system_desc.callback = struct {
497-
pub fn chatSystem(it: *ecs.iter_t) callconv(.C) void {
490+
pub fn chatSystem(it: *ecs.iter_t) callconv(.c) void {
498491
const chat_components = ecs.field(it, Chat, 0).?;
499492
for (0..it.count()) |i| {
500-
chat_components[i].messages.append("some words hi") catch @panic("whomp");
493+
chat_components[i].messages.append(std.testing.allocator, "some words hi") catch @panic("whomp");
501494
}
502495
}
503496
}.chatSystem;
@@ -506,7 +499,7 @@ test "zflecs.struct-dtor-hook" {
506499
}
507500

508501
const chat_entity = ecs.new_entity(world, "Chat entity");
509-
_ = ecs.set(world, chat_entity, Chat, Chat.init(std.testing.allocator));
502+
_ = ecs.set(world, chat_entity, Chat, Chat{});
510503

511504
_ = ecs.progress(world, 0);
512505

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

0 commit comments

Comments
 (0)