Merge pull request #8 from ryleelyman/main
Build.zig tweaks, zig breakage fixes
This commit is contained in:
commit
9e2174ed9b
6 changed files with 30 additions and 14 deletions
10
build.zig
10
build.zig
|
@ -3,8 +3,16 @@ const std = @import("std");
|
|||
pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const add_paths = b.option(bool, "add-paths", "add macos SDK paths from dependency") orelse false;
|
||||
|
||||
_ = b.addModule("objc", .{ .root_source_file = .{ .path = "src/main.zig" } });
|
||||
const objc = b.addModule("objc", .{
|
||||
.root_source_file = .{ .path = "src/main.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
if (add_paths) @import("macos_sdk").addPathsModule(objc);
|
||||
objc.linkSystemLibrary("objc", .{});
|
||||
objc.linkFramework("Foundation", .{});
|
||||
|
||||
const tests = b.addTest(.{
|
||||
.name = "objc-test",
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
},
|
||||
.dependencies = .{
|
||||
.macos_sdk = .{
|
||||
.url = "https://github.com/mitchellh/zig-build-macos-sdk/archive/4186e9fd445d12041651abe59ea5f396499b0844.tar.gz",
|
||||
.hash = "1220bc2612b57b0cfaaecbcac38e3144e5a9362ff668d71eb8334e895047bdbb7148",
|
||||
.url = "https://github.com/mitchellh/zig-build-macos-sdk/archive/ee70f27c08680307fa35ada92e6b2c36e0ff84c6.tar.gz",
|
||||
.hash = "1220b415f529f1c04ed876c2b481e9f8119d353d4e3d4d7c8607ee302d2142e13eca",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
6
flake.lock
generated
6
flake.lock
generated
|
@ -109,11 +109,11 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1711585351,
|
||||
"narHash": "sha256-rVJ/lRPQNCjU/98SZmQUhksoZOrKajwGS1UmEMuXzss=",
|
||||
"lastModified": 1712923708,
|
||||
"narHash": "sha256-gx0nOU67FBJ6S4S2VtnahhSHW9CW8zsYzE616/NV4eo=",
|
||||
"owner": "mitchellh",
|
||||
"repo": "zig-overlay",
|
||||
"rev": "6ac62029cf9a5fd2cec831a2dfc541f3cae63297",
|
||||
"rev": "c4412eedbfed081eefd5120c85e7910a953ae818",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn Block(
|
|||
.size = @sizeOf(Context),
|
||||
.copy_helper = &descCopyHelper,
|
||||
.dispose_helper = &descDisposeHelper,
|
||||
.signature = objc.comptimeEncode(InvokeFn).ptr,
|
||||
.signature = &objc.comptimeEncode(InvokeFn),
|
||||
};
|
||||
|
||||
/// This is the function type that is called back.
|
||||
|
|
|
@ -76,7 +76,7 @@ pub const Class = struct {
|
|||
self.value,
|
||||
objc.sel(name).value,
|
||||
@ptrCast(&imp),
|
||||
encoding.ptr,
|
||||
&encoding,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,22 +4,30 @@ const c = @import("c.zig");
|
|||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
||||
/// Encode a type into a comptime string.
|
||||
pub fn comptimeEncode(comptime T: type) [:0]const u8 {
|
||||
/// how much space do we need to encode this type?
|
||||
fn comptimeN(comptime T: type) usize {
|
||||
comptime {
|
||||
const encoding = objc.Encoding.init(T);
|
||||
|
||||
// Figure out how much space we need
|
||||
var counting = std.io.countingWriter(std.io.null_writer);
|
||||
try std.fmt.format(counting.writer(), "{}", .{encoding});
|
||||
return counting.bytes_written;
|
||||
}
|
||||
}
|
||||
|
||||
/// Encode a type into a comptime string.
|
||||
pub fn comptimeEncode(comptime T: type) [comptimeN(T):0]u8 {
|
||||
comptime {
|
||||
const encoding = objc.Encoding.init(T);
|
||||
|
||||
// Build our final signature
|
||||
var buf: [counting.bytes_written + 1]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(buf[0..counting.bytes_written]);
|
||||
var buf: [comptimeN(T) + 1]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(buf[0 .. buf.len - 1]);
|
||||
try std.fmt.format(fbs.writer(), "{}", .{encoding});
|
||||
buf[counting.bytes_written] = 0;
|
||||
buf[buf.len - 1] = 0;
|
||||
|
||||
return buf[0..counting.bytes_written :0];
|
||||
return buf[0 .. buf.len - 1 :0].*;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue