@@ -13,18 +13,15 @@ fn define_from_bool(val: bool) ?u1 {
1313pub fn build (b : * Build ) void {
1414 const optimize = b .standardOptimizeOption (.{});
1515 const target = b .standardTargetOptions (.{});
16- const system_libudev = b .option (
17- bool ,
18- "system-libudev" ,
19- "link with system libudev on linux" ,
20- ) orelse true ;
16+ const system_libudev = b .option (bool , "system-libudev" , "link with system libudev on linux" ) orelse true ;
17+ const linkage = b .option (std .builtin .LinkMode , "linkage" , "static vs dynamic linkage" ) orelse .dynamic ;
2118
22- const libusb = create_libusb (b , target , optimize , system_libudev );
19+ const libusb = create_libusb (b , target , optimize , linkage , system_libudev );
2320 b .installArtifact (libusb );
2421
2522 const build_all = b .step ("all" , "build libusb for all targets" );
2623 for (targets (b )) | t | {
27- const lib = create_libusb (b , t , optimize , system_libudev );
24+ const lib = create_libusb (b , t , optimize , linkage , system_libudev );
2825 build_all .dependOn (& lib .step );
2926 }
3027}
@@ -33,25 +30,29 @@ fn create_libusb(
3330 b : * Build ,
3431 target : std.Build.ResolvedTarget ,
3532 optimize : std.builtin.OptimizeMode ,
33+ linkage : std.builtin.LinkMode ,
3634 system_libudev : bool ,
3735) * Build.Step.Compile {
3836 const is_posix =
39- target .result .isDarwin () or
37+ target .result .os . tag == .macos or
4038 target .result .os .tag == .linux or
4139 target .result .os .tag == .openbsd ;
4240
43- const lib = b .addStaticLibrary (.{
41+ const lib = b .addLibrary (.{
4442 .name = "usb" ,
45- .target = target ,
46- .optimize = optimize ,
47- .link_libc = true ,
43+ .linkage = linkage ,
44+ .root_module = b .createModule (.{
45+ .target = target ,
46+ .optimize = optimize ,
47+ .link_libc = true ,
48+ }),
4849 });
4950 lib .addCSourceFiles (.{ .files = src });
5051
5152 if (is_posix )
5253 lib .addCSourceFiles (.{ .files = posix_platform_src });
5354
54- if (target .result .isDarwin () ) {
55+ if (target .result .os . tag == .macos ) {
5556 lib .addCSourceFiles (.{ .files = darwin_src });
5657 lib .linkFramework ("CoreFoundation" );
5758 lib .linkFramework ("IOKit" );
@@ -79,15 +80,15 @@ fn create_libusb(
7980 lib .installHeader (b .path ("libusb/libusb.h" ), "libusb.h" );
8081
8182 // config header
82- if (target .result .isDarwin () ) {
83+ if (target .result .os . tag == .macos ) {
8384 lib .addIncludePath (b .path ("Xcode" ));
8485 } else if (target .result .abi == .msvc ) {
8586 lib .addIncludePath (b .path ("msvc" ));
8687 } else if (target .result .abi == .android ) {
8788 lib .addIncludePath (b .path ("android" ));
8889 } else {
8990 const config_h = b .addConfigHeader (.{ .style = .{
90- .autoconf = b .path ("config.h.in" ),
91+ .autoconf_undef = b .path ("config.h.in" ),
9192 } }, .{
9293 .DEFAULT_VISIBILITY = .@"__attribute__ ((visibility (\" default \")))" ,
9394 .ENABLE_DEBUG_LOGGING = define_from_bool (optimize == .Debug ),
@@ -101,7 +102,7 @@ fn create_libusb(
101102 .HAVE_DLFCN_H = null ,
102103 .HAVE_EVENTFD = null ,
103104 .HAVE_INTTYPES_H = null ,
104- .HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H = define_from_bool (target .result .isDarwin () ),
105+ .HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H = define_from_bool (target .result .os . tag == .macos ),
105106 .HAVE_LIBUDEV = define_from_bool (system_libudev ),
106107 .HAVE_NFDS_T = null ,
107108 .HAVE_PIPE2 = null ,
0 commit comments