Obsolete
/
libipc-old
Archived
3
0
Fork 0

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 bin_dir = "bin";
const build_dir = "build";
const VERSION = "0.1.5";
pub fn build(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
// const mode = b.standardReleaseOptions();
// const mode = std.builtin.Mode.Debug;
const mode = std.builtin.Mode.ReleaseSmall;
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// 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");
ipcd_exe.addPackagePath("ipc", "./src/ipc.zig");
ipcd_exe.setOutputDir(bin_dir);
ipcd_exe.linkLibC();
ipcd_exe.setBuildMode(mode);
ipcd_exe.install();
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const tcpd_exe = b.addExecutable("tcpd", "apps/tcpd.zig");
tcpd_exe.addPackagePath("ipc", "./src/ipc.zig");
tcpd_exe.setOutputDir(bin_dir);
tcpd_exe.linkLibC();
tcpd_exe.setBuildMode(mode);
tcpd_exe.install();
const lib = b.addStaticLibrary(.{
.name = "ipc",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/bindings.zig" },
.target = target,
.optimize = optimize,
});
const pong_exe = b.addExecutable("pong", "apps/pong.zig");
pong_exe.addPackagePath("ipc", "./src/ipc.zig");
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);
// Link with the libc of the target system since the C allocator
// is required in the bindings.
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();
const solib = b.addSharedLibrary("ipc", "src/bindings.zig", b.version(0, 1, 0));
solib.setOutputDir(build_dir);
const solib = b.addSharedLibrary(.{
.name = "ipc",
.root_source_file = .{ .path = "src/bindings.zig" },
.version = comptime (try std.builtin.Version.parse(VERSION)),
.target = target,
.optimize = optimize,
});
solib.linkLibC();
solib.setBuildMode(mode);
solib.install();
const main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
// Creates a step for unit testing.
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");
test_step.dependOn(&main_tests.step);
}

View File

@ -1,6 +1,6 @@
const std = @import("std");
const log = std.log.scoped(.libipc_bindings);
const ipc = @import("./ipc.zig");
const ipc = @import("./main.zig");
const Context = ipc.Context;
const Message = ipc.Message;
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 SwitchDB = @import("./switch.zig").SwitchDB;
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);

View File

@ -120,7 +120,7 @@ pub fn recvmsg(
) SendMsgError!usize {
while (true) {
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 (rc == windows.ws2_32.SOCKET_ERROR) {
switch (windows.ws2_32.WSAGetLastError()) {

View File

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