Merge "Add basic example for testing/validation" into main
diff --git a/.bazelignore b/.bazelignore
new file mode 100644
index 0000000..d838da9
--- /dev/null
+++ b/.bazelignore
@@ -0,0 +1 @@
+examples/
diff --git a/examples/basic_usage/BUILD.bazel b/examples/basic_usage/BUILD.bazel
new file mode 100644
index 0000000..6517265
--- /dev/null
+++ b/examples/basic_usage/BUILD.bazel
@@ -0,0 +1,20 @@
+# Copyright 2024 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This is enumerated as a test to ensure it is run and doesn't crash/fail.
+cc_test(
+    name = "example",
+    srcs = ["main.cc"],
+    deps = ["@libusb//:libusb"],
+)
diff --git a/examples/basic_usage/MODULE.bazel b/examples/basic_usage/MODULE.bazel
new file mode 100644
index 0000000..f98ebee
--- /dev/null
+++ b/examples/basic_usage/MODULE.bazel
@@ -0,0 +1,13 @@
+module(name = "rules_libusb_basic_example")
+
+bazel_dep(name = "rules_libusb")
+
+# DO NOT copy this into your project. This allows this repository to reference
+# itself.
+local_path_override(
+    module_name = "rules_libusb",
+    path = "../..",
+)
+
+libusb = use_extension("@rules_libusb//:extensions.bzl", "libusb")
+use_repo(libusb, "libusb")
diff --git a/examples/basic_usage/main.cc b/examples/basic_usage/main.cc
new file mode 100644
index 0000000..c5f47ca
--- /dev/null
+++ b/examples/basic_usage/main.cc
@@ -0,0 +1,36 @@
+// Copyright 2024 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#include <cstdio>
+
+#include "libusb.h"
+
+int main() {
+    libusb_device** devs;
+    if (libusb_init(nullptr) < 0) {
+        printf("Error: Failed to initialize libusb\n");
+        return 1;
+    }
+
+    ssize_t device_count = libusb_get_device_list(nullptr, &devs);
+    if (device_count < 0) {
+        printf("Error: Failed to enumerate devices\n");
+        return 1;
+    }
+    printf("%d devices attached\n", static_cast<int>(device_count));
+
+    libusb_free_device_list(devs, 1);
+    libusb_exit(nullptr);
+    return 0;
+}