Skip to content
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

Build libusb out of tree build #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ if available.

You can also install from a clone of the git repository by running `pip install .` from the repository root directory.
Editable installs are supported. Please note that running `setup.py` directly is no longer supported for PEP 517
compliant packages. When building from the repo, because libusb 1.0.24 does not support out of tree builds, the build is
done in-place in the `src/libusb` directory. `make clean` is run before compiling to ensure a clean build.
compliant packages. Building libusb is done out of tree in an automatically created build directory for libusb 1.0.25
and later.


## APIs
Expand All @@ -42,7 +42,7 @@ There are four public functions exported by `libusb_package`.

- `find(*args, **kwargs)`: Wrapper around pyusb's `usb.core.find()` that sets the `backend`
parameter to a libusb1 backend created from the libusb library included in `libusb_package`.
All other parameters are passed unmodified
All other parameters are passed unmodified.

- `get_libusb1_backend()`: Returns a `pyusb` backend object for the libusb version contained
in `libusb_package`.
Expand Down
4 changes: 2 additions & 2 deletions scripts/vsenv.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rem From: https://renenyffenegger.ch/notes/development/tools/scripts/personal/vsenv_bat

@echo off

rem From: https://renenyffenegger.ch/notes/development/tools/scripts/personal/vsenv_bat

rem
rem Uncomment setting VSCMD_DEBUG to enable debugging to output
rem
Expand Down
25 changes: 16 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2021-2022 Chris Reed
# Copyright (c) 2022 Mitchell Kline
#
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -97,12 +97,10 @@ def run(self):
build_lib = ROOT_DIR / Path(build_py.get_package_dir(PACKAGE_NAME)).parent
else:
build_lib = Path(os.path.abspath(self.build_lib))
# build_temp = Path(os.path.abspath(self.build_temp))

# Build in-tree for the time being. libusb commit 1001cb5 adds support for out of tree builds, but
# this is not yet supported in an existing release. Once libusb version 1.0.25 is released, we can
# build out of tree.
build_temp = LIBUSB_DIR
# Build out of tree. Requires libusb commit 1001cb5 which adds support for out of tree builds, present
# in libusb 1.0.25 and later.
build_temp = Path(os.path.abspath(self.build_temp))

print(f"build_temp = {build_temp}")
print(f"build_lib = {build_lib}")
Expand Down Expand Up @@ -156,7 +154,6 @@ def run(self):
self.spawn(['env']) # Dump environment for debugging purposes.
self.spawn(['bash', str(BOOTSTRAP_SCRIPT)])
self.spawn(['bash', str(CONFIGURE_SCRIPT), *extra_configure_args])
self.spawn(['make', 'clean'])
self.spawn(['make', f'-j{os.cpu_count() or 4}', 'all'])
except Exception as err:
# Exception is caught here and reraised as our specific Exception class because the actual
Expand All @@ -178,10 +175,20 @@ def run(self):
else:
platform = "x64" if IS_64_BIT else "x86"
config = "Release"
properties = {
"Configuration": config,
"Platform": platform,
"IntermediateOutputPath": str(build_temp / platform / "obj") + "\\", # Must end with trailing slash.
"OutDir": str(build_temp / platform / config) + "\\",
#IntermediateOutputPath
#OutputPath
}

property_values = ';'.join(f'{k}={v}' for k, v in properties.items())
msbuild_cmd = f'msbuild -p:{property_values} {VS_PROJ}'

try:
self.spawn(['cmd.exe', '/c', f'{VSENV_SCRIPT} && '
f'msbuild -p:Configuration={config} -p:Platform={platform} {VS_PROJ}'])
self.spawn(['cmd.exe', '/c', f'{VSENV_SCRIPT} && {msbuild_cmd}'])
except Exception as err:
# See comment above for notes about this exception handler.
raise LibusbBuildError(str(err)) from err
Expand Down