Skip to content

Android support #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v1.0.26-zig
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ fn create_libusb(
target.result.os.tag == .linux or
target.result.os.tag == .openbsd;

const lib = b.addStaticLibrary(.{
const lib = if (target.result.isAndroid()) b.addSharedLibrary(.{
.name = "usb",
.target = target,
.optimize = optimize,
.link_libc = true,
}) else b.addStaticLibrary(.{
.name = "usb",
.target = target,
.optimize = optimize,
Expand All @@ -49,6 +54,8 @@ fn create_libusb(
lib.addCSourceFiles(.{ .files = darwin_src });
lib.linkFrameworkNeeded("IOKit");
lib.linkFrameworkNeeded("Security");
} else if (target.result.isAndroid()) {
lib.addCSourceFiles(.{ .files = android_src });
} else if (target.result.os.tag == .linux) {
lib.addCSourceFiles(.{ .files = linux_src });
lib.linkSystemLibrary("udev");
Expand All @@ -73,7 +80,7 @@ fn create_libusb(
lib.addIncludePath(b.path("Xcode"));
} else if (target.result.abi == .msvc) {
lib.addIncludePath(b.path("msvc"));
} else if (target.result.abi == .android) {
} else if (target.result.isAndroid()) {
lib.addIncludePath(b.path("android"));
} else {
const config_h = b.addConfigHeader(.{ .style = .{
Expand Down Expand Up @@ -169,6 +176,11 @@ const linux_src: []const []const u8 = &.{
"libusb/os/linux_usbfs.c",
};

const android_src: []const []const u8 = &.{
"libusb/os/linux_netlink.c",
"libusb/os/linux_usbfs.c",
};

const netbsd_src: []const []const u8 = &.{
"libusb/os/netbsd_usb.c",
};
Expand Down