aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--build.zig72
2 files changed, 30 insertions, 46 deletions
diff --git a/README.md b/README.md
index d0ea23e..b8d1d5d 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
-libxcb build for zig. Includes libxcb source code which is compiled from source. If you include this library in your zig project and build with `zig build -Doptimize=ReleaseSmall -Dtarget=native-linux-musl -Dcpu=baseline` then it will create a very small (75kb) static executable that is redistributable. \ No newline at end of file
+libxcb build for zig. Includes libxcb source code which is compiled from source. If you include this library in your zig project and build with `zig build -Doptimize=ReleaseSmall -Dtarget=native-linux-musl -Dcpu=baseline` then it will create a very small (75kb) static executable that is redistributable.\
+A minimal example of using this library is available here: [xcb-zig-example](https://git.dec05eba.com/xcb-zig-example/).\
+Note that this includes all xcb utilities in the xorg family, see: https://gitlab.freedesktop.org/xorg/lib?filter=libxcb \ No newline at end of file
diff --git a/build.zig b/build.zig
index d0e4092..ba6f638 100644
--- a/build.zig
+++ b/build.zig
@@ -1,29 +1,17 @@
const std = @import("std");
-pub fn build(b: *std.Build) void {
+pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+ const single_threaded = true; // TODO: remove, inherit from parent
- const lib = b.addStaticLibrary(.{
- .name = "xcb-zig",
- .target = target,
- .optimize = optimize,
- });
+ var libxcb = try buildXcb(b, &target, optimize, single_threaded);
- const single_threaded = true;
- const libXcb = buildXcb(b, &target, optimize, single_threaded);
+ libxcb.addIncludePath(.{ .path = "depends/libxcb/include" });
+ libxcb.installHeadersDirectory("depends/libxcb/include", ".");
- lib.linkLibrary(libXcb);
- lib.linkLibC();
- lib.strip = optimize != std.builtin.OptimizeMode.Debug;
- lib.want_lto = optimize != std.builtin.OptimizeMode.Debug;
- lib.single_threaded = single_threaded;
-
- lib.addIncludePath(.{ .path = "depends/libxcb/include" });
- lib.installHeadersDirectory("depends/libxcb/include", ".");
-
- lib.addIncludePath(.{ .path = "depends/libxcb/depends/xorgproto/include" });
- lib.installHeadersDirectory("depends/libxcb/depends/xorgproto/include", ".");
+ libxcb.addIncludePath(.{ .path = "depends/libxcb/depends/xorgproto/include" });
+ libxcb.installHeadersDirectory("depends/libxcb/depends/xorgproto/include", ".");
const util_deps = [_][]const u8 {
"depends/libxcb-keysyms",
@@ -36,8 +24,8 @@ pub fn build(b: *std.Build) void {
};
for(&util_deps) |dep| {
- lib.addIncludePath(.{ .path = dep });
- lib.installHeadersDirectoryOptions(.{
+ libxcb.addIncludePath(.{ .path = dep });
+ libxcb.installHeadersDirectoryOptions(.{
.source_dir = .{ .path = dep },
.install_dir = .header,
.install_subdir = ".",
@@ -45,14 +33,17 @@ pub fn build(b: *std.Build) void {
});
}
- b.installArtifact(lib);
+ b.installArtifact(libxcb);
}
-fn buildXau(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) *std.Build.Step.Compile {
+fn buildXau(b: *std.Build, target: *const std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) *std.Build.Step.Compile {
const lib = b.addStaticLibrary(.{
.name = "libxau",
.target = target.*,
.optimize = optimize,
+ .strip = optimize != std.builtin.OptimizeMode.Debug,
+ .single_threaded = single_threaded,
+ .link_libc = true,
});
lib.addCSourceFiles(.{
@@ -75,26 +66,26 @@ fn buildXau(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.bui
lib.addIncludePath(.{ .path = "depends/libxcb/depends/libxau/include" });
lib.addIncludePath(.{ .path = "depends/libxcb/depends/libxdmcp/include" });
lib.addIncludePath(.{ .path = "depends/libxcb/depends/xorgproto/include" });
- lib.linkLibC();
- lib.strip = optimize != std.builtin.OptimizeMode.Debug;
lib.want_lto = optimize != std.builtin.OptimizeMode.Debug;
- lib.single_threaded = single_threaded;
return lib;
}
-fn buildXdmcp(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) *std.Build.Step.Compile {
+fn buildXdmcp(b: *std.Build, target: *const std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) !*std.Build.Step.Compile {
const lib = b.addStaticLibrary(.{
.name = "libxdmcp",
.target = target.*,
.optimize = optimize,
+ .strip = optimize != std.builtin.OptimizeMode.Debug,
+ .single_threaded = single_threaded,
+ .link_libc = true,
});
var flags = std.ArrayList([]const u8).init(b.allocator);
- flags.append("-DHAVE_CONFIG_H") catch @panic("OOM");
- if (target.abi) |abi| {
+ try flags.append("-DHAVE_CONFIG_H");
+ if (target.query.abi) |abi| {
if (abi.isMusl()) {
- flags.append("-D__MUSL__") catch @panic("OOM");
+ try flags.append("-D__MUSL__");
}
}
@@ -116,22 +107,22 @@ fn buildXdmcp(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.b
lib.addIncludePath(.{ .path = "depends/libxcb/depends/libxdmcp" });
lib.addIncludePath(.{ .path = "depends/libxcb/depends/libxdmcp/include" });
lib.addIncludePath(.{ .path = "depends/libxcb/depends/xorgproto/include" });
- lib.linkLibC();
- lib.strip = optimize != std.builtin.OptimizeMode.Debug;
lib.want_lto = optimize != std.builtin.OptimizeMode.Debug;
- lib.single_threaded = single_threaded;
return lib;
}
-fn buildXcb(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) *std.Build.Step.Compile {
+fn buildXcb(b: *std.Build, target: *const std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, single_threaded: bool) !*std.Build.Step.Compile {
const libXau = buildXau(b, target, optimize, single_threaded);
- const libXdmcp = buildXdmcp(b, target, optimize, single_threaded);
+ const libXdmcp = try buildXdmcp(b, target, optimize, single_threaded);
const libXcb = b.addStaticLibrary(.{
- .name = "libxcb",
+ .name = "xcb-zig",
.target = target.*,
.optimize = optimize,
+ .strip = optimize != std.builtin.OptimizeMode.Debug,
+ .single_threaded = single_threaded,
+ .link_libc = true,
});
libXcb.linkLibrary(libXau);
@@ -214,18 +205,9 @@ fn buildXcb(b: *std.Build, target: *const std.zig.CrossTarget, optimize: std.bui
libXcb.addIncludePath(.{ .path = "depends/libxcb/depends/libxau/include" });
libXcb.addIncludePath(.{ .path = "depends/libxcb/depends/libxdmcp/include" });
libXcb.addIncludePath(.{ .path = "depends/libxcb/depends/xorgproto/include" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-render-util" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-image" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-util" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-keysyms" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-errors" });
- libXcb.addIncludePath(.{ .path = "depends/libxcb-wm" });
libXcb.addIncludePath(.{ .path = "depends/libxcb/include/xcb" });
libXcb.addIncludePath(.{ .path = "depends/libxcb/include" });
- libXcb.linkLibC();
- libXcb.strip = optimize != std.builtin.OptimizeMode.Debug;
libXcb.want_lto = optimize != std.builtin.OptimizeMode.Debug;
- libXcb.single_threaded = single_threaded;
return libXcb;
}