-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathEarthfile
More file actions
169 lines (136 loc) · 7.23 KB
/
Earthfile
File metadata and controls
169 lines (136 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
VERSION 0.8
ARG --global debian = bookworm
# Using commit hash pinning because git tags can be changed
# Ref: https://github.com/earthly/lib/tree/3.0.3
IMPORT github.com/earthly/lib/rust:a49d2a0f4028cd15666d19904f8fc5fbd0b9ba87 AS lib-rust
install-build-dependencies:
FROM rust:1.95.0-$debian
WORKDIR /lightway
RUN dpkg --add-architecture arm64
RUN apt-get update -qq
RUN apt-get install --no-install-recommends -qq \
autoconf \
autotools-dev \
bsdmainutils \
clang \
cmake \
g++-aarch64-linux-gnu \
libc6:arm64 \
libtool-bin \
qemu-user-static \
shellcheck \
g++-riscv64-linux-gnu \
gcc-riscv64-linux-gnu
# Note this must be done before `lib-rust+INIT` overrides `$CARGO_HOME`.
RUN rustup toolchain install nightly
DO lib-rust+INIT --keep_fingerprints=true
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/refs/tags/v1.17.8/install-from-binstall-release.sh | bash
DO lib-rust+CARGO --args="binstall --no-confirm cargo-deny cargo-llvm-cov cargo-make"
RUN rustup component add clippy
RUN rustup component add rustfmt
RUN rustup component add llvm-tools-preview
RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup target add riscv64gc-unknown-linux-gnu
RUN rustup +nightly component add miri
RUN rustup +nightly component add rust-src
DO lib-rust+CARGO --args="+nightly miri setup"
source:
FROM +install-build-dependencies
COPY --keep-ts Cargo.toml Cargo.lock Makefile.toml ./
COPY --keep-ts deny.toml ./
COPY --keep-ts --dir lightway-core lightway-app-utils lightway-client uniffi-bindgen lightway-server tests ./
# build runs cargo to build native binaries for the host platform.
# You may use `--platform linux/[amd64|arm64]` to override the host platform, to natively compile in emulation.
build:
FROM +source
DO lib-rust+CARGO --args="build --release --features io-uring" --output="release/lightway-(client|server)$"
SAVE ARTIFACT ./target/release/lightway-client AS LOCAL ./target/release/
SAVE ARTIFACT ./target/release/lightway-server AS LOCAL ./target/release/
# build-cross-arm64 cross-compiles to arm64 from an amd64 host.
build-cross-arm64:
FROM +source
LET target = "aarch64-unknown-linux-gnu"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc"
DO lib-rust+CARGO --args="build --release --features io-uring --target=$target" --output="$target/release/lightway-(client|server)$"
SAVE ARTIFACT ./target/$target/release/lightway-client AS LOCAL ./target/$target/release/
SAVE ARTIFACT ./target/$target/release/lightway-server AS LOCAL ./target/$target/release/
# build-cross-riscv64 cross-compiles to riscv64 from an amd64 or arm64 host.
build-cross-riscv64:
FROM +source
LET target = "riscv64gc-unknown-linux-gnu"
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="riscv64-linux-gnu-gcc"
DO lib-rust+CARGO --args="build --release --features io-uring --target=$target" --output="$target/release/lightway-(client|server)$"
SAVE ARTIFACT ./target/$target/release/lightway-client AS LOCAL ./target/$target/release/
SAVE ARTIFACT ./target/$target/release/lightway-server AS LOCAL ./target/$target/release/
# test runs cargo to compile all unit and integration tests, natively for the host platform.
# You may use `--platform linux/[amd64|arm64]` to override the host platform, to natively compile in emulation.
test:
FROM +source
# Run all tests except privileged tests
DO lib-rust+CARGO --args="test"
# Run only privileged tests with sudo permissions
RUN --privileged cargo test --package lightway-client test_privileged -- --ignored
# test-miri runs tests for modules which make use of `unsafe` under Miri.
test-miri:
FROM +source
# The libc crate uses integer-to-pointer casts which are not compatible with "strict provenance"
# (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance).
ENV MIRIFLAGS=-Zmiri-permissive-provenance
DO lib-rust+CARGO --args="+nightly miri test -p lightway-app-utils -- iouring sockopt"
DO lib-rust+CARGO --args="+nightly miri test -p lightway-server -- io::outside::udp"
# test-cross-arm64 cross-compiles to arm64 from an amd64 host. It then runs tests via QEMU.
test-cross-arm64:
FROM +source
LET target = "aarch64-unknown-linux-gnu"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64-static"
# Run all tests except privileged tests
DO lib-rust+CARGO --args="test --target=$target"
# Run only privileged tests with sudo permissions
RUN --privileged cargo test --package lightway-client --target=$target test_privileged -- --ignored
# test-cross-riscv64 cross-compiles to riscv64 from an amd64 or arm64 host. It then runs tests via QEMU.
test-cross-riscv64:
FROM +source
LET target = "riscv64gc-unknown-linux-gnu"
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="riscv64-linux-gnu-gcc"
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64-static -L /usr/riscv64-linux-gnu -cpu rv64"
# Run all tests except privileged tests
DO lib-rust+CARGO --args="test --target=$target"
# Run only privileged tests with sudo permissions
RUN --privileged cargo test --package lightway-client --target=$target test_privileged -- --ignored
# e2e runs all end-to-end tests, must be run with `--allow-privileged`
e2e:
BUILD ./tests+run-all-tests --debian=$debian
# coverage generates a report of code coverage by unit and integration tests via `cargo llvm-cov`
coverage:
FROM +source
RUN mkdir /tmp/coverage
DO lib-rust+SET_CACHE_MOUNTS_ENV
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE \
cargo llvm-cov test --no-report
# Run privileged tests with sudo for coverage
RUN --privileged --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE \
cargo llvm-cov test --package lightway-client test_privileged --no-report -- --ignored
# Generate final coverage report including all tests
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE \
cargo llvm-cov report --summary-only --output-path /tmp/coverage/summary.txt && \
cargo llvm-cov report --json --output-path /tmp/coverage/coverage.json && \
cargo llvm-cov report --html --output-dir /tmp/coverage/
SAVE ARTIFACT /tmp/coverage/*
# fmt checks whether Rust code is formatted according to style guidelines
fmt:
FROM +source
DO lib-rust+CARGO --args="fmt --check"
# lint runs cargo clippy on the source code
lint:
FROM +source
DO lib-rust+CARGO --args="clippy -p lightway-client --no-default-features --all-targets -- -D warnings"
ENV RUSTDOCFLAGS="-D warnings"
DO lib-rust+CARGO --args="doc --document-private-items"
# Run lint for shell scripts inside tests/ directory
COPY --dir tests ./
RUN find tests -name "*.sh" -print0 | xargs -r0 shellcheck
# check-dependencies lints our dependencies via `cargo deny`
check-dependencies:
FROM +source
DO lib-rust+CARGO --args="deny --all-features check --deny warnings bans license sources"