Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: linux
on:
push:
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
- uses: mlugg/setup-zig@v2
with:
version: 0.13.0
version: 0.15.1
- name: install libudev
run: sudo apt install -y libudev-dev
- name: build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: macos
on:
push:
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
strategy:
matrix:
os: [macos-11, macos-12, macos-13]
os: [macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
- uses: mlugg/setup-zig@v2
with:
version: 0.13.0
version: 0.15.1
- name: build
run: zig build
8 changes: 4 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ name: windows
on:
push:
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
strategy:
matrix:
os: [windows-2022, windows-2019]
os: [windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
- uses: mlugg/setup-zig@v2
with:
version: 0.13.0
version: 0.15.1
- name: build
run: zig build
33 changes: 17 additions & 16 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ 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 system_libudev = b.option(bool, "system-libudev", "link with system libudev on linux") orelse true;
const linkage = b.option(std.builtin.LinkMode, "linkage", "static vs dynamic linkage") orelse .dynamic;

const libusb = create_libusb(b, target, optimize, system_libudev);
const libusb = create_libusb(b, target, optimize, linkage, 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, system_libudev);
const lib = create_libusb(b, t, optimize, linkage, system_libudev);
build_all.dependOn(&lib.step);
}
}
Expand All @@ -33,25 +30,29 @@ fn create_libusb(
b: *Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
linkage: std.builtin.LinkMode,
system_libudev: bool,
) *Build.Step.Compile {
const is_posix =
target.result.isDarwin() or
target.result.os.tag == .macos or
target.result.os.tag == .linux or
target.result.os.tag == .openbsd;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.name = "usb",
.target = target,
.optimize = optimize,
.link_libc = true,
.linkage = linkage,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
lib.addCSourceFiles(.{ .files = src });

if (is_posix)
lib.addCSourceFiles(.{ .files = posix_platform_src });

if (target.result.isDarwin()) {
if (target.result.os.tag == .macos) {
lib.addCSourceFiles(.{ .files = darwin_src });
lib.linkFramework("CoreFoundation");
lib.linkFramework("IOKit");
Expand Down Expand Up @@ -79,15 +80,15 @@ fn create_libusb(
lib.installHeader(b.path("libusb/libusb.h"), "libusb.h");

// config header
if (target.result.isDarwin()) {
if (target.result.os.tag == .macos) {
lib.addIncludePath(b.path("Xcode"));
} else if (target.result.abi == .msvc) {
lib.addIncludePath(b.path("msvc"));
} else if (target.result.abi == .android) {
lib.addIncludePath(b.path("android"));
} else {
const config_h = b.addConfigHeader(.{ .style = .{
.autoconf = b.path("config.h.in"),
.autoconf_undef = b.path("config.h.in"),
} }, .{
.DEFAULT_VISIBILITY = .@"__attribute__ ((visibility (\"default\")))",
.ENABLE_DEBUG_LOGGING = define_from_bool(optimize == .Debug),
Expand All @@ -101,7 +102,7 @@ fn create_libusb(
.HAVE_DLFCN_H = null,
.HAVE_EVENTFD = null,
.HAVE_INTTYPES_H = null,
.HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H = define_from_bool(target.result.isDarwin()),
.HAVE_IOKIT_USB_IOUSBHOSTFAMILYDEFINITIONS_H = define_from_bool(target.result.os.tag == .macos),
.HAVE_LIBUDEV = define_from_bool(system_libudev),
.HAVE_NFDS_T = null,
.HAVE_PIPE2 = null,
Expand Down
6 changes: 4 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.{
.name = "libusb",
.version = "1.0.26",
.name = .libusb,
.version = "0.0.1",
.minimum_zig_version = "0.15.1",
.fingerprint = 0x3e6dc4cc42984d3f,
.paths = .{
"README",
"COPYING",
Expand Down