NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
345 stars 143 forks source link

Create instructions for FreeBSD to cross-compile on an Ubuntu target #173

Closed madhephaestus closed 3 years ago

madhephaestus commented 4 years ago

The intent is to get all of the cross-compileing to take place in CI. It would be nice for the CI to take care of the task of cross compiling all of the toolchains and placing binaries in the staging branch automatically.

RafalLukawiecki commented 4 years ago

Adding your original instructions: https://marcelog.github.io/articles/cross_freebsd_compiler_in_linux.html

If the FreeBSD cross-compiler were to be set-up, would it need its own repository, or would it live inside this one? Do you use an external environment for the build process, if so, where is it?

madhephaestus commented 4 years ago

the goal would be to make a shell script that gets called by the Freebsd make target that auto-downloads the tool and sets it up. Then it calls the compiler out of the folder it just created. I usually do this all with apt commands to install pre-packaged tools for the arm compiles. This may need to be a bit more elaborate for the freebsd build.

MrDOS commented 4 years ago

I took a look on Docker Hub and found two existing FreeBSD cross-compilation environments, but neither worked for this project: both of them had a broken termios.h header.

By following a couple different FreeBSD cross-compiler guides (primarily the one linked above) and referencing the two existing FreeBSD cross-compilation environments on Docker Hub (which also seem to be based on that same guide), I've built my own Docker container which works well for our purpose. Based on my updated .travis.yml from #189:

$ docker pull empterdose/freebsd-cross-build:9.3
$ cd /path/to/nrjavaserial
$ export JAVA_HOME=/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64 # or wherever
$ docker run --interactive \
             --tty \
             --detach \
             --rm \
             --user $(id --user):$(id --group) \
             --name build \
             --env JAVA_HOME=$JAVA_HOME \
             --volume $(pwd):/build \
             --volume $JAVA_HOME:$JAVA_HOME \
             --volume $JAVA_HOME/include/linux:$JAVA_HOME/include/freebsd \
             empterdose/freebsd-cross-build:9.3
$ docker exec build make -C /build/src/main/c clean-freebsd
$ docker exec build settarget i386-freebsd9 make -C /build/src/main/c -j freebsd32
$ docker exec build settarget x86_64-freebsd9 make -C /build/src/main/c -j freebsd64

Note that this will only work on my refactor-native-builds branch until that gets merged into master: besides the fact the current native makefile has no clean-freebsd target, its FreeBSD targets don't use the CC environment variable, so it's not possible to override which compiler they use to build/link.

Do you really want this invocation to be scripted from within the repo? IMHO, if CI will cross-compile all the libraries and put them somewhere they can be easily downloaded, I think most developers hacking on the native code will probably prefer to compile locally for their native platform and get Travis to build the rest.

MrDOS commented 3 years ago

Resolved by #189.