{"id":23507399,"url":"https://github.com/ssttevee/zig-libusb","last_synced_at":"2025-05-12T15:51:06.446Z","repository":{"id":243709332,"uuid":"813190448","full_name":"ssttevee/zig-libusb","owner":"ssttevee","description":"zig builder and wrapper for libusb","archived":false,"fork":false,"pushed_at":"2024-06-10T22:17:46.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-02-16T19:15:23.029Z","etag":null,"topics":["libusb","usb","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssttevee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-10T16:33:23.000Z","updated_at":"2024-10-26T16:45:05.000Z","dependencies_parsed_at":"2024-06-10T20:30:02.631Z","dependency_job_id":"e5d5db38-6e39-4a9b-80a7-72c2a75365d3","html_url":"https://github.com/ssttevee/zig-libusb","commit_stats":null,"previous_names":["ssttevee/zig-libusb"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssttevee%2Fzig-libusb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssttevee%2Fzig-libusb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssttevee%2Fzig-libusb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssttevee%2Fzig-libusb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssttevee","download_url":"https://codeload.github.com/ssttevee/zig-libusb/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253768484,"owners_count":21961338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libusb","usb","zig"],"created_at":"2024-12-25T10:18:41.643Z","updated_at":"2025-05-12T15:51:06.425Z","avatar_url":"https://github.com/ssttevee.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig-libusb\n\nThis module takes full advantage of the zig build system to download and build libusb. There is also a thin zig layer for more natural integration in other zig code.\n\nTested with the following configurations:\n- self-hosted zig 0.12.0 on aarch64-macos\n- self-hosted zig 0.13.0 on x86_64-linux\n\nSome effort was spent porting other build configurations as well. Please submit a pull request to verify or fix builds on your system if possible.\n\n# Building\n\n```sh\nzig build --release=safe\n```\n\n## Options\n\nRun `zig build --help` for the full list of options offered by zig.\n\n```\n  -Dtarget=[string]            The CPU architecture, OS, and ABI to build for\n  -Dcpu=[string]               Target CPU features to add or subtract\n  -Ddynamic-linker=[string]    Path to interpreter on the target system\n  -Doptimize=[enum]            Prioritize performance, safety, or binary size\n                                 Supported Values:\n                                   Debug\n                                   ReleaseSafe\n                                   ReleaseFast\n                                   ReleaseSmall\n  -Dstatic=[bool]              Build static lib (default: true)\n  -Dshared=[bool]              Build shared lib (default: true)\n```\n\n# Zig Layer\n\nThe zig layer tries OO-ify the library and remove manual bit-wise operations where possible.\n\n## Installing into your own project\n\nRun this command from your project folder\n\n```sh\nzig fetch --save https://github.com/ssttevee/zig-libusb/archive/refs/tags/1.0.27.tar.gz\n```\n\nThen add this snippet to your `build.zig` file\n\n```zig\nconst libusb = b.dependency(\"libusb\", .{\n    .optimize = optimize,\n    .target = target,\n});\n\nexe.root_module.addImport(\"libusb\", libusb.module(\"libusb\"));\n```\n\n## Example\n\n```zig\nconst std = @import(\"std\");\nconst libusb = @import(\"libusb\");\n\npub fn main() !void {\n    try libusb.init(.{ .log_level = .info });\n    defer libusb.deinit();\n\n    const my_device = blk: {\n        const devices = try libusb.getDeviceList();\n        defer libusb.freeDeviceList(devices);\n\n        for (devices) |device| {\n            if (isMyDevice(device)) {\n                break :blk device.ref();\n            }\n        }\n    };\n    defer my_device.unref();\n\n    var config_desc = try my_device.getActiveConfigDescriptor();\n    defer config_desc.deinit();\n\n    const interface_desc = config_desc.interfacesSlice()[0].toSlice()[0];\n    const write_endpoint = interface_desc.endpointsSlice()[0];\n\n    std.debug.assert(write_endpoint.bmAttributes.transfer_type == .bulk);\n    std.debug.assert(write_endpoint.bEndpointAddress.direction == .output);\n\n    const device_handle = try my_device.open();\n    defer device_handle.close();\n    defer device_handle.reset() catch {};\n\n    const my_interface = try device_handle.claimInterface(interface_desc.bInterfaceNumber);\n    defer my_interface.release();\n\n    const w = my_interface.writable(write_endpoint.bEndpointAddress, 0);\n    try std.fmt.format(w.writer(), \"Hello World\\n\", .{});\n}\n```\n\nThe raw c functions are also all accessible\n\n```zig\nconst std = @import(\"std\");\nconst libusb = @import(\"libusb\");\n\npub fn main() !void {\n    try libusb.c.libusb_init_context(null, null, 0).result();\n    defer libusb.c.libusb_exit(null);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssttevee%2Fzig-libusb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssttevee%2Fzig-libusb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssttevee%2Fzig-libusb/lists"}