This commit is contained in:
Philippe PITTOLI 2024-06-14 16:20:37 +02:00
parent 2a8b4a198f
commit ed9f719fa9
3 changed files with 67 additions and 40 deletions

View File

@ -15,6 +15,12 @@ build: $(BINS)
$(BINS):
$(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS)
run-pong:
$(VALGRIND) ./pong
run-pongd:
$(VALGRIND) ./pongd
clean:
rm $(BINS) 2>/dev/null

View File

@ -1,16 +1,17 @@
const std = @import("std");
const module = std.Build.Module;
fn link_and_install(exe : *std.Build.CompileStep) void {
const source_file = std.Build.FileSource.relative("./lib/ipc/src/main.zig");
// var empty : []const std.Build.ModuleDependency = &.{};
exe.addAnonymousModule("ipc", .{ .source_file = source_file, .dependencies = &.{} });
exe.linkLibC();
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
exe.install();
}
//fn link_and_install(exe : *std.Build.CompileStep) void {
// const source_file = std.Build.FileSource.relative("./lib/ipc/src/main.zig");
// // var empty : []const std.Build.ModuleDependency = &.{};
// exe.addModule("ipc", .{ .source_file = source_file, .dependencies = &.{} });
// exe.linkLibC();
//
// // This declares intent for the executable to be installed into the
// // standard location when the user invokes the "install" step (the default
// // step when running `zig build`).
// exe.install();
//}
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
@ -27,43 +28,63 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const ipc_static_lib = b.addStaticLibrary(.{
.name = "ipc",
.optimize = optimize,
.target = target,
.root_source_file = b.path("./lib/ipc/src/main.zig")
});
// const ipc_module = b.dependency("ipc", .{}).module("ipc");
// ipc_module.linkSystemLibrary("ipc", .{ .needed = true });
const ipcd_exe = b.addExecutable(.{
.name = "ipcd",
.root_source_file = .{ .path = "src/ipcd.zig" },
.target = target,
.optimize = optimize,
});
link_and_install(ipcd_exe);
const tcpd_exe = b.addExecutable(.{
.name = "tcpd",
.root_source_file = .{ .path = "src/tcpd.zig" },
.target = target,
.optimize = optimize,
});
link_and_install(tcpd_exe);
const pong_exe = b.addExecutable(.{
.name = "pong",
.root_source_file = .{ .path = "src/pong.zig" },
.target = target,
.optimize = optimize,
});
link_and_install(pong_exe);
const pongd_exe = b.addExecutable(.{
.name = "pongd",
.root_source_file = .{ .path = "src/pongd.zig" },
.target = target,
.optimize = optimize,
});
link_and_install(pongd_exe);
ipcd_exe.linkLibrary(ipc_static_lib);
b.installArtifact(ipc_static_lib);
ipcd_exe.linkSystemLibrary("ipc");
ipcd_exe.linkLibC();
b.installArtifact(ipcd_exe);
//
// const tcpd_exe = b.addExecutable(.{
// .name = "tcpd",
// .root_source_file = .{ .path = "src/tcpd.zig" },
// .target = target,
// .optimize = optimize,
// });
// // tcpd_exe.addModule("ipc", module.CreateOptions);
// tcpd_exe.linkLibC();
// b.installArtifact(tcpd_exe);
//
// const pong_exe = b.addExecutable(.{
// .name = "pong",
// .root_source_file = .{ .path = "src/pong.zig" },
// .target = target,
// .optimize = optimize,
// });
// // pong_exe.addModule("ipc", module.CreateOptions);
// pong_exe.linkLibC();
// b.installArtifact(pong_exe);
//
// const pongd_exe = b.addExecutable(.{
// .name = "pongd",
// .root_source_file = .{ .path = "src/pongd.zig" },
// .target = target,
// .optimize = optimize,
// });
// // pongd_exe.addModule("ipc", module.CreateOptions);
// pongd_exe.linkLibC();
// b.installArtifact(pongd_exe);
const is_static = b.option(bool, "static", "Compile static binaries.") orelse false;
if (is_static) {
ipcd_exe.linkage = .static;
tcpd_exe.linkage = .static;
pong_exe.linkage = .static;
pongd_exe.linkage = .static;
// tcpd_exe.linkage = .static;
// pong_exe.linkage = .static;
// pongd_exe.linkage = .static;
}
}

@ -1 +0,0 @@
Subproject commit 64506bbee0d691b3a0c6d5d97894426c188bc3df

1
zig/lib/ipc Symbolic link
View File

@ -0,0 +1 @@
/tmp/prog/libipc