Skip to content

Commit fdd58cb

Browse files
committed
port to 0.15
1 parent c5a3809 commit fdd58cb

7 files changed

Lines changed: 39 additions & 38 deletions

File tree

build.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ pub fn build(b: *std.Build) !void {
2020

2121
const tests = b.addTest(.{
2222
.name = "objc-test",
23-
.root_source_file = b.path("src/main.zig"),
24-
.target = target,
25-
.optimize = optimize,
23+
.root_module = b.createModule(.{
24+
.root_source_file = b.path("src/main.zig"),
25+
.target = target,
26+
.optimize = optimize,
27+
}),
2628
});
2729
tests.linkSystemLibrary("objc");
2830
tests.linkFramework("Foundation");
@@ -66,7 +68,7 @@ pub fn addAppleSDK(b: *std.Build, m: *std.Build.Module) !void {
6668
if (!gop.found_existing) {
6769
gop.value_ptr.* = std.zig.system.darwin.getSdk(
6870
b.allocator,
69-
m.resolved_target.?.result,
71+
&m.resolved_target.?.result,
7072
);
7173
}
7274

build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.name = .zig_objc,
33
.version = "0.0.0",
44
.fingerprint = 0x8a91772ba7d2bf22,
5+
.minimum_zig_version = "0.15.1",
56
.paths = .{
67
"src/",
78
"build.zig",

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
in rec {
3636
devShells.default = pkgs.mkShell {
3737
nativeBuildInputs = with pkgs; [
38-
zigpkgs."0.14.0"
38+
zigpkgs."0.15.1"
3939
];
4040
};
4141

src/block.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn Block(
120120
_Block_release(@ptrCast(@alignCast(ctx)));
121121
}
122122

123-
fn descCopyHelper(src: *anyopaque, dst: *anyopaque) callconv(.C) void {
123+
fn descCopyHelper(src: *anyopaque, dst: *anyopaque) callconv(.c) void {
124124
const real_src: *Context = @ptrCast(@alignCast(src));
125125
const real_dst: *Context = @ptrCast(@alignCast(dst));
126126
inline for (captures_info.fields) |field| {
@@ -134,7 +134,7 @@ pub fn Block(
134134
}
135135
}
136136

137-
fn descDisposeHelper(src: *anyopaque) callconv(.C) void {
137+
fn descDisposeHelper(src: *anyopaque) callconv(.c) void {
138138
const real_src: *Context = @ptrCast(@alignCast(src));
139139
inline for (captures_info.fields) |field| {
140140
if (field.type == objc.c.id) {
@@ -158,7 +158,7 @@ pub fn Block(
158158

159159
return @Type(.{
160160
.@"fn" = .{
161-
.calling_convention = .C,
161+
.calling_convention = .c,
162162
.is_generic = false,
163163
.is_var_args = false,
164164
.return_type = Return,
@@ -249,16 +249,16 @@ const BlockFieldFlags = enum(c_int) {
249249
byref_caller = 128, // BLOCK_BYREF_CALLER
250250
};
251251

252-
extern "C" fn _Block_copy(src: *const anyopaque) callconv(.c) ?*anyopaque;
253-
extern "C" fn _Block_release(src: *const anyopaque) callconv(.c) void;
254-
extern "C" fn _Block_object_assign(dst: *anyopaque, src: *const anyopaque, flag: BlockFieldFlags) void;
255-
extern "C" fn _Block_object_dispose(src: *const anyopaque, flag: BlockFieldFlags) void;
252+
extern "c" fn _Block_copy(src: *const anyopaque) callconv(.c) ?*anyopaque;
253+
extern "c" fn _Block_release(src: *const anyopaque) callconv(.c) void;
254+
extern "c" fn _Block_object_assign(dst: *anyopaque, src: *const anyopaque, flag: BlockFieldFlags) void;
255+
extern "c" fn _Block_object_dispose(src: *const anyopaque, flag: BlockFieldFlags) void;
256256

257257
const Descriptor = extern struct {
258258
reserved: c_ulong = 0,
259259
size: c_ulong,
260-
copy_helper: *const fn (dst: *anyopaque, src: *anyopaque) callconv(.C) void,
261-
dispose_helper: *const fn (src: *anyopaque) callconv(.C) void,
260+
copy_helper: *const fn (dst: *anyopaque, src: *anyopaque) callconv(.c) void,
261+
dispose_helper: *const fn (src: *anyopaque) callconv(.c) void,
262262
signature: ?[*:0]const u8,
263263
};
264264

@@ -287,7 +287,7 @@ test "Block" {
287287
};
288288

289289
var block: AddBlock.Context = AddBlock.init(captures, (struct {
290-
fn addFn(block: *const AddBlock.Context) callconv(.C) i32 {
290+
fn addFn(block: *const AddBlock.Context) callconv(.c) i32 {
291291
return block.x + block.y;
292292
}
293293
}).addFn);
@@ -317,7 +317,7 @@ test "Block copy objc id" {
317317
var block = TestBlock.init(.{
318318
.id = obj.value,
319319
}, (struct {
320-
fn addFn(block: *const TestBlock.Context) callconv(.C) i32 {
320+
fn addFn(block: *const TestBlock.Context) callconv(.c) i32 {
321321
_ = block;
322322
return 0;
323323
}

src/class.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ test "allocatecClassPair and replaceMethod" {
167167
const NSObject = getClass("NSObject").?;
168168
var my_object = allocateClassPair(NSObject, "my_object").?;
169169
my_object.replaceMethod("hash", struct {
170-
fn inner(target: c.id, sel: c.SEL) callconv(.C) u64 {
170+
fn inner(target: c.id, sel: c.SEL) callconv(.c) u64 {
171171
_ = sel;
172172
_ = target;
173173
return 69;
@@ -208,7 +208,7 @@ test "addMethod" {
208208
const My_Class = allocateClassPair(objc.getClass("NSObject").?, "my_class").?;
209209
defer registerClassPair(My_Class);
210210
std.debug.assert(My_Class.addMethod("my_addition", struct {
211-
fn imp(target: objc.c.id, sel: objc.c.SEL, a: i32, b: i32) callconv(.C) i32 {
211+
fn imp(target: objc.c.id, sel: objc.c.SEL, a: i32, b: i32) callconv(.c) i32 {
212212
_ = sel;
213213
_ = target;
214214
return a + b;

src/encoding.zig

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fn comptimeN(comptime T: type) usize {
1010
const encoding = objc.Encoding.init(T);
1111

1212
// Figure out how much space we need
13-
var counting = std.io.countingWriter(std.io.null_writer);
14-
try std.fmt.format(counting.writer(), "{}", .{encoding});
15-
return counting.bytes_written;
13+
var stream: std.io.Writer.Discarding = .init(&.{});
14+
stream.writer.print("{f}", .{encoding});
15+
return stream.count;
1616
}
1717
}
1818

@@ -23,8 +23,8 @@ pub fn comptimeEncode(comptime T: type) [comptimeN(T):0]u8 {
2323

2424
// Build our final signature
2525
var buf: [comptimeN(T) + 1]u8 = undefined;
26-
var fbs = std.io.fixedBufferStream(buf[0 .. buf.len - 1]);
27-
try std.fmt.format(fbs.writer(), "{}", .{encoding});
26+
var fbs: std.io.Writer = .fixed(buf[0 .. buf.len - 1]);
27+
fbs.writer.print("{f}", .{encoding});
2828
buf[buf.len - 1] = 0;
2929

3030
return buf[0 .. buf.len - 1 :0].*;
@@ -107,9 +107,7 @@ pub const Encoding = union(enum) {
107107

108108
pub fn format(
109109
comptime self: Encoding,
110-
comptime fmt: []const u8,
111-
options: std.fmt.FormatOptions,
112-
writer: anytype,
110+
writer: *std.io.Writer,
113111
) !void {
114112
switch (self) {
115113
.char => try writer.writeAll("c"),
@@ -133,7 +131,7 @@ pub const Encoding = union(enum) {
133131
.array => |a| {
134132
try writer.print("[{}", .{a.len});
135133
const encode_type = init(a.arr_type);
136-
try encode_type.format(fmt, options, writer);
134+
try encode_type.format(writer);
137135
try writer.writeAll("]");
138136
},
139137
.structure => |s| {
@@ -152,7 +150,7 @@ pub const Encoding = union(enum) {
152150
try writer.writeAll("=");
153151
inline for (struct_info.@"struct".fields) |field| {
154152
const field_encode = init(field.type);
155-
try field_encode.format(fmt, options, writer);
153+
try field_encode.format(writer);
156154
}
157155
}
158156

@@ -174,7 +172,7 @@ pub const Encoding = union(enum) {
174172
try writer.writeAll("=");
175173
inline for (union_info.@"union".fields) |field| {
176174
const field_encode = init(field.type);
177-
try field_encode.format(fmt, options, writer);
175+
try field_encode.format(writer);
178176
}
179177
}
180178

@@ -209,7 +207,7 @@ pub const Encoding = union(enum) {
209207
}
210208

211209
// call this format function again, this time with the child type encoding
212-
try encoding.format(fmt, options, writer);
210+
try encoding.format(writer);
213211
},
214212
else => @compileError("Pointer size not supported for encoding"),
215213
}
@@ -219,10 +217,10 @@ pub const Encoding = union(enum) {
219217

220218
// Return type is first in a method encoding
221219
const ret_type_enc = init(fn_info.return_type.?);
222-
try ret_type_enc.format(fmt, options, writer);
220+
try ret_type_enc.format(writer);
223221
inline for (fn_info.params) |param| {
224222
const param_enc = init(param.type.?);
225-
try param_enc.format(fmt, options, writer);
223+
try param_enc.format(writer);
226224
}
227225
},
228226
.unknown => {},
@@ -400,7 +398,7 @@ test "**Union to Encoding.union encoding" {
400398

401399
test "Fn to Encoding.function encoding" {
402400
const test_fn = struct {
403-
fn add(_: c.id, _: c.SEL, _: i8) callconv(.C) void {}
401+
fn add(_: c.id, _: c.SEL, _: i8) callconv(.c) void {}
404402
};
405403

406404
try encodingMatchesType(@TypeOf(test_fn.add), "v@:c");

src/msg_send.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn MsgSend(comptime T: type) type {
7878
fn msgSendPtr(
7979
comptime Return: type,
8080
comptime super: bool,
81-
) *const fn () callconv(.C) void {
81+
) *const fn () callconv(.c) void {
8282
// See objc/message.h. The high-level is that depending on the
8383
// target architecture and return type, we must use a different
8484
// objc_msgSend function.
@@ -204,7 +204,7 @@ fn MsgSendFn(
204204

205205
return @Type(.{
206206
.@"fn" = .{
207-
.calling_convention = .C,
207+
.calling_convention = .c,
208208
.is_generic = false,
209209
.is_var_args = false,
210210
.return_type = Return,
@@ -218,8 +218,8 @@ test {
218218
try testing.expectEqual(fn (
219219
c.id,
220220
c.SEL,
221-
) callconv(.C) u64, MsgSendFn(u64, c.id, @TypeOf(.{})));
222-
try testing.expectEqual(fn (c.id, c.SEL, u16, u32) callconv(.C) u64, MsgSendFn(u64, c.id, @TypeOf(.{
221+
) callconv(.c) u64, MsgSendFn(u64, c.id, @TypeOf(.{})));
222+
try testing.expectEqual(fn (c.id, c.SEL, u16, u32) callconv(.c) u64, MsgSendFn(u64, c.id, @TypeOf(.{
223223
@as(u16, 0),
224224
@as(u32, 0),
225225
})));
@@ -229,7 +229,7 @@ test "subClass" {
229229
const Subclass = objc.allocateClassPair(objc.getClass("NSObject").?, "subclass").?;
230230
defer objc.disposeClassPair(Subclass);
231231
const str = struct {
232-
fn inner(target: objc.c.id, sel: objc.c.SEL) callconv(.C) objc.c.id {
232+
fn inner(target: objc.c.id, sel: objc.c.SEL) callconv(.c) objc.c.id {
233233
_ = sel;
234234
const self = objc.Object.fromId(target);
235235
self.msgSendSuper(objc.getClass("NSObject").?, void, "init", .{});

0 commit comments

Comments
 (0)