From 6f247810dc709b2efb982d7ce0783a2cb55c6c84 Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Fri, 8 Nov 2024 13:56:44 +0100 Subject: [PATCH 1/2] make system libudev optional --- build.zig | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index dd0feed0..318ec413 100644 --- a/build.zig +++ b/build.zig @@ -13,13 +13,18 @@ fn define_from_bool(val: bool) ?u1 { pub fn build(b: *Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + const system_libudev = b.option( + bool, + "system-libudev", + "link with system libudev on linux", + ) orelse true; - const libusb = create_libusb(b, target, optimize); + const libusb = create_libusb(b, target, optimize, system_libudev); b.installArtifact(libusb); const build_all = b.step("all", "build libusb for all targets"); for (targets(b)) |t| { - const lib = create_libusb(b, t, optimize); + const lib = create_libusb(b, t, optimize, system_libudev); build_all.dependOn(&lib.step); } } @@ -28,6 +33,7 @@ fn create_libusb( b: *Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, + system_libudev: bool, ) *Build.Step.Compile { const is_posix = target.result.isDarwin() or @@ -51,7 +57,10 @@ fn create_libusb( lib.linkFrameworkNeeded("Security"); } else if (target.result.os.tag == .linux) { lib.addCSourceFiles(.{ .files = linux_src }); - lib.linkSystemLibrary("udev"); + if (system_libudev) { + lib.addCSourceFiles(.{ .files = linux_udev_src }); + lib.linkSystemLibrary("udev"); + } } else if (target.result.os.tag == .windows) { lib.addCSourceFiles(.{ .files = windows_src }); lib.addCSourceFiles(.{ .files = windows_platform_src }); @@ -92,7 +101,7 @@ fn create_libusb( .HAVE_EVENTFD = null, .HAVE_INTTYPES_H = null, .HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H = define_from_bool(target.result.isDarwin()), - .HAVE_LIBUDEV = null, + .HAVE_LIBUDEV = define_from_bool(system_libudev), .HAVE_NFDS_T = null, .HAVE_PIPE2 = null, .HAVE_PTHREAD_CONDATTR_SETCLOCK = null, @@ -165,9 +174,11 @@ const haiku_src: []const []const u8 = &.{ const linux_src: []const []const u8 = &.{ "libusb/os/linux_netlink.c", - "libusb/os/linux_udev.c", "libusb/os/linux_usbfs.c", }; +const linux_udev_src: []const []const u8 = &.{ + "libusb/os/linux_udev.c", +}; const netbsd_src: []const []const u8 = &.{ "libusb/os/netbsd_usb.c", From 749a1b12c786701843db5273206d4d012f34444b Mon Sep 17 00:00:00 2001 From: Tobias Simetsreiter Date: Fri, 8 Nov 2024 13:57:05 +0100 Subject: [PATCH 2/2] ignore .zig-cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ab8ce7a3..1bf53f1d 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ xcuserdata *.xcworkspace zig-cache zig-out +.zig-cache \ No newline at end of file