Zig implementation: update to current zig API.

master
Philippe Pittoli 2023-02-05 09:34:36 +01:00
parent f0e41455be
commit 1479d4e243
6 changed files with 48 additions and 47 deletions

View File

@ -1,59 +1,60 @@
const std = @import("std"); const std = @import("std");
const bin_dir = "bin"; const VERSION = "0.1.5";
const build_dir = "build";
pub fn build(b: *std.build.Builder) void { // Although this function looks imperative, note that its job is to
// Standard release options allow the person running `zig build` to select // declaratively construct a build graph that will be executed by an external
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. // runner.
// const mode = b.standardReleaseOptions(); pub fn build(b: *std.Build) void {
// const mode = std.builtin.Mode.Debug; // Standard target options allows the person running `zig build` to choose
const mode = std.builtin.Mode.ReleaseSmall; // what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
const ipcd_exe = b.addExecutable("ipcd", "apps/ipcd.zig"); // Standard optimization options allow the person running `zig build` to select
ipcd_exe.addPackagePath("ipc", "./src/ipc.zig"); // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
ipcd_exe.setOutputDir(bin_dir); // set a preferred release mode, allowing the user to decide how to optimize.
ipcd_exe.linkLibC(); const optimize = b.standardOptimizeOption(.{});
ipcd_exe.setBuildMode(mode);
ipcd_exe.install();
const tcpd_exe = b.addExecutable("tcpd", "apps/tcpd.zig"); const lib = b.addStaticLibrary(.{
tcpd_exe.addPackagePath("ipc", "./src/ipc.zig"); .name = "ipc",
tcpd_exe.setOutputDir(bin_dir); // In this case the main source file is merely a path, however, in more
tcpd_exe.linkLibC(); // complicated build scripts, this could be a generated file.
tcpd_exe.setBuildMode(mode); .root_source_file = .{ .path = "src/bindings.zig" },
tcpd_exe.install(); .target = target,
.optimize = optimize,
});
const pong_exe = b.addExecutable("pong", "apps/pong.zig"); // Link with the libc of the target system since the C allocator
pong_exe.addPackagePath("ipc", "./src/ipc.zig"); // is required in the bindings.
pong_exe.setOutputDir(bin_dir);
pong_exe.linkLibC();
pong_exe.setBuildMode(mode);
pong_exe.install();
const pongd_exe = b.addExecutable("pongd", "apps/pongd.zig");
pongd_exe.addPackagePath("ipc", "./src/ipc.zig");
pongd_exe.setOutputDir(bin_dir);
pongd_exe.linkLibC();
pongd_exe.setBuildMode(mode);
pongd_exe.install();
const lib = b.addStaticLibrary("ipc", "src/bindings.zig");
lib.setOutputDir(build_dir);
lib.linkLibC(); lib.linkLibC();
lib.setBuildMode(mode);
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
lib.install(); lib.install();
const solib = b.addSharedLibrary("ipc", "src/bindings.zig", b.version(0, 1, 0)); const solib = b.addSharedLibrary(.{
solib.setOutputDir(build_dir); .name = "ipc",
.root_source_file = .{ .path = "src/bindings.zig" },
.version = comptime (try std.builtin.Version.parse(VERSION)),
.target = target,
.optimize = optimize,
});
solib.linkLibC(); solib.linkLibC();
solib.setBuildMode(mode);
solib.install(); solib.install();
const main_tests = b.addTest("src/main.zig"); // Creates a step for unit testing.
main_tests.setBuildMode(mode); const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step); test_step.dependOn(&main_tests.step);
} }

View File

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
const log = std.log.scoped(.libipc_bindings); const log = std.log.scoped(.libipc_bindings);
const ipc = @import("./ipc.zig"); const ipc = @import("./main.zig");
const Context = ipc.Context; const Context = ipc.Context;
const Message = ipc.Message; const Message = ipc.Message;
const CBEventType = ipc.CBEvent.Type; const CBEventType = ipc.CBEvent.Type;

View File

@ -20,7 +20,7 @@ const print_eq = @import("./util.zig").print_eq;
const Messages = @import("./message.zig").Messages; const Messages = @import("./message.zig").Messages;
const SwitchDB = @import("./switch.zig").SwitchDB; const SwitchDB = @import("./switch.zig").SwitchDB;
const Connections = @import("./connection.zig").Connections; const Connections = @import("./connection.zig").Connections;
const CBEventType = @import("./ipc.zig").CBEvent.Type; const CBEventType = @import("./main.zig").CBEvent.Type;
pub const PollFD = std.ArrayList(std.os.pollfd); pub const PollFD = std.ArrayList(std.os.pollfd);

View File

@ -120,7 +120,7 @@ pub fn recvmsg(
) SendMsgError!usize { ) SendMsgError!usize {
while (true) { while (true) {
var m = msg; var m = msg;
const rc = system.recvmsg(sockfd, @ptrCast(*std.x.os.Socket.Message, &m), @intCast(c_int, flags)); const rc = system.recvmsg(sockfd, @ptrCast(*std.os.msghdr, &m), @intCast(c_uint, flags));
if (builtin.os.tag == .windows) { if (builtin.os.tag == .windows) {
if (rc == windows.ws2_32.SOCKET_ERROR) { if (rc == windows.ws2_32.SOCKET_ERROR) {
switch (windows.ws2_32.WSAGetLastError()) { switch (windows.ws2_32.WSAGetLastError()) {

View File

@ -4,7 +4,7 @@ const fmt = std.fmt;
const net = std.net; const net = std.net;
const ipc = @import("./ipc.zig"); const ipc = @import("./main.zig");
const Message = ipc.Message; const Message = ipc.Message;
const CBEventType = ipc.CBEvent.Type; const CBEventType = ipc.CBEvent.Type;