Skip to content

Commit a108639

Browse files
committed
[Breaking] Upgrade to Zig 0.15.1
1 parent 73e6415 commit a108639

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

build.zig

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@ pub fn build(b: *std.Build) void {
44
const optimize = b.standardOptimizeOption(.{});
55
const target = b.standardTargetOptions(.{});
66

7-
_ = b.addModule("root", .{
7+
const module = b.addModule("root", .{
88
.root_source_file = b.path("src/zbullet.zig"),
9-
});
10-
11-
const cbullet = b.addStaticLibrary(.{
12-
.name = "cbullet",
139
.target = target,
1410
.optimize = optimize,
1511
});
16-
b.installArtifact(cbullet);
17-
18-
cbullet.addIncludePath(b.path("libs/cbullet"));
19-
cbullet.addIncludePath(b.path("libs/bullet"));
20-
cbullet.linkLibC();
21-
cbullet.linkLibCpp();
2212

2313
// TODO: Use the old damping method for now otherwise there is a hang in powf().
2414
const flags = &.{
@@ -27,7 +17,7 @@ pub fn build(b: *std.Build) void {
2717
"-std=c++11",
2818
"-fno-sanitize=undefined",
2919
};
30-
cbullet.addCSourceFiles(.{
20+
module.addCSourceFiles(.{
3121
.files = &.{
3222
"libs/cbullet/cbullet.cpp",
3323
"libs/bullet/btLinearMathAll.cpp",
@@ -36,22 +26,29 @@ pub fn build(b: *std.Build) void {
3626
},
3727
.flags = flags,
3828
});
29+
module.addIncludePath(b.path("libs/cbullet"));
30+
module.addIncludePath(b.path("libs/bullet"));
31+
32+
const cbullet_lib = b.addLibrary(.{
33+
.name = "cbullet",
34+
.root_module = module,
35+
});
36+
b.installArtifact(cbullet_lib);
37+
38+
cbullet_lib.linkLibC();
39+
cbullet_lib.linkLibCpp();
3940

4041
const test_step = b.step("test", "Run zbullet tests");
4142

4243
const zmath = b.dependency("zmath", .{});
4344

4445
var tests = b.addTest(.{
4546
.name = "zbullet-tests",
46-
.root_source_file = b.path("src/zbullet.zig"),
47-
.target = target,
48-
.optimize = optimize,
47+
.root_module = module,
4948
});
5049
b.installArtifact(tests);
5150

5251
tests.root_module.addImport("zmath", zmath.module("root"));
5352

54-
tests.linkLibrary(cbullet);
55-
5653
test_step.dependOn(&b.addRunArtifact(tests).step);
5754
}

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .zbullet,
33
.fingerprint = 0xdea5c1cd8f1709ee, // Changing this has security and trust implications.
44
.version = "0.4.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",
@@ -13,8 +13,8 @@
1313
.dependencies = .{
1414
// Used by tests
1515
.zmath = .{
16-
.url = "git+https://github.com/zig-gamedev/zmath#ccf7297ef6c01e21b2d51ad81b5b6ce929e86a00",
17-
.hash = "zmath-0.11.0-dev-wjwivZY1AwDO7yxNmZ5HWoU03f9mFBet8LN9-oYc3i29",
16+
.url = "https://github.com/zig-gamedev/zmath/archive/3a5955b2b72cd081563fbb084eff05bffd1e3fbb.tar.gz",
17+
.hash = "zmath-0.11.0-dev-wjwivdMsAwD-xaLj76YHUq3t9JDH-X16xuMTmnDzqbu2",
1818
},
1919
},
2020
}

src/zbullet.zig

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub const Body = *align(@sizeOf(usize)) BodyImpl;
1818
pub const Constraint = *align(@sizeOf(usize)) ConstraintImpl;
1919
pub const Point2PointConstraint = *align(@sizeOf(usize)) Point2PointConstraintImpl;
2020

21-
pub const AllocFn = *const fn (size: usize, alignment: i32) callconv(.C) ?*anyopaque;
22-
pub const FreeFn = *const fn (ptr: ?*anyopaque) callconv(.C) void;
21+
pub const AllocFn = *const fn (size: usize, alignment: i32) callconv(.c) ?*anyopaque;
22+
pub const FreeFn = *const fn (ptr: ?*anyopaque) callconv(.c) void;
2323

2424
extern fn cbtAlignedAllocSetCustomAligned(
2525
alloc: ?AllocFn,
@@ -34,7 +34,7 @@ var mem_allocator: ?std.mem.Allocator = null;
3434
var mem_allocations: ?std.AutoHashMap(usize, SizeAndAlignment) = null;
3535
var mem_mutex: std.Thread.Mutex = .{};
3636

37-
export fn zbulletAlloc(size: usize, alignment: i32) callconv(.C) ?*anyopaque {
37+
export fn zbulletAlloc(size: usize, alignment: i32) callconv(.c) ?*anyopaque {
3838
mem_mutex.lock();
3939
defer mem_mutex.unlock();
4040

@@ -53,7 +53,7 @@ export fn zbulletAlloc(size: usize, alignment: i32) callconv(.C) ?*anyopaque {
5353
return ptr;
5454
}
5555

56-
export fn zbulletFree(maybe_ptr: ?*anyopaque) callconv(.C) void {
56+
export fn zbulletFree(maybe_ptr: ?*anyopaque) callconv(.c) void {
5757
if (maybe_ptr) |ptr| {
5858
mem_mutex.lock();
5959
defer mem_mutex.unlock();
@@ -1156,23 +1156,23 @@ pub const DebugDraw = extern struct {
11561156
*const [3]f32,
11571157
*const [3]f32,
11581158
*const [3]f32,
1159-
) callconv(.C) void;
1159+
) callconv(.c) void;
11601160

11611161
const DrawLine2Fn = *const fn (
11621162
?*anyopaque,
11631163
*const [3]f32,
11641164
*const [3]f32,
11651165
*const [3]f32,
11661166
*const [3]f32,
1167-
) callconv(.C) void;
1167+
) callconv(.c) void;
11681168

11691169
const DrawContactPointFn = *const fn (
11701170
?*anyopaque,
11711171
*const [3]f32,
11721172
*const [3]f32,
11731173
f32,
11741174
*const [3]f32,
1175-
) callconv(.C) void;
1175+
) callconv(.c) void;
11761176

11771177
drawLine1: DrawLine1Fn,
11781178
drawLine2: ?DrawLine2Fn,
@@ -1188,12 +1188,12 @@ pub const DebugDrawer = struct {
11881188
color: u32,
11891189
};
11901190

1191-
pub fn init(alloc: std.mem.Allocator) DebugDrawer {
1192-
return .{ .lines = std.ArrayList(Vertex).init(alloc) };
1191+
pub fn init() DebugDrawer {
1192+
return .{ .lines = std.ArrayList(Vertex){} };
11931193
}
11941194

11951195
pub fn deinit(debug: *DebugDrawer) void {
1196-
debug.lines.deinit();
1196+
debug.lines.deinit(mem_allocator.?);
11971197
debug.* = undefined;
11981198
}
11991199

@@ -1211,7 +1211,7 @@ pub const DebugDrawer = struct {
12111211
p0: *const [3]f32,
12121212
p1: *const [3]f32,
12131213
color: *const [3]f32,
1214-
) callconv(.C) void {
1214+
) callconv(.c) void {
12151215
const debug = @as(
12161216
*DebugDrawer,
12171217
@ptrCast(@alignCast(context.?)),
@@ -1223,9 +1223,11 @@ pub const DebugDrawer = struct {
12231223
const rgb = r | g | b;
12241224

12251225
debug.lines.append(
1226+
mem_allocator.?,
12261227
.{ .position = .{ p0[0], p0[1], p0[2] }, .color = rgb },
12271228
) catch unreachable;
12281229
debug.lines.append(
1230+
mem_allocator.?,
12291231
.{ .position = .{ p1[0], p1[1], p1[2] }, .color = rgb },
12301232
) catch unreachable;
12311233
}
@@ -1236,7 +1238,7 @@ pub const DebugDrawer = struct {
12361238
p1: *const [3]f32,
12371239
color0: *const [3]f32,
12381240
color1: *const [3]f32,
1239-
) callconv(.C) void {
1241+
) callconv(.c) void {
12401242
const debug = @as(
12411243
*DebugDrawer,
12421244
@ptrCast(@alignCast(context.?)),
@@ -1253,9 +1255,11 @@ pub const DebugDrawer = struct {
12531255
const rgb1 = r1 | g1 | b1;
12541256

12551257
debug.lines.append(
1258+
mem_allocator.?,
12561259
.{ .position = .{ p0[0], p0[1], p0[2] }, .color = rgb0 },
12571260
) catch unreachable;
12581261
debug.lines.append(
1262+
mem_allocator.?,
12591263
.{ .position = .{ p1[0], p1[1], p1[2] }, .color = rgb1 },
12601264
) catch unreachable;
12611265
}

0 commit comments

Comments
 (0)