make source files and build file compatible with current zig compiler 0.11.0-dev.1580+a5b34a61a

master
Stefan Partheymüller 2 years ago
parent e0eb68dd5b
commit 94f38a3d89

@ -3,7 +3,10 @@ const Builder = std.build.Builder;
const builtin = @import("builtin"); const builtin = @import("builtin");
pub fn build(b: *Builder) void { pub fn build(b: *Builder) void {
const build_mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const ecs_module = b.createModule(.{
.source_file = std.build.FileSource{ .path = "src/ecs.zig" },
});
// use a different cache folder for macos arm builds // use a different cache folder for macos arm builds
b.cache_root = if (builtin.os.tag == .macos and builtin.target.cpu.arch == .aarch64) "zig-arm-cache" else "zig-cache"; b.cache_root = if (builtin.os.tag == .macos and builtin.target.cpu.arch == .aarch64) "zig-arm-cache" else "zig-cache";
@ -18,11 +21,14 @@ pub fn build(b: *Builder) void {
const name = if (i == 0) "ecs" else example[0]; const name = if (i == 0) "ecs" else example[0];
const source = example[1]; const source = example[1];
var exe = b.addExecutable(name, source); var exe = b.addExecutable(.{
exe.setBuildMode(b.standardReleaseOptions()); .name = name,
.root_source_file = std.build.FileSource{ .path = source },
.optimize = optimize,
});
exe.setOutputDir(std.fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "bin" }) catch unreachable); exe.setOutputDir(std.fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "bin" }) catch unreachable);
exe.addPackagePath("ecs", "src/ecs.zig"); exe.addModule("ecs", ecs_module);
exe.linkSystemLibrary("c"); exe.linkLibC();
const docs = exe; const docs = exe;
docs.emit_docs = .emit; docs.emit_docs = .emit;
@ -42,13 +48,17 @@ pub fn build(b: *Builder) void {
} }
// internal tests // internal tests
const internal_test_step = b.addTest("src/tests.zig"); const internal_test_step = b.addTest(.{
internal_test_step.setBuildMode(build_mode); .root_source_file = std.build.FileSource{ .path = "src/tests.zig" },
.optimize = optimize,
});
// public api tests // public api tests
const test_step = b.addTest("tests/tests.zig"); const test_step = b.addTest(.{
test_step.addPackagePath("ecs", "src/ecs.zig"); .root_source_file = std.build.FileSource{ .path = "tests/tests.zig" },
test_step.setBuildMode(build_mode); .optimize = optimize,
});
test_step.addModule("ecs", ecs_module);
const test_cmd = b.step("test", "Run the tests"); const test_cmd = b.step("test", "Run the tests");
test_cmd.dependOn(&internal_test_step.step); test_cmd.dependOn(&internal_test_step.step);
@ -61,7 +71,7 @@ pub const LibType = enum(i32) {
exe_compiled, exe_compiled,
}; };
pub fn getPackage(comptime prefix_path: []const u8) std.build.Pkg { pub fn getModule(comptime prefix_path: []const u8) std.build.Module {
return .{ return .{
.name = "ecs", .name = "ecs",
.path = .{ .path = prefix_path ++ "src/ecs.zig" }, .path = .{ .path = prefix_path ++ "src/ecs.zig" },
@ -70,18 +80,16 @@ pub fn getPackage(comptime prefix_path: []const u8) std.build.Pkg {
/// prefix_path is used to add package paths. It should be the the same path used to include this build file /// prefix_path is used to add package paths. It should be the the same path used to include this build file
pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.build.Target, lib_type: LibType, comptime prefix_path: []const u8) void { pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.build.Target, lib_type: LibType, comptime prefix_path: []const u8) void {
const build_mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
switch (lib_type) { switch (lib_type) {
.static => { .static => {
const lib = b.addStaticLibrary("ecs", "ecs.zig"); const lib = b.addStaticLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
lib.setBuildMode(build_mode);
lib.install(); lib.install();
artifact.linkLibrary(lib); artifact.linkLibrary(lib);
}, },
.dynamic => { .dynamic => {
const lib = b.addSharedLibrary("ecs", "ecs.zig", .unversioned); const lib = b.addSharedLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
lib.setBuildMode(build_mode);
lib.install(); lib.install();
artifact.linkLibrary(lib); artifact.linkLibrary(lib);
@ -89,5 +97,5 @@ pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.buil
else => {}, else => {},
} }
artifact.addPackage(getPackage(prefix_path)); artifact.addModule(getModule(prefix_path));
} }

@ -86,7 +86,7 @@ pub const OwningGroup = struct {
var component_ptrs: [component_info.fields.len][*]u8 = undefined; var component_ptrs: [component_info.fields.len][*]u8 = undefined;
inline for (component_info.fields) |field, i| { inline for (component_info.fields) |field, i| {
const storage = group.registry.assure(@typeInfo(field.field_type).Pointer.child); const storage = group.registry.assure(@typeInfo(field.type).Pointer.child);
component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr); component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr);
} }
@ -105,7 +105,7 @@ pub const OwningGroup = struct {
// fill and return the struct // fill and return the struct
var comps: Components = undefined; var comps: Components = undefined;
inline for (@typeInfo(Components).Struct.fields) |field, i| { inline for (@typeInfo(Components).Struct.fields) |field, i| {
const typed_ptr = @ptrCast([*]@typeInfo(field.field_type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.field_type).Pointer.child), it.component_ptrs[i])); const typed_ptr = @ptrCast([*]@typeInfo(field.type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.type).Pointer.child), it.component_ptrs[i]));
@field(comps, field.name) = &typed_ptr[it.index]; @field(comps, field.name) = &typed_ptr[it.index];
} }
return comps; return comps;
@ -161,8 +161,8 @@ pub const OwningGroup = struct {
std.debug.assert(@typeInfo(Components) == .Struct); std.debug.assert(@typeInfo(Components) == .Struct);
inline for (@typeInfo(Components).Struct.fields) |field| { inline for (@typeInfo(Components).Struct.fields) |field| {
std.debug.assert(@typeInfo(field.field_type) == .Pointer); std.debug.assert(@typeInfo(field.type) == .Pointer);
const found = std.mem.indexOfScalar(u32, self.group_data.owned, utils.typeId(std.meta.Child(field.field_type))); const found = std.mem.indexOfScalar(u32, self.group_data.owned, utils.typeId(std.meta.Child(field.type)));
std.debug.assert(found != null); std.debug.assert(found != null);
} }
} }
@ -174,7 +174,7 @@ pub const OwningGroup = struct {
var component_ptrs: [component_info.fields.len][*]u8 = undefined; var component_ptrs: [component_info.fields.len][*]u8 = undefined;
inline for (component_info.fields) |field, i| { inline for (component_info.fields) |field, i| {
const storage = self.registry.assure(std.meta.Child(field.field_type)); const storage = self.registry.assure(std.meta.Child(field.type));
component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr); component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr);
} }
@ -182,7 +182,7 @@ pub const OwningGroup = struct {
const index = self.firstOwnedStorage().set.index(entity); const index = self.firstOwnedStorage().set.index(entity);
var comps: Components = undefined; var comps: Components = undefined;
inline for (component_info.fields) |field, i| { inline for (component_info.fields) |field, i| {
const typed_ptr = @ptrCast([*]std.meta.Child(field.field_type), @alignCast(@alignOf(std.meta.Child(field.field_type)), component_ptrs[i])); const typed_ptr = @ptrCast([*]std.meta.Child(field.type), @alignCast(@alignOf(std.meta.Child(field.type)), component_ptrs[i]));
@field(comps, field.name) = &typed_ptr[index]; @field(comps, field.name) = &typed_ptr[index];
} }
@ -200,7 +200,7 @@ pub const OwningGroup = struct {
// optionally we could just use an Iterator here and pay for some slight indirection for code sharing // optionally we could just use an Iterator here and pay for some slight indirection for code sharing
var iter = self.iterator(Components); var iter = self.iterator(Components);
while (iter.next()) |comps| { while (iter.next()) |comps| {
@call(.{ .modifier = .always_inline }, func, .{comps}); @call(.always_inline, func, .{comps});
} }
} }

@ -59,7 +59,7 @@ pub fn Cache(comptime T: type) type {
pub fn remove(self: *@This(), id: u32) void { pub fn remove(self: *@This(), id: u32) void {
if (self.resources.fetchRemove(id)) |kv| { if (self.resources.fetchRemove(id)) |kv| {
if (@hasDecl(T, "deinit")) { if (@hasDecl(T, "deinit")) {
@call(.{ .modifier = .always_inline }, @field(kv.value, "deinit"), .{}); @call(.always_inline, @field(kv.value, "deinit"), .{});
} }
} }
} }
@ -69,7 +69,7 @@ pub fn Cache(comptime T: type) type {
if (@hasDecl(T, "deinit")) { if (@hasDecl(T, "deinit")) {
var iter = self.resources.iterator(); var iter = self.resources.iterator();
while (iter.next()) |kv| { while (iter.next()) |kv| {
@call(.{ .modifier = .always_inline }, @field(kv.value_ptr.*, "deinit"), .{}); @call(.always_inline, @field(kv.value_ptr.*, "deinit"), .{});
} }
} }
self.resources.clearAndFree(); self.resources.clearAndFree();

@ -22,7 +22,7 @@ pub fn Delegate(comptime Event: type) type {
.callback = .{ .callback = .{
.bound = struct { .bound = struct {
fn cb(self: usize, param: Event) void { fn cb(self: usize, param: Event) void {
@call(.{ .modifier = .always_inline }, @field(@intToPtr(T, self), fn_name), .{param}); @call(.always_inline, @field(@intToPtr(T, self), fn_name), .{param});
} }
}.cb, }.cb,
}, },
@ -38,8 +38,8 @@ pub fn Delegate(comptime Event: type) type {
pub fn trigger(self: Self, param: Event) void { pub fn trigger(self: Self, param: Event) void {
switch (self.callback) { switch (self.callback) {
.free => |func| @call(.{}, func, .{param}), .free => |func| @call(.auto, func, .{param}),
.bound => |func| @call(.{}, func, .{ self.ctx_ptr_address, param }), .bound => |func| @call(.auto, func, .{ self.ctx_ptr_address, param }),
} }
} }

Loading…
Cancel
Save