Skip to content

Commit a3f8614

Browse files
authored
Merge pull request #3 from opensight-cv/feature/better-cross
Improve cross compilation process
2 parents a586f32 + 2afbe03 commit a3f8614

File tree

8 files changed

+160
-48
lines changed

8 files changed

+160
-48
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515

1616
# End of https://www.gitignore.io/api/rust
1717

18-
docker/qemu-arm-static
18+
# Debian packaging materials
19+
pkg-debian/usr
20+
pkg-debian/DEBIAN/md5sums
21+
!pkg-debian/DEBIAN/control
22+
# built Debian packages
23+
*.deb

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ addons:
1313
update: true
1414
arch:
1515
- amd64
16-
- arm64 # while this technically isn't the RPi4 it's a nice proof of concept
16+
- arm64
1717
cache: cargo
1818
before_deploy:
1919
- cargo deb

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM ubuntu:18.04
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
5+
# use ports.ubuntu.com
6+
RUN sed 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch-=amd64,i386] http:\/\/ports.ubuntu.com\/ubuntu-ports\//g' /etc/apt/sources.list > /etc/apt/sources.list.d/ports.list
7+
RUN sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list
8+
RUN dpkg --add-architecture armhf
9+
RUN apt-get -y update
10+
# basic build tools
11+
RUN apt-get install --assume-yes --no-install-recommends \
12+
autoconf \
13+
automake \
14+
binutils \
15+
ca-certificates \
16+
curl \
17+
file \
18+
gcc \
19+
g++ \
20+
git \
21+
libc6-dev \
22+
libtool \
23+
m4 \
24+
make \
25+
pkg-config
26+
27+
# cross-compiler chain
28+
RUN apt-get install --assume-yes --no-install-recommends \
29+
g++-arm-linux-gnueabihf \
30+
libc6-dev-armhf-cross
31+
ENV PKG_CONFIG_ALLOW_CROSS 1
32+
ENV PKG_CONFIG_PATH "${PKG_CONFIG_PATH}:/usr/lib/arm-linux-gnueabihf/pkgconfig"
33+
ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc
34+
35+
# gstreamer
36+
RUN apt-get install --no-install-recommends -yq libgstreamer1.0-dev:armhf \
37+
libgstreamer-plugins-base1.0-dev:armhf \
38+
gstreamer1.0-plugins-base:armhf \
39+
gstreamer1.0-plugins-good:armhf \
40+
gstreamer1.0-plugins-bad:armhf \
41+
gstreamer1.0-plugins-ugly:armhf \
42+
gstreamer1.0-libav:armhf \
43+
libgstrtspserver-1.0-dev:armhf

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ sudo apt update && sudo apt install libgstreamer1.0-dev \
1919
## Cross-Compiling for Raspberry Pi
2020
(because Travis won't give ARM 32 VMs...)
2121

22-
Running `cross-build.sh` with [`cross`](https://github.com/rust-embedded/cross) and `qemu-arm-static` installed should (eventually) produce an ARM 32 executable file suitable for use with Raspbian in `target/arm7-unknown-linux-gnueabihf/release`.
22+
Running `cross-build.sh` with [`cross`](https://github.com/rust-embedded/cross) and Docker installed should (eventually) produce an ARM 32 executable file suitable for use with Raspbian in `target/arm7-unknown-linux-gnueabihf/release`.
2323

24-
This takes a long, long time thanks to the involvement of Docker and QEMU. Building on real hardware is probably faster and saner.
24+
If you want an installable `.deb` file, run `deb-pack.sh` **after running `cross-build.sh`.** You need `dpkg` to run `deb-pack.sh`.
25+
26+
However, `rusty-engine` is not incredibly heavyweight and can almost certainly be compiled on your Pi without the use of any particular configuration beyond [installing the dependencies.](#dependencies)
2527

2628
Licensing
2729
---

cross-build.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,8 @@ if ! ${DOCKER} ps >/dev/null; then
1111
${DOCKER} ps
1212
exit 1
1313
fi
14-
# bind last argument in portable manner
15-
for last in "$@"; do :; done
1614

17-
docker_qemu="docker/qemu-arm-static"
18-
rm -f ${docker_qemu}
19-
cp "$(which qemu-arm-static)" ${docker_qemu}
2015
# build image
21-
${DOCKER} build -t rusty-engine:latest docker/
22-
rm ${docker_qemu}
16+
${DOCKER} build -t rusty-engine:latest .
2317

24-
if [ "${last}" == "run" ]; then
25-
cross build --target armv7-unknown-linux-gnueabihf --release
26-
${DOCKER} run --rm --privileged \
27-
--volume "$(pwd)":/docking-bay \
28-
rusty-engine:latest \
29-
bash -e -o pipefail -c \
30-
"cd /docking-bay; cargo deb"
31-
fi
18+
cross build --release --target armv7-unknown-linux-gnueabihf

deb-pack.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
for last in "$@"; do :; done
5+
6+
if [ "${last}" == "clean" ]; then
7+
rm pkg-debian/DEBIAN/md5sums
8+
rm -rf pkg-debian/usr
9+
exit
10+
fi
11+
12+
mkdir -p pkg-debian/usr/bin
13+
mkdir -p pkg-debian/usr/share/doc/rusty-engine
14+
15+
# copy files into place
16+
cp ./target/armv7-unknown-linux-gnueabihf/release/rusty-engine pkg-debian/usr/bin
17+
cp ./README.md pkg-debian/usr/share/doc/rusty-engine
18+
cat > pkg-debian/usr/share/doc/rusty-engine/copyright <<EOF
19+
Upstream Name: rusty-engine
20+
Source: https://github.com/opensight-cv/rusty-engine
21+
Copyright: Caleb Xavier Berger <caleb.x.berger@gmail.com>
22+
License: MIT
23+
MIT License
24+
.
25+
Copyright (c) 2020 OpenSight contributors
26+
.
27+
Permission is hereby granted, free of charge, to any person obtaining a copy
28+
of this software and associated documentation files (the "Software"), to deal
29+
in the Software without restriction, including without limitation the rights
30+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31+
copies of the Software, and to permit persons to whom the Software is
32+
furnished to do so, subject to the following conditions:
33+
.
34+
The above copyright notice and this permission notice shall be included in all
35+
copies or substantial portions of the Software.
36+
.
37+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43+
SOFTWARE.
44+
.
45+
EOF
46+
47+
48+
cd pkg-debian
49+
find . -type f ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' -printf '%P ' | xargs md5sum > DEBIAN/md5sums
50+
cd ..
51+
dpkg -b pkg-debian/ rusty-engine_0.2.3_armhf.deb

docker/Dockerfile

Lines changed: 0 additions & 29 deletions
This file was deleted.

pkg-debian/DEBIAN/control

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Package: rusty-engine
2+
Version: 0.2.2
3+
Architecture: amd64
4+
Vcs-Browser: https://github.com/opensight-cv/rusty-engine
5+
Vcs-Git: https://github.com/opensight-cv/rusty-engine
6+
Priority: optional
7+
Standards-Version: 3.9.4
8+
Maintainer: Caleb Xavier Berger <caleb.x.berger@gmail.com>
9+
Installed-Size: 897
10+
Depends: gstreamer1.0-plugins-bad (>=1.14.4-1), libgstrtspserver-1.0-0 (>=1.14.4-1), gstreamer1.0-plugins-ugly (>=1.14.4-1), gstreamer1.0-plugins-good (>=1.14.4-1)
11+
Description: Rust reimagining of potential-engine
12+
`rusty-engine`
13+
===
14+
:gear::steam_locomotive:
15+
.
16+
`rusty-engine` is a Rust rewrite/redesign/reimagining of The Quadrangles'
17+
[`potential-engine` RTSP server. ](https://github.com/BHSSFRC/potential-engine)
18+
`rusty-engine` aims to be more easily extensible and added to from a developer
19+
standpoint, while Rust helps to cover most of the corner cases and ensure
20+
everything fits together. (It's also just plainly more accessible to a novice
21+
than C/C++.)
22+
.
23+
## Dependencies
24+
Aside from what `cargo` grabs automatically, `rusty-engine` requires some C
25+
packages to link to GStreamer. On Debian and Debian derivatives, these can be
26+
fetched with the following `apt` command:
27+
```bash
28+
sudo apt update && sudo apt install libgstreamer1.0-dev \
29+
libgstreamer-plugins-base1.0-dev \
30+
gstreamer1.0-plugins-base \
31+
gstreamer1.0-plugins-good \
32+
gstreamer1.0-plugins-bad \
33+
gstreamer1.0-plugins-ugly \
34+
gstreamer1.0-libav \
35+
libgstrtspserver-1.0-dev
36+
```
37+
## Cross-Compiling for Raspberry Pi
38+
(because Travis won't give ARM 32 VMs...)
39+
.
40+
Running `cross-build.sh` with [`cross`](https://github.com/rust-embedded/cross)
41+
and `qemu-arm-static` installed should (eventually) produce an ARM 32
42+
executable file suitable for use with Raspbian in
43+
`target/arm7-unknown-linux-gnueabihf/release`.
44+
.
45+
This takes a long, long time thanks to the involvement of Docker and QEMU.
46+
Building on real hardware is probably faster and saner.
47+
.
48+
Licensing
49+
---
50+
`rusty-engine` is made available under the MIT license. While it uses
51+
proprietary codecs, it interacts with these at arm's length via Gstreamer and
52+
does not include any implementation of an H.264 encoder or other proprietary
53+
encoders in itself.

0 commit comments

Comments
 (0)