Skip to content

Commit 6d4464c

Browse files
committed
Refactor cross compiling + update README.
1 parent 472a273 commit 6d4464c

24 files changed

+323
-190
lines changed

.cargo/config.toml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
[target.aarch64-unknown-linux-musl]
2+
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc", "-L", "native=/usr/local/aarch64-linux-musl-target/lib", "-l", "static=stdc++"]
3+
4+
[target.armv7-unknown-linux-musleabihf]
5+
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc", "-L", "native=/usr/local/arm-linux-musleabihf-target/lib", "-l", "static=stdc++"]
6+
17
[target.mips-unknown-linux-musl]
2-
linker = "mips-linux-muslsf-cc"
3-
# https://github.com/rust-lang/rust/issues/80693
4-
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc"]
8+
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc", "-L", "native=/usr/local/mips-linux-muslsf-target/lib", "-l", "static=stdc++"]
59

6-
[target.armv5te-unknown-linux-gnueabi]
7-
linker = "arm-linux-gnueabi-gcc"
10+
[target.armv5te-unknown-linux-musleabi]
811
# Workaround for:
912
# https://github.com/rust-lang/compiler-builtins/issues/420
10-
rustflags = ["-C", "link-arg=-Wl,--allow-multiple-definition"]
11-
12-
[target.armv7-unknown-linux-gnueabihf]
13-
linker = "arm-linux-gnueabihf-gcc"
14-
15-
[target.aarch64-unknown-linux-gnu]
16-
linker = "aarch64-linux-gnu-gcc"
13+
rustflags = ["-C", "link-arg=-Wl,--allow-multiple-definition", "-C", "target-feature=+crt-static", "-C", "link-arg=-s", "-C", "link-arg=-lc", "-C", "link-arg=-lgcc", "-L", "native=/usr/local/arm-linux-musleabi-target/lib", "-l", "static=stdc++"]

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Testing
2+
TEST_MQTT_BROKER_URL="tcp://localhost:1883"

.github/workflows/main.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ jobs:
1414
-
1515
name: Checkout
1616
uses: actions/checkout@v2
17+
-
18+
name: Install Nix
19+
uses: cachix/install-nix-action@v20
20+
with:
21+
nix_path: nixpkgs=channel:nixos-22.11
1722
-
1823
name: Cargo cache
1924
uses: actions/cache@v3
2025
with:
21-
path: .rust/
22-
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
26+
path: |
27+
~/.cargo/bin/
28+
~/.cargo/registry/index/
29+
~/.cargo/registry/cache/
30+
~/.cargo/git/db/
31+
target/
32+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
2333
-
24-
name: Run tests
25-
run: make test
34+
name: Start dependency services
35+
run: docker-compose up -d
2636
-
27-
name: Make cache accessible to caching action
28-
run: |
29-
sudo chown $(whoami):$(whoami) -R .rust
37+
name: Run tests
38+
run: nix-shell --command "make test"
3039

3140
dist:
3241
needs: tests
@@ -36,15 +45,25 @@ jobs:
3645
-
3746
name: Checkout
3847
uses: actions/checkout@v2
48+
-
49+
name: Install Nix
50+
uses: cachix/install-nix-action@v20
51+
with:
52+
nix_path: nixpkgs=channel:nixos-22.11
3953
-
4054
name: Cargo cache
4155
uses: actions/cache@v3
4256
with:
43-
path: .rust/
44-
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
57+
path: |
58+
~/.cargo/bin/
59+
~/.cargo/registry/index/
60+
~/.cargo/registry/cache/
61+
~/.cargo/git/db/
62+
target/
63+
key: ${{ runner.os }}-cargo-dist-${{ hashFiles('**/Cargo.lock') }}
4564
-
4665
name: Build distributables
47-
run: make dist
66+
run: nix-shell --command "make dist"
4867
-
4968
name: Configure AWS credentials
5069
uses: aws-actions/configure-aws-credentials@v1
@@ -57,7 +76,3 @@ jobs:
5776
run: |
5877
aws s3 sync dist s3://builds.loraserver.io/chirpstack-mqtt-forwarder
5978
if: startsWith(github.ref, 'refs/tags/v')
60-
-
61-
name: Make cache accessible to caching action
62-
run: |
63-
sudo chown $(whoami):$(whoami) -R .rust

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Hidden files
22
.*
3+
!.cargo
4+
!.github
5+
!.vscode
6+
!.env
37

48
# Config files
5-
/*.toml
9+
chirpstack-mqtt-forwarder.toml
610

711
# Rust target directory
812
/target
913

1014
# IPK packages
1115
*.ipk
1216
/dist
13-
14-
# Exclude from gitignore
15-
!/.github
16-
!/.cargo

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix"
3+
}

Cargo.lock

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ hex = "0.4"
3535
base64 = "0.21"
3636
rand = "0.8"
3737
pbjson-types = "0.5"
38-
paho-mqtt = { version = "0.12", features = ["vendored-ssl", "build_bindgen"] }
38+
paho-mqtt = { version = "0.12", features = ["ssl", "build_bindgen"] }
3939
handlebars = "4.3"
4040
tokio = { version = "1.27", features = [
4141
"macros",
@@ -50,6 +50,9 @@ futures = "0.3"
5050
async-trait = "0.1"
5151
zmq = { version = "0.10", optional = true }
5252

53+
[dev-dependencies]
54+
dotenv = "0.15"
55+
5356
[features]
5457
default = ["semtech_udp", "concentratord"]
5558
semtech_udp = []

Cross.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.aarch64-unknown-linux-musl]
2+
dockerfile="cross/Dockerfile.aarch64-unknown-linux-musl"
3+
4+
[target.armv7-unknown-linux-musleabihf]
5+
dockerfile="cross/Dockerfile.armv7-unknown-linux-musleabihf"
6+
7+
[target.mips-unknown-linux-musl]
8+
dockerfile="cross/Dockerfile.mips-unknown-linux-musl"
9+
10+
[target.armv5te-unknown-linux-musleabi]
11+
dockerfile="cross/Dockerfile.armv5te-unknown-linux-musleabi"

Dockerfile-devel

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,6 @@
1-
# FROM rust:1.65.0-buster
2-
# Unfortunately we can not use the above, as it would compile against a libc
3-
# version (2.28) which is not supported by all gateways yet. Below is the
4-
# source of the Rust image based on Buster, but then using Stretch.
5-
6-
FROM buildpack-deps:stretch
7-
8-
ENV RUSTUP_HOME=/usr/local/rustup \
9-
CARGO_HOME=/usr/local/cargo \
10-
PATH=/usr/local/cargo/bin:$PATH \
11-
RUST_VERSION=1.68.2
12-
13-
RUN set -eux; \
14-
dpkgArch="$(dpkg --print-architecture)"; \
15-
case "${dpkgArch##*-}" in \
16-
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='bb31eaf643926b2ee9f4d8d6fc0e2835e03c0a60f34d324048aa194f0b29a71c' ;; \
17-
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='6626b90205d7fe7058754c8e993b7efd91dedc6833a11a225b296b7c2941194f' ;; \
18-
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='4ccaa7de6b8be1569f6b764acc28e84f5eca342f5162cd5c810891bff7ed7f74' ;; \
19-
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='34392b53a25c56435b411d3e575b63aab962034dd1409ba405e708610c829607' ;; \
20-
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
21-
esac; \
22-
url="https://static.rust-lang.org/rustup/archive/1.25.2/${rustArch}/rustup-init"; \
23-
wget "$url"; \
24-
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
25-
chmod +x rustup-init; \
26-
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
27-
rm rustup-init; \
28-
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
29-
rustup --version; \
30-
cargo --version; \
31-
rustc --version;
32-
1+
FROM nixos/nix
332

343
ENV PROJECT_PATH=/chirpstack-mqtt-forwarder
35-
RUN mkdir -p $PROJECT_PATH
36-
37-
RUN apt-get update && \
38-
apt-get install -y \
39-
make \
40-
cmake \
41-
clang-11 \
42-
libclang-11-dev \
43-
llvm-dev \
44-
musl-dev \
45-
git \
46-
bash \
47-
protobuf-compiler \
48-
libprotobuf-dev \
49-
jq \
50-
gcc-arm-linux-gnueabi \
51-
g++-arm-linux-gnueabi \
52-
gcc-arm-linux-gnueabihf \
53-
g++-arm-linux-gnueabihf \
54-
gcc-aarch64-linux-gnu \
55-
g++-aarch64-linux-gnu
56-
57-
RUN cargo install cargo-bitbake
58-
RUN cargo install cargo-bloat
59-
60-
# Install musl cross toolchain for mips
61-
# 1.1.24 is the musl version bundled with Rust:
62-
# https://github.com/rust-lang/rust/blob/master/src/ci/docker/scripts/musl.sh#L28
63-
RUN git clone https://github.com/richfelker/musl-cross-make.git /opt/musl-cross-make
64-
RUN echo '\
65-
TARGET = mips-linux-muslsf\n\
66-
OUTPUT = /opt/mips-linux-muslsf\n\
67-
MUSL_VER = 1.1.24\n\
68-
'\
69-
>> /opt/musl-cross-make/config.mak
70-
RUN cd /opt/musl-cross-make && make && make install
71-
72-
# Install opkg-utils
73-
RUN git clone git://git.yoctoproject.org/opkg-utils /opt/opkg-utils && \
74-
cd /opt/opkg-utils && \
75-
make install
76-
774
WORKDIR $PROJECT_PATH
5+
6+
ENTRYPOINT ["nix-shell"]

0 commit comments

Comments
 (0)