Add libusb package (#56)
This commit is contained in:
52
libusb/build.sh
Executable file
52
libusb/build.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
|
VERSION="1.0.29"
|
||||||
|
ARCHIVE="libusb-${VERSION}.tar.bz2"
|
||||||
|
URL="https://github.com/libusb/libusb/releases/download/v${VERSION}/${ARCHIVE}"
|
||||||
|
INSTALL_DIR="$DIR/libusb/install"
|
||||||
|
SRC_DIR="$DIR/libusb-src"
|
||||||
|
VERSION_FILE="$SRC_DIR/.version"
|
||||||
|
|
||||||
|
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
|
||||||
|
export CC="ccache ${CC:-cc}"
|
||||||
|
|
||||||
|
if [ ! -f "$VERSION_FILE" ] || [ "$(cat "$VERSION_FILE")" != "$VERSION" ]; then
|
||||||
|
rm -rf "$SRC_DIR"
|
||||||
|
mkdir -p "$SRC_DIR"
|
||||||
|
curl -fSL "$URL" | tar xj --strip-components=1 -C "$SRC_DIR"
|
||||||
|
echo "$VERSION" > "$VERSION_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PREFIX="$DIR/build/prefix"
|
||||||
|
rm -rf "$DIR/build"
|
||||||
|
mkdir -p "$DIR/build"
|
||||||
|
|
||||||
|
CONFIGURE_ARGS=(
|
||||||
|
--prefix="$PREFIX"
|
||||||
|
--disable-shared
|
||||||
|
--enable-static
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ "$(uname)" = "Linux" ]; then
|
||||||
|
CONFIGURE_ARGS+=(--disable-udev)
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$SRC_DIR"
|
||||||
|
CFLAGS="-O2 -fPIC" ./configure "${CONFIGURE_ARGS[@]}"
|
||||||
|
make -j"$NJOBS"
|
||||||
|
make install
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
|
rm -rf "$INSTALL_DIR"
|
||||||
|
mkdir -p "$INSTALL_DIR/lib/pkgconfig" "$INSTALL_DIR/include/libusb-1.0"
|
||||||
|
|
||||||
|
cp "$PREFIX/lib/libusb-1.0.a" "$INSTALL_DIR/lib/"
|
||||||
|
cp "$PREFIX/lib/pkgconfig/libusb-1.0.pc" "$INSTALL_DIR/lib/pkgconfig/"
|
||||||
|
cp "$PREFIX/include/libusb-1.0/libusb.h" "$INSTALL_DIR/include/libusb-1.0/"
|
||||||
|
|
||||||
|
echo "Installed libusb to $INSTALL_DIR"
|
||||||
|
du -sh "$INSTALL_DIR"
|
||||||
12
libusb/libusb/__init__.py
Normal file
12
libusb/libusb/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
DIR = os.path.join(os.path.dirname(__file__), "install")
|
||||||
|
LIB_DIR = os.path.join(DIR, "lib")
|
||||||
|
INCLUDE_DIR = os.path.join(DIR, "include")
|
||||||
|
PKGCONFIG_DIR = os.path.join(LIB_DIR, "pkgconfig")
|
||||||
|
|
||||||
|
|
||||||
|
def smoketest():
|
||||||
|
assert os.path.isfile(os.path.join(LIB_DIR, "libusb-1.0.a")), "libusb-1.0.a not found"
|
||||||
|
assert os.path.isfile(os.path.join(INCLUDE_DIR, "libusb-1.0", "libusb.h")), "libusb.h not found"
|
||||||
|
assert os.path.isfile(os.path.join(PKGCONFIG_DIR, "libusb-1.0.pc")), "libusb-1.0.pc not found"
|
||||||
15
libusb/pyproject.toml
Normal file
15
libusb/pyproject.toml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=64", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "libusb"
|
||||||
|
version = "1.0.29"
|
||||||
|
description = "libusb USB device access library (static build)"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
include = ["libusb*"]
|
||||||
|
|
||||||
|
[tool.setuptools.package-data]
|
||||||
|
libusb = ["install/**/*"]
|
||||||
58
libusb/setup.py
Normal file
58
libusb/setup.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from setuptools.command.build_py import build_py
|
||||||
|
|
||||||
|
try:
|
||||||
|
from wheel.bdist_wheel import bdist_wheel
|
||||||
|
except ImportError:
|
||||||
|
bdist_wheel = None
|
||||||
|
|
||||||
|
|
||||||
|
class BuildLibusb(build_py):
|
||||||
|
"""Run build.sh to compile libusb before collecting package data."""
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
build_script = os.path.join(pkg_dir, "build.sh")
|
||||||
|
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
|
||||||
|
|
||||||
|
super().run()
|
||||||
|
|
||||||
|
|
||||||
|
cmdclass = {"build_py": BuildLibusb}
|
||||||
|
|
||||||
|
if bdist_wheel is not None:
|
||||||
|
|
||||||
|
class PlatformWheel(bdist_wheel):
|
||||||
|
"""Produce a platform-specific, Python-version-agnostic wheel."""
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
super().finalize_options()
|
||||||
|
self.root_is_pure = False
|
||||||
|
|
||||||
|
def get_tag(self):
|
||||||
|
system = platform.system()
|
||||||
|
machine = platform.machine()
|
||||||
|
|
||||||
|
if system == "Linux":
|
||||||
|
plat = f"linux_{machine}"
|
||||||
|
elif system == "Darwin":
|
||||||
|
plat = "macosx_11_0_arm64"
|
||||||
|
else:
|
||||||
|
plat = f"{system.lower()}_{machine}"
|
||||||
|
|
||||||
|
return "py3", "none", plat
|
||||||
|
|
||||||
|
cmdclass["bdist_wheel"] = PlatformWheel
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
from setuptools import setup as _setup
|
||||||
|
|
||||||
|
_setup(cmdclass=cmdclass)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
setup()
|
||||||
@@ -9,6 +9,7 @@ members = [
|
|||||||
"git-lfs",
|
"git-lfs",
|
||||||
"imgui",
|
"imgui",
|
||||||
"json11",
|
"json11",
|
||||||
|
"libusb",
|
||||||
"libjpeg",
|
"libjpeg",
|
||||||
"libyuv",
|
"libyuv",
|
||||||
"nanosvg",
|
"nanosvg",
|
||||||
|
|||||||
Reference in New Issue
Block a user