xobs / wishbone-utils

Utilities for working with a Wishbone bridge
9 stars 5 forks source link

libusb-sys: build native libusb on FreeBSD #9

Closed kevans91 closed 4 years ago

kevans91 commented 4 years ago

FreeBSD maintains a libusb that is compatible with the libusb used everywhere else. Upstream for libusb-sys uses pkgconf for this, which 'just works' and grabs -lusb from the base system.

Further research after my previous PR seems to indicate that wishbone-tool specifically vendored libusb in the libusb-sys build, so add the build glue for FreeBSD libusb to the build. With this, wishbone-tool can successfully build.

Signed-off-by: Kyle Evans kevans@FreeBSD.org

xobs commented 4 years ago

If libusb-sys uses this, and if it builds for you, then that's good enough for me.

kevans91 commented 4 years ago

If libusb-sys uses this, and if it builds for you, then that's good enough for me.

Hmm... to be clear, this is specifically equivalent to what https://github.com/dcuddeback/libusb-sys does. I see in another PR that this version of libusb-sys was actually from https://github.com/paritytech/libusb-sys/, which was forked from the former and vendored libusb- that version doesn't take this approach at this time.

xobs commented 4 years ago

The Travis freebsd build servers don't seem to have those files installed: https://travis-ci.org/xobs/wishbone-utils/jobs/633096803

error: failed to run custom build command for `libusb-sys v0.2.5 (/home/travis/build/xobs/wishbone-utils/wishbone-tool/libusb-sys)`

Caused by:

  process didn't exit successfully: `/home/travis/build/xobs/wishbone-utils/wishbone-tool/target/debug/build/libusb-sys-fee4db3ff7ed92dd/build-script-build` (exit code: 101)

--- stdout

TARGET = Some("x86_64-unknown-freebsd")

OPT_LEVEL = Some("0")

HOST = Some("x86_64-unknown-linux-gnu")

CC_x86_64-unknown-freebsd = None

CC_x86_64_unknown_freebsd = None

TARGET_CC = None

CC = None

CROSS_COMPILE = None

CFLAGS_x86_64-unknown-freebsd = None

CFLAGS_x86_64_unknown_freebsd = None

TARGET_CFLAGS = None

CFLAGS = None

CRATE_CC_NO_DEFAULTS = None

DEBUG = Some("true")

CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/home/travis/build/xobs/wishbone-utils/wishbone-tool/target/x86_64-unknown-freebsd/debug/build/libusb-sys-c70b8e1836f9ce52/out/libusb20.o" "-c" "/usr/src/lib/libusb/libusb20.c"

cargo:warning=cc: error: /usr/src/lib/libusb/libusb20.c: No such file or directory

cargo:warning=cc: fatal error: no input files

cargo:warning=compilation terminated.

exit code: 4

--- stderr

thread 'main' panicked at '

Internal error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/home/travis/build/xobs/wishbone-utils/wishbone-tool/target/x86_64-unknown-freebsd/debug/build/libusb-sys-c70b8e1836f9ce52/out/libusb20.o" "-c" "/usr/src/lib/libusb/libusb20.c" with args "cc" did not execute successfully (status code exit code: 4).

', /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.35/src/lib.rs:2398:5

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

The dcuddeback/libusb-sys library was last updated in 2016, and seems mostly dead. paritytech/libusb-sys seemed to be the most up-to-date, and worked for my purposes. It required a small patch on Windows, but in order to get it merged I had to sign over my worldwide patent rights to that company.

Do I need to install something prior to building?

kevans91 commented 4 years ago

I submitted another PR to just import our libusb source. Change velocity is incredibly low, and I wouldn't anticipate any problems with keeping it in-tree just as you do with the other libusb. All of the dependencies should be there now, but we'll see what Travis says.

xobs commented 4 years ago

Alright, I moved them into a freebsd subdirectory. The proper way would probably be to pull the latest version of libusb, but this'll work for now.

kevans91 commented 4 years ago

https://github.com/xobs/wishbone-utils/blob/master/wishbone-tool/libusb-sys/build.rs#L17 -> this line will need a change from "." to "freebsd" to match. =-)

Unfortunately we (for some reason, that I don't understand) don't hold much stock in porting the actual libusb to FreeBSD, unlike almost every other platform, so even the latest doesn't support us. =(

xobs commented 4 years ago

Good catch. For some reason that file didn't checked in!

kevans91 commented 4 years ago

I'm poking around Travis stuff now to figure out how this happens:

cargo:warning=In file included from /usr/include/ctype.h:25:0,
cargo:warning=                 from freebsd/lib/libusb/libusb20.c:32:
cargo:warning=/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory
cargo:warning= #  include <sys/cdefs.h>

That doesn't feel like a functional build environment, and seems like a minimum if you're offering images that people can build stuff in. =\

xobs commented 4 years ago

It looks like it's cross-compiling on Linux, which could be part of the problem.

Let me disable the other builds to decrease the latency, and try to figure out what's going on here...

kevans91 commented 4 years ago

Ahh, that would make sense. I'd be tempted to push FreeBSD CI over to Cirrus, which also does GitHub integration, but I can understand if you'd rather not have yet another CI solution.