commit d286a5afddca3280cdc00c94d9d2e710e8ea924d Author: Kaitlyn~Ethylia Date: Tue Jun 10 23:24:32 2025 +0100 Initial Commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f23a044 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = tab +indent_size = 4 +max_line_length = 90 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e25cd9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/.zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..8e9f6df --- /dev/null +++ b/build.zig @@ -0,0 +1,27 @@ +const std = @import("std"); + +const client_b = @import("client/build.zig"); +const common_b = @import("common/build.zig"); +const server_b = @import("server/build.zig"); + +pub fn build(b: *std.Build) void { + const Modules = enum { Client, Server, Both }; + const modules = b.option(Modules, "modules", "Choose whether to build the client, the server, or both.") orelse .Both; + + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const common = common_b.build(b, target, optimize); + + if (modules != Modules.Server) { + const client = client_b.build(b, target, optimize); + client.root_module.addImport("common", common.root_module); + b.installArtifact(client); + } + + if (modules != Modules.Client) { + const server = server_b.build(b, target, optimize); + server.root_module.addImport("common", common.root_module); + b.installArtifact(server); + } +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..2adaec9 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,20 @@ +.{ + .name = .chat, + .version = "0.0.1", + .fingerprint = 0x659df2aa32a4b33f, // Changing this has security and trust implications. + .minimum_zig_version = "0.14.1", + .dependencies = .{ + .libqt6zig = .{ + .url = "git+https://github.com/rcalixte/libqt6zig#8d1561a2a1e34f6818e4afdb6028ddfe1dcee4d4", + .hash = "libqt6zig-6.4.2-OSXtXCItfQgnNBvZOhUDSl9QEqLIsmpGn2vf5ZjBFDdw", + .lazy = true, + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "client", + "common", + "server", + }, +} diff --git a/client/build.zig b/client/build.zig new file mode 100644 index 0000000..a17aa58 --- /dev/null +++ b/client/build.zig @@ -0,0 +1,43 @@ +const std = @import("std"); + +pub fn build( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, +) *std.Build.Step.Compile { + const qt6zig_ = b.lazyDependency("libqt6zig", .{ + .target = target, + .optimize = .ReleaseFast, + }); + + const mod = b.createModule(.{ + .root_source_file = b.path("client/src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const step = b.addExecutable(.{ + .name = "chat.client", + .root_module = mod, + }); + + if (qt6zig_) |qt6zig| { + step.root_module.addImport("libqt6zig", qt6zig.module("libqt6zig")); + step.root_module.linkLibrary(qt6zig.artifact("qapplication")); + step.root_module.linkLibrary(qt6zig.artifact("qwidget")); + step.root_module.linkSystemLibrary("Qt6Core", .{}); + step.root_module.linkSystemLibrary("Qt6Gui", .{}); + step.root_module.linkSystemLibrary("Qt6Widgets", .{}); + } + + const cmd = b.addRunArtifact(step); + cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + cmd.addArgs(args); + } + + const run = b.step("run-client", "Run the chat client"); + run.dependOn(&cmd.step); + + return step; +} diff --git a/client/src/main.zig b/client/src/main.zig new file mode 100644 index 0000000..6e0a9ab --- /dev/null +++ b/client/src/main.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +const common = @import("common"); + +pub fn main() void { + common.print_test("client"); +} diff --git a/common/build.zig b/common/build.zig new file mode 100644 index 0000000..3006ced --- /dev/null +++ b/common/build.zig @@ -0,0 +1,21 @@ +const std = @import("std"); + +pub fn build( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, +) *std.Build.Step.Compile { + const mod = b.createModule(.{ + .root_source_file = b.path("common/src/root.zig"), + .target = target, + .optimize = optimize, + }); + + const step = b.addLibrary(.{ + .linkage = .static, + .name = "chat.common", + .root_module = mod, + }); + + return step; +} diff --git a/common/src/root.zig b/common/src/root.zig new file mode 100644 index 0000000..cb40f7e --- /dev/null +++ b/common/src/root.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn print_test(sender: []const u8) void { + std.log.debug("Message from {s}", .{ sender }); +} diff --git a/server/build.zig b/server/build.zig new file mode 100644 index 0000000..d769e00 --- /dev/null +++ b/server/build.zig @@ -0,0 +1,29 @@ +const std = @import("std"); + +pub fn build( + b: *std.Build, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, +) *std.Build.Step.Compile { + const mod = b.createModule(.{ + .root_source_file = b.path("server/src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const step = b.addExecutable(.{ + .name = "chat.server", + .root_module = mod, + }); + + const cmd = b.addRunArtifact(step); + cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + cmd.addArgs(args); + } + + const run = b.step("run-server", "Run the chat server"); + run.dependOn(&cmd.step); + + return step; +} diff --git a/server/src/main.zig b/server/src/main.zig new file mode 100644 index 0000000..1ec9400 --- /dev/null +++ b/server/src/main.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +const common = @import("common"); + +pub fn main() void { + common.print_test("server"); +}