diff --git a/.gitignore b/.gitignore index 4c82b07..d8c8979 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -zig-cache +.zig-cache zig-out diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..802fa7d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "external/libxau.zig"] + path = external/libxau.zig + url = https://github.com/PaNDa2code/libxau_zig +[submodule "external/zig-clap"] + path = external/zig-clap + url = https://github.com/Hejsil/zig-clap diff --git a/build.zig b/build.zig index 6e578fc..73ec43c 100644 --- a/build.zig +++ b/build.zig @@ -1,227 +1,128 @@ const std = @import("std"); -const assert = std.debug.assert; +const Build = std.Build; pub const Protocol = @import("lib/xcb/protocol.zig"); -const LinkMode = if (@hasField(std.builtin.LinkMode, "static")) std.builtin.LinkMode else std.Build.Step.Compile.Linkage; - -fn runAllowFail( - self: *std.Build, - argv: []const []const u8, - cwd: []const u8, - out_code: *u8, - stderr_behavior: std.ChildProcess.StdIo, -) std.Build.RunError![]u8 { - assert(argv.len != 0); - - if (!std.process.can_spawn) - return error.ExecNotSupported; - - const max_output_size = 400 * 1024; - var child = std.ChildProcess.init(argv, self.allocator); - child.stdin_behavior = .Ignore; - child.stdout_behavior = .Pipe; - child.stderr_behavior = stderr_behavior; - child.env_map = &self.graph.env_map; - child.cwd = cwd; - - try child.spawn(); - - const stdout = child.stdout.?.reader().readAllAlloc(self.allocator, max_output_size) catch { - return error.ReadFailure; - }; - errdefer self.allocator.free(stdout); - - const term = try child.wait(); - switch (term) { - .Exited => |code| { - if (code != 0) { - out_code.* = @as(u8, @truncate(code)); - return error.ExitCodeFailure; - } - return stdout; - }, - .Signal, .Stopped, .Unknown => |code| { - out_code.* = @as(u8, @truncate(code)); - return error.ProcessTerminated; - }, - } -} - -fn run(b: *std.Build, argv: []const []const u8, cwd: []const u8) []u8 { - if (!std.process.can_spawn) { - std.debug.print("unable to spawn the following command: cannot spawn child process\n{s}\n", .{ - try std.Build.Step.allocPrintCmd(b.allocator, null, argv), - }); - std.process.exit(1); - } - - var code: u8 = undefined; - return runAllowFail(b, argv, cwd, &code, .Inherit) catch |err| { - const printed_cmd = std.Build.Step.allocPrintCmd(b.allocator, null, argv) catch @panic("OOM"); - std.debug.print("unable to spawn the following command: {s}\n{s}\n", .{ - @errorName(err), printed_cmd, - }); - std.process.exit(1); - }; -} - pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const no_docs = b.option(bool, "no-docs", "skip installing documentation") orelse false; - const linkage = b.option(LinkMode, "linkage", "whether to statically or dynamically link the library") orelse @as(LinkMode, if (target.result.isGnuLibC()) .dynamic else .static); - - const clap = b.dependency("clap", .{ - .target = target, - .optimize = optimize, - }); - - const libxcbSource = b.dependency("libxcb", .{}); - const xcbprotoSource = b.dependency("xcbproto", .{}); + // const no_docs = b.option(bool, "no-docs", "skip installing documentation") orelse false; + const linkage: std.builtin.LinkMode = + b.option(std.builtin.LinkMode, "linkage", "whether to statically or dynamically link the library") orelse + if (target.result.isGnuLibC()) + .dynamic + else + .static; + + // const clap = b.dependency("clap", .{ + // .target = target, + // .optimize = optimize, + // }); + + const libxcb_upstream = b.dependency("libxcb", .{}); + const xcbproto_upstream = b.dependency("xcbproto", .{}); const libxau = b.dependency("libxau", .{ .target = target, .optimize = optimize, .linkage = linkage, }); - const libxauSource = libxau.builder.dependency("libxau", .{}); - const xorgprotoSource = libxau.builder.dependency("xorgproto", .{}); - - const xcbUtilSource = b.dependency("xcb-util", .{}); - const xcbUtilImageSource = b.dependency("xcb-util-image", .{}); - - const python3 = try b.findProgram(&.{ "python3", "python" }, &.{}); - - const headers = b.addWriteFiles(); - var protoCSources = std.ArrayList([]const u8).init(b.allocator); - - const xcbprotoPath = blk: { - var man = b.graph.cache.obtain(); - defer man.deinit(); - - const xcbprotoSourcePath = xcbprotoSource.path("src").getPath(xcbprotoSource.builder); - man.hash.addBytes(xcbprotoSourcePath); - - var dir = try std.fs.openDirAbsolute(xcbprotoSourcePath, .{ .iterate = true }); - defer dir.close(); - - var iter = dir.iterate(); - while (try iter.next()) |entry| { - if (!std.mem.endsWith(u8, entry.name, ".xml")) continue; - - _ = try man.addFile(xcbprotoSource.path(try std.fs.path.join(b.allocator, &.{ "src", entry.name })).getPath(xcbprotoSource.builder), null); - } - if (!(try man.hit())) { - const digest = man.final(); - const cachePath = try b.cache_root.join(b.allocator, &.{ "o", &digest }); + const xorgproto_upstream = libxau.builder.dependency("xorgproto", .{}); - try b.cache_root.handle.makeDir(try std.fs.path.join(b.allocator, &.{ "o", &digest })); + const xcb_util_upstream = b.dependency("xcb-util", .{}); + const xcb_util_image_upstream = b.dependency("xcb-util-image", .{}); + const libxdmcp_upstream = b.dependency("libXdmcp", .{}); - iter = dir.iterate(); - while (try iter.next()) |entry| { - if (!std.mem.endsWith(u8, entry.name, ".xml")) continue; + const python3_path = try b.findProgram(&.{ "python3", "python" }, &.{}); - _ = run(b, &.{ - python3, - libxcbSource.path("src/c_client.py").getPath(xcbprotoSource.builder), - "-c", - "libxcb", - "-l", - "libxcb", - "-s", - "3", - "-p", - xcbprotoSource.path(".").getPath(xcbprotoSource.builder), - xcbprotoSource.path(try std.fs.path.join(b.allocator, &.{ "src", entry.name })).getPath(xcbprotoSource.builder), - }, cachePath); - - const header = b.fmt("{s}.h", .{entry.name[0..(entry.name.len - 4)]}); - - _ = headers.addCopyFile(.{ - .path = try std.fs.path.join(b.allocator, &.{ cachePath, header }), - }, try std.fs.path.join(b.allocator, &.{ "xcb", header })); - - try protoCSources.append(b.fmt("{s}.c", .{ - entry.name[0..(entry.name.len - 4)], - })); - } + const libxcb = b.addLibrary(.{ + .name = "xcb", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + }), + .linkage = linkage, + }); - try man.writeManifest(); + libxcb.linkLibC(); - break :blk cachePath; - } else { - const digest = man.final(); - const cachePath = try b.cache_root.join(b.allocator, &.{ "o", &digest }); + const headers = b.addWriteFiles(); + const c_client_sources = b.addWriteFiles(); + { + const xcbgen = xcbproto_upstream.path("xcbgen"); + const xcbgen_path = xcbgen.getPath3(b, null).root_dir.path.?; - iter = dir.iterate(); - while (try iter.next()) |entry| { - if (!std.mem.endsWith(u8, entry.name, ".xml")) continue; + const c_client_py = libxcb_upstream.path("src/c_client.py"); + const c_client_py_wrapper = b.path("script/c_client.py"); - const header = b.fmt("{s}.h", .{entry.name[0..(entry.name.len - 4)]}); + for (xml_files) |xml_file_basename| { + const c_file_basename = b.fmt("{s}.c", .{xml_file_basename[0 .. xml_file_basename.len - 4]}); + const h_file_basename = b.fmt("{s}.h", .{xml_file_basename[0 .. xml_file_basename.len - 4]}); - _ = headers.addCopyFile(.{ - .path = try std.fs.path.join(b.allocator, &.{ cachePath, header }), - }, try std.fs.path.join(b.allocator, &.{ "xcb", header })); + const PYTHONPATH = b.fmt("{s}:{s}", .{ + c_client_py.dirname().getPath3(b, null).root_dir.path.?, + xcbgen_path, + }); + const src_xml_file = b.fmt("src/{s}", .{xml_file_basename}); - try protoCSources.append(b.fmt("{s}.c", .{ - entry.name[0..(entry.name.len - 4)], - })); - } + const py = b.addSystemCommand(&.{python3_path}); + py.setEnvironmentVariable("PYTHONPATH", PYTHONPATH); + py.addFileArg(c_client_py_wrapper); + py.addPrefixedFileArg("--child-script=", c_client_py); - break :blk try b.cache_root.join(b.allocator, &.{ "o", &digest }); - } - }; + // not the best but works + const c_file = py.addPrefixedOutputFileArg("--c-output=", c_file_basename); + const h_file = py.addPrefixedOutputFileArg("--h-output=", h_file_basename); - { - var dir = try std.fs.openDirAbsolute(xorgprotoSource.path("include").getPath(xorgprotoSource.builder), .{ .iterate = true }); - defer dir.close(); + py.addArgs(&.{ "-c", "libxcb", "-l", "libxcb", "-s", "3", "-p" }); + py.addDirectoryArg(xcbproto_upstream.path("")); + py.addFileArg(xcbproto_upstream.path(src_xml_file)); - var iter = try dir.walk(b.allocator); - defer iter.deinit(); + py.setCwd(libxcb_upstream.path("src")); - while (try iter.next()) |entry| { - if (std.mem.eql(u8, entry.basename, "meson.build")) continue; - if (entry.kind != .file) continue; + _ = headers.addCopyFile( + h_file, + b.fmt("xcb/{s}", .{h_file_basename}), + ); - _ = headers.addCopyFile(xorgprotoSource.path(try std.fs.path.join(b.allocator, &.{ "include", entry.path })), entry.path); + _ = c_client_sources.addCopyFile(c_file, c_file_basename); } - } - - _ = headers.addCopyFile(libxcbSource.path("src/xcb.h"), "xcb/xcb.h"); - _ = headers.addCopyFile(xcbUtilSource.path("src/xcb_atom.h"), "xcb/xcb_atom.h"); - _ = headers.addCopyFile(xcbUtilSource.path("src/xcb_aux.h"), "xcb/xcb_aux.h"); - _ = headers.addCopyFile(xcbUtilSource.path("src/xcb_event.h"), "xcb/xcb_event.h"); - _ = headers.addCopyFile(xcbUtilSource.path("src/xcb_util.h"), "xcb/xcb_util.h"); - _ = headers.addCopyFile(xcbUtilImageSource.path("image/xcb_bitops.h"), "xcb/xcb_bitops.h"); - _ = headers.addCopyFile(xcbUtilImageSource.path("image/xcb_image.h"), "xcb/xcb_image.h"); - _ = headers.addCopyFile(xcbUtilImageSource.path("image/xcb_pixel.h"), "xcb/xcb_pixel.h"); - const libxcb = std.Build.Step.Compile.create(b, .{ - .name = "xcb", - .root_module = .{ - .target = target, - .optimize = optimize, - .link_libc = true, - }, - .kind = .lib, - .linkage = linkage, - }); - - for (headers.files.items) |header| { - const install_file = b.addInstallFileWithDir(header.getPath(), .header, header.sub_path); - b.getInstallStep().dependOn(&install_file.step); - libxcb.installed_headers.append(&install_file.step) catch @panic("OOM"); + libxcb.root_module.addCSourceFiles(.{ + .root = c_client_sources.getDirectory(), + .files = blk: { + const files_names = try b.allocator.alloc([]const u8, c_client_sources.files.items.len); + for (0..files_names.len) |i| + files_names[i] = c_client_sources.files.items[i].sub_path; + break :blk files_names; + }, + .flags = &.{ + "-DXCB_QUEUE_BUFFER_SIZE=16384", + "-DIOV_MAX=16", + }, + }); } - libxcb.addIncludePath(libxcbSource.path("src")); - libxcb.addIncludePath(libxauSource.path("include")); - libxcb.addIncludePath(xorgprotoSource.path("include")); - libxcb.addIncludePath(.{ .path = xcbprotoPath }); + _ = headers.addCopyDirectory( + xorgproto_upstream.path("include"), + "", + .{ .include_extensions = &.{".h"} }, + ); + + _ = headers.addCopyFile(libxcb_upstream.path("src/xcb.h"), "xcb/xcb.h"); + _ = headers.addCopyFile(libxcb_upstream.path("src/xcbext.h"), "xcb/xcbext.h"); + _ = headers.addCopyFile(libxcb_upstream.path("src/xcbint.h"), "xcb/xcbint.h"); + _ = headers.addCopyFile(xcb_util_upstream.path("src/xcb_atom.h"), "xcb/xcb_atom.h"); + _ = headers.addCopyFile(xcb_util_upstream.path("src/xcb_aux.h"), "xcb/xcb_aux.h"); + _ = headers.addCopyFile(xcb_util_upstream.path("src/xcb_event.h"), "xcb/xcb_event.h"); + _ = headers.addCopyFile(xcb_util_upstream.path("src/xcb_util.h"), "xcb/xcb_util.h"); + _ = headers.addCopyFile(xcb_util_image_upstream.path("image/xcb_bitops.h"), "xcb/xcb_bitops.h"); + _ = headers.addCopyFile(xcb_util_image_upstream.path("image/xcb_image.h"), "xcb/xcb_image.h"); + _ = headers.addCopyFile(xcb_util_image_upstream.path("image/xcb_pixel.h"), "xcb/xcb_pixel.h"); libxcb.addCSourceFiles(.{ - .root = libxcbSource.path("."), + .root = libxcb_upstream.path("."), .files = &.{ "src/xcb_auth.c", "src/xcb_conn.c", @@ -238,57 +139,49 @@ pub fn build(b: *std.Build) !void { }, }); - libxcb.addCSourceFiles(.{ - .root = .{ .path = xcbprotoPath }, - .files = protoCSources.items, - .flags = &.{ - "-DXCB_QUEUE_BUFFER_SIZE=16384", - "-DIOV_MAX=16", - }, - }); + libxcb.root_module.addIncludePath(xorgproto_upstream.path("include")); + libxcb.root_module.addIncludePath(headers.getDirectory().path(b, "xcb")); + libxcb.root_module.addIncludePath(headers.getDirectory().path(b, "include")); - libxcb.linkLibrary(libxau.artifact("Xau")); - b.installArtifact(libxcb); + libxcb.root_module.linkLibrary(libxau.artifact("Xau")); - const libxcbShm = std.Build.Step.Compile.create(b, .{ + libxcb.installHeadersDirectory(headers.getDirectory(), "", .{}); + libxcb.root_module.addIncludePath(headers.getDirectory()); + + const libxcb_shm = b.addLibrary(.{ .name = "xcb-shm", - .root_module = .{ + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, - }, - .kind = .lib, + }), .linkage = linkage, }); - libxcbShm.addIncludePath(libxcbSource.path("src")); - libxcbShm.addIncludePath(libxauSource.path("include")); - libxcbShm.addIncludePath(xorgprotoSource.path("include")); - libxcbShm.addIncludePath(.{ .path = xcbprotoPath }); + libxcb_shm.root_module.addIncludePath(libxcb_upstream.path("src")); + libxcb_shm.root_module.addIncludePath(xorgproto_upstream.path("include")); + libxcb_shm.root_module.addIncludePath(headers.getDirectory().path(b, "xcb")); + + libxcb_shm.root_module.linkLibrary(libxau.artifact("Xau")); - libxcbShm.addCSourceFiles(.{ - .root = .{ .path = xcbprotoPath }, + libxcb_shm.addCSourceFiles(.{ + .root = c_client_sources.getDirectory(), .files = &.{ "shm.c", "xinerama.c" }, }); - libxcbShm.linkLibrary(libxcb); - b.installArtifact(libxcbShm); - - const xcbutil = std.Build.Step.Compile.create(b, .{ + const xcb_util = b.addLibrary(.{ .name = "xcb-util", - .root_module = .{ + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, - }, - .kind = .lib, + }), .linkage = linkage, }); - xcbutil.addIncludePath(headers.getDirectory()); - - xcbutil.addCSourceFiles(.{ - .root = xcbUtilSource.path("src"), + xcb_util.root_module.addIncludePath(headers.getDirectory()); + xcb_util.addCSourceFiles(.{ + .root = xcb_util_upstream.path("src"), .files = &.{ "atoms.c", "event.c", @@ -296,174 +189,114 @@ pub fn build(b: *std.Build) !void { }, }); - b.installArtifact(xcbutil); - - const xcbutilImage = std.Build.Step.Compile.create(b, .{ + const xcb_image = b.addLibrary(.{ .name = "xcb-image", - .root_module = .{ + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, - }, - .kind = .lib, + }), .linkage = linkage, }); - xcbutilImage.addIncludePath(headers.getDirectory()); - - xcbutilImage.addCSourceFiles(.{ - .root = xcbUtilImageSource.path("image"), + xcb_image.root_module.addIncludePath(headers.getDirectory()); + xcb_image.addCSourceFiles(.{ + .root = xcb_util_image_upstream.path("image"), .files = &.{ "xcb_image.c", }, }); - xcbutilImage.linkLibrary(xcbutil); - xcbutilImage.linkLibrary(libxcbShm); - b.installArtifact(xcbutilImage); + xcb_image.root_module.linkLibrary(xcb_util); + xcb_image.root_module.linkLibrary(libxcb_shm); - const bootstrapOptions = b.addOptions(); - bootstrapOptions.addOption([]const u8, "importName", "../xcb.zig"); + libxcb.installHeadersDirectory(headers.getDirectory(), "", .{}); + libxcb.root_module.linkLibrary(xcb_image); - const options = b.addOptions(); - options.addOption([]const u8, "importName", "xcb"); - - const moduleSource = b.addWriteFiles(); - { - const protogen = b.addExecutable(.{ - .name = "protogen", - .root_source_file = .{ - .path = b.pathFromRoot("bin/protogen.zig"), - }, - .target = b.host, - .optimize = optimize, - .linkage = linkage, - }); - - protogen.root_module.addImport("clap", clap.module("clap")); - protogen.root_module.addAnonymousImport("xcb", .{ - .root_source_file = .{ - .path = b.pathFromRoot("lib/xcb.zig"), - }, - .target = b.host, + const libxdmcp = b.addLibrary(.{ + .name = "Xdmcp", + .root_module = b.createModule(.{ + .target = target, .optimize = optimize, - .imports = &.{ - .{ - .name = "options", - .module = bootstrapOptions.createModule(), - }, - }, - }); - - const protogenRun = b.addRunArtifact(protogen); - protogenRun.addDirectoryArg(xcbprotoSource.path("src")); - protogenRun.addArgs(&.{ "-g", "zig" }); - _ = moduleSource.addCopyFile(protogenRun.captureStdOut(), "xcb/protos.zig"); - } - - { - var dir = try std.fs.openDirAbsolute(b.pathFromRoot("lib"), .{ .iterate = true }); - defer dir.close(); - - var iter = try dir.walk(b.allocator); - defer iter.deinit(); - - while (try iter.next()) |entry| { - if (entry.kind != .file) continue; - if (std.mem.eql(u8, entry.path, "xcb/protos.zig")) continue; - - _ = moduleSource.addCopyFile(.{ - .path = b.pathFromRoot(try std.fs.path.join(b.allocator, &.{ "lib", entry.path })), - }, entry.path); - } - } + .link_libc = true, + }), + .linkage = linkage, + }); - const module = b.addModule("xcb", .{ - .root_source_file = blk: { - for (moduleSource.files.items) |item| { - if (std.mem.eql(u8, item.sub_path, "xcb.zig")) { - break :blk item.getPath(); - } - } - unreachable; + libxdmcp.root_module.addCSourceFiles(.{ + .root = libxdmcp_upstream.path(""), + .files = &.{ + "Array.c", + "Fill.c", + "Flush.c", + "Key.c", + "Read.c", + "Unwrap.c", + "Wrap.c", + "Write.c", }, - .target = target, - .optimize = optimize, - .link_libc = true, + .flags = &.{}, }); - module.addImport("options", options.createModule()); - - module.addIncludePath(headers.getDirectory()); - module.linkLibrary(libxcb); - module.linkLibrary(xcbutilImage); - - const step_test = b.step("test", "Run all unit tests"); - - const unit_tests = b.addTest(.{ - .root_source_file = module.root_source_file.?, - .target = target, - .optimize = optimize, - .link_libc = true, - }); + libxdmcp.root_module.addIncludePath(xorgproto_upstream.path("include")); + libxdmcp.root_module.addIncludePath(libxdmcp_upstream.path("include")); + libxdmcp.root_module.addIncludePath(headers.getDirectory()); - unit_tests.root_module.addImport("options", bootstrapOptions.createModule()); + libxcb.root_module.linkLibrary(libxdmcp); - unit_tests.addIncludePath(headers.getDirectory()); - unit_tests.linkLibrary(libxcb); - unit_tests.linkLibrary(xcbutilImage); + b.installArtifact(libxcb); +} - const run_unit_tests = b.addRunArtifact(unit_tests); - step_test.dependOn(&run_unit_tests.step); +fn cwdOutFile(b: *Build, run: *Build.Step.Run, basename: []const u8) Build.LazyPath { + const cwd = run.cwd.?; + const abs_path = cwd.join(b.allocator, basename) catch @panic("OOM"); + const output = b.allocator.create(Build.Step.Run.Output) catch @panic("OOM"); - if (!no_docs) { - const docs = b.addInstallDirectory(.{ - .source_dir = unit_tests.getEmittedDocs(), - .install_dir = .prefix, - .install_subdir = "docs", - }); + output.* = .{ + .prefix = "", + .basename = basename, + .generated_file = .{ .step = &run.step, .path = abs_path.getPath(b) }, + }; - b.getInstallStep().dependOn(&docs.step); + if (run.rename_step_with_output_arg) { + run.setName(b.fmt("{s} ({s})", .{ run.step.name, basename })); } - const example = b.addExecutable(.{ - .name = "example", - .root_source_file = .{ - .path = b.pathFromRoot("example.zig"), - }, - .target = target, - .optimize = optimize, - .link_libc = true, - .linkage = linkage, - }); - - example.root_module.addImport("xcb", module); - b.installArtifact(example); - - const protogen = b.addExecutable(.{ - .name = "protogen", - .root_source_file = .{ - .path = b.pathFromRoot("bin/protogen.zig"), - }, - .target = target, - .optimize = optimize, - .linkage = linkage, - }); - - protogen.root_module.addImport("clap", clap.module("clap")); - - protogen.root_module.addAnonymousImport("xcb", .{ - .root_source_file = .{ - .path = b.pathFromRoot("lib/xcb.zig"), - }, - .target = target, - .optimize = optimize, - .imports = &.{ - .{ - .name = "options", - .module = options.createModule(), - }, - }, - }); - b.installArtifact(protogen); + return .{ .generated = .{ .file = &output.generated_file } }; } + +const xml_files = [_][]const u8{ + // "xcb.xsd", + "xproto.xml", + "bigreq.xml", + "composite.xml", + "damage.xml", + "dbe.xml", + "dpms.xml", + "dri2.xml", + "dri3.xml", + "ge.xml", + "glx.xml", + "present.xml", + "randr.xml", + "record.xml", + "render.xml", + "res.xml", + "screensaver.xml", + "shape.xml", + "shm.xml", + "sync.xml", + "xc_misc.xml", + "xevie.xml", + "xf86dri.xml", + "xf86vidmode.xml", + "xfixes.xml", + "xinerama.xml", + "xinput.xml", + "xkb.xml", + "xprint.xml", + "xselinux.xml", + "xtest.xml", + "xv.xml", + "xvmc.xml", +}; diff --git a/build.zig.zon b/build.zig.zon index e0b05f7..7f0812c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,31 +1,37 @@ .{ - .name = "xcb.zig", - .version = "0.1.16", + .name = .xcb, + .fingerprint = 0x48cfd8eae06c78ea, + .version = "0.1.17", + .minimum_zig_version = "0.14.0", .paths = .{""}, .dependencies = .{ .libxcb = .{ - .url = "https://gitlab.freedesktop.org/xorg/lib/libxcb/-/archive/libxcb-1.16/libxcb-libxcb-1.16.tar.gz", - .hash = "1220c6c1f5516d0fe1ca72f5391f7f00f3114c0761cedeccbeeb5d8e7efaefc87fbc", + .url = "https://gitlab.freedesktop.org/xorg/lib/libxcb/-/archive/libxcb-1.17.0/libxcb-libxcb-1.17.0.tar.gz", + .hash = "N-V-__8AAPZxCQD7JyQLx0_D9J9dnkSoP7iziBVxreTgUqlj", }, .xcbproto = .{ - .url = "https://gitlab.freedesktop.org/xorg/proto/xcbproto/-/archive/xcb-proto-1.16.0/xcbproto-xcb-proto-1.16.0.tar.gz", - .hash = "122088858bfa13f990603440f3b13aa027abfa828de875497fcb58efd017fe0af6ea", - }, - .libxau = .{ - .url = "https://github.com/MidstallSoftware/libxau.zig/archive/a8adbbd1a687cb460dcb0356b973c740d6dc4c36.tar.gz", - .hash = "1220a0ccc00ff9ee2df9ae313345dd93af2a8876772f127e8bc5c90eca7bd2547c34", + .url = "https://gitlab.freedesktop.org/xorg/proto/xcbproto/-/archive/xcb-proto-1.17.0/xcbproto-xcb-proto-1.17.0.tar.gz", + .hash = "N-V-__8AAFnMDACdXT5YIakLgEMFZ-K7ZICgB18p8xKobHjk", }, .@"xcb-util" = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxcb-util/-/archive/xcb-util-0.4.1/libxcb-util-xcb-util-0.4.1.tar.gz", - .hash = "1220096cb9b583a14b307609801d8a018a3babc9e608170afc521a0db4e437165c15", + .hash = "N-V-__8AAMqcAAAJbLm1g6FLMHYJgB2KAYo7q8nmCBcK_FIa", }, .@"xcb-util-image" = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxcb-image/-/archive/xcb-util-image-0.4.1/libxcb-image-xcb-util-image-0.4.1.tar.gz", - .hash = "122092beed2990a3b55f6ad7984159e2e53ef2372ecd36d95deeda007ee3903a6797", + .hash = "N-V-__8AAIogAgCSvu0pkKO1X2rXmEFZ4uU-8jcuzTbZXe7a", }, .clap = .{ - .url = "https://github.com/MidstallSoftware/zig-clap/archive/2f0b4443b2a168e2ee545e595b104a9900bc3401.tar.gz", - .hash = "12201e606115ddfe830f1a585919bdebe27d2217114d05b03b617fc0f274218514d3", + .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz", + .hash = "clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e", + }, + .libxau = .{ + .url = "https://github.com/PaNDa2code/libxau_zig/archive/0e129be42205a99d329b3737476a0dc828857779.tar.gz", + .hash = "libxau-1.0.11-kZh3fMiRAAAjO0giWUHQ2CR4jvq-6ThU46cz1eNx7ZnE", + }, + .libXdmcp = .{ + .url = "https://gitlab.freedesktop.org/xorg/lib/libxdmcp/-/archive/libXdmcp-1.1.5/libxdmcp-libXdmcp-1.1.5.tar.gz", + .hash = "N-V-__8AAHC7AgA7EvtCRM2pOGbGmSYsVrYJoTPjVbUX1_ue", }, }, } diff --git a/external/libxau.zig b/external/libxau.zig new file mode 160000 index 0000000..0e129be --- /dev/null +++ b/external/libxau.zig @@ -0,0 +1 @@ +Subproject commit 0e129be42205a99d329b3737476a0dc828857779 diff --git a/external/zig-clap b/external/zig-clap new file mode 160000 index 0000000..5289e07 --- /dev/null +++ b/external/zig-clap @@ -0,0 +1 @@ +Subproject commit 5289e0753cd274d65344bef1c114284c633536ea diff --git a/lib/xcb/protocol.zig b/lib/xcb/protocol.zig index 73cac09..fe66a6a 100644 --- a/lib/xcb/protocol.zig +++ b/lib/xcb/protocol.zig @@ -15,7 +15,7 @@ pub const Enum = @import("protocol/enum.zig"); pub const Error = @import("protocol/error.zig"); pub const Event = @import("protocol/event.zig"); pub const EventStruct = @import("protocol/eventstruct.zig"); -pub usingnamespace @import("protocol/field.zig"); +pub const Field = @import("protocol/field.zig"); pub const Request = @import("protocol/request.zig"); pub const Struct = @import("protocol/struct.zig"); pub const Union = @import("protocol/union.zig"); diff --git a/script/c_client.py b/script/c_client.py new file mode 100644 index 0000000..14b30e2 --- /dev/null +++ b/script/c_client.py @@ -0,0 +1,70 @@ +import sys +import os +import getopt +import subprocess +import shutil + +def main(): + try: + opts, args = getopt.getopt( + sys.argv[1:], + "c:l:s:p:m", + ["server-side", "child-script=", "c-output=", "h-output="] + ) + except getopt.GetoptError as err: + print("Error:", err) + sys.exit(1) + + c_output = None + h_output = None + child_script = None + + # Options to forward to c_client.py + forward_opts = [] + + for (opt, arg) in opts: + if opt == "--child-script": + child_script = arg + elif opt == "--c-output": + c_output = arg + elif opt == "--h-output": + h_output = arg + else: + if arg: + forward_opts.extend([opt, arg]) + else: + forward_opts.append(opt) + + if not c_output: + print("Error: --c-output must be provided") + sys.exit(1) + + if not h_output: + print("Error: --h-output must be provided") + sys.exit(1) + + if not child_script: + print("Error: --child-script must be provided (path to c_client.py)") + sys.exit(1) + + if not args: + print("Error: Missing XML file argument") + sys.exit(1) + + xml_file = args[0] + + # Run child c_client.py with forwarded args + cmd = [sys.executable, child_script] + forward_opts + [xml_file] + subprocess.check_call(cmd) + + # Determine generated base filename (same as XML without extension) + base_name = os.path.splitext(os.path.basename(xml_file))[0] + generated_c = f"{base_name}.c" + generated_h = f"{base_name}.h" + + # Move files if requested + shutil.move(generated_c, c_output) + shutil.move(generated_h, h_output) + +if __name__ == "__main__": + main()