Skip to content

Commit 363c738

Browse files
authored
Zig 0.15.1 (#17)
* Update to Zig 0.15.1 * Use mlugg's setup-zig action
1 parent 9e8cd74 commit 363c738

5 files changed

Lines changed: 33 additions & 30 deletions

File tree

‎.github/workflows/linux.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: linux
22
on:
33
push:
44
pull_request:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
build:
99
strategy:
1010
matrix:
11-
os: [ubuntu-20.04, ubuntu-22.04]
11+
os: [ubuntu-latest]
1212
runs-on: ${{ matrix.os }}
1313

1414
steps:
1515
- uses: actions/checkout@v2
16-
- uses: goto-bus-stop/setup-zig@v2
16+
- uses: mlugg/setup-zig@v2
1717
with:
18-
version: 0.13.0
18+
version: 0.15.1
1919
- name: install libudev
2020
run: sudo apt install -y libudev-dev
2121
- name: build

‎.github/workflows/macos.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ name: macos
22
on:
33
push:
44
pull_request:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
build:
99
strategy:
1010
matrix:
11-
os: [macos-11, macos-12, macos-13]
11+
os: [macos-latest]
1212
runs-on: ${{ matrix.os }}
1313

1414
steps:
1515
- uses: actions/checkout@v2
16-
- uses: goto-bus-stop/setup-zig@v2
16+
- uses: mlugg/setup-zig@v2
1717
with:
18-
version: 0.13.0
18+
version: 0.15.1
1919
- name: build
2020
run: zig build

‎.github/workflows/windows.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ name: windows
22
on:
33
push:
44
pull_request:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
build:
99
strategy:
1010
matrix:
11-
os: [windows-2022, windows-2019]
11+
os: [windows-latest]
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- uses: actions/checkout@v2
15-
- uses: goto-bus-stop/setup-zig@v2
15+
- uses: mlugg/setup-zig@v2
1616
with:
17-
version: 0.13.0
17+
version: 0.15.1
1818
- name: build
1919
run: zig build

‎build.zig‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ fn define_from_bool(val: bool) ?u1 {
1313
pub 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,

‎build.zig.zon‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.{
2-
.name = "libusb",
3-
.version = "1.0.26",
2+
.name = .libusb,
3+
.version = "0.0.1",
4+
.minimum_zig_version = "0.15.1",
5+
.fingerprint = 0x3e6dc4cc42984d3f,
46
.paths = .{
57
"README",
68
"COPYING",

0 commit comments

Comments
 (0)