-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add cross-compile support (#506)
* build: add cross-compile support * fix: switch to musl
- Loading branch information
1 parent
a2da58a
commit fa30323
Showing
4 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
[alias] | ||
xtask = "run --package xtask --bin xtask --" | ||
xtask = "run --package xtask --bin xtask --" | ||
|
||
[target.aarch64-unknown-linux-musl] | ||
linker = "aarch64-linux-gnu-gcc" | ||
|
||
[target.x86_64-unknown-linux-musl] | ||
linker = "x86_64-linux-gnu-gcc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Rust related build artifacts. | ||
/target | ||
.cargo/ | ||
wix/ | ||
scripts/ | ||
examples/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
|
||
# The build image | ||
FROM rust:1.83.0-alpine3.20 AS weaver-build | ||
RUN apk add musl-dev | ||
FROM --platform=$BUILDPLATFORM docker.io/rust:1.83.0 AS weaver-build | ||
WORKDIR /build | ||
ARG BUILDPLATFORM | ||
ARG TARGETPLATFORM | ||
|
||
# list out directories to avoid pulling local cargo `target/` | ||
COPY Cargo.toml /build/Cargo.toml | ||
COPY Cargo.lock /build/Cargo.lock | ||
COPY .cargo /build/.cargo | ||
COPY crates /build/crates | ||
COPY data /build/data | ||
COPY src /build/src | ||
COPY tests /build/tests | ||
COPY defaults /build/defaults | ||
COPY cross-arch-build.sh /build/cross-arch-build.sh | ||
|
||
# Build weaver | ||
RUN cargo build --release | ||
RUN ./cross-arch-build.sh | ||
|
||
# The runtime image | ||
FROM alpine:3.20.3 | ||
FROM docker.io/alpine:3.20.3 | ||
LABEL maintainer="The OpenTelemetry Authors" | ||
RUN addgroup weaver \ | ||
&& adduser \ | ||
--ingroup weaver \ | ||
--disabled-password \ | ||
weaver | ||
WORKDIR /home/weaver | ||
COPY --from=weaver-build /build/target/release/weaver /weaver/weaver | ||
COPY --from=weaver-build --chown=weaver:weaver /build/weaver /weaver/weaver | ||
USER weaver | ||
RUN mkdir /home/weaver/target | ||
ENTRYPOINT ["/weaver/weaver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
set -exu | ||
|
||
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then | ||
RUST_TARGET=x86_64-unknown-linux-musl | ||
if [ "${TARGETPLATFORM}" != "${BUILDPLATFORM}" ]; then | ||
apt-get update && apt-get install -y gcc-x86-64-linux-gnu | ||
fi | ||
elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then | ||
RUST_TARGET=aarch64-unknown-linux-musl | ||
if [ "${TARGETPLATFORM}" != "${BUILDPLATFORM}" ]; then | ||
apt-get update && apt-get install -y gcc-aarch64-linux-gnu | ||
fi | ||
else | ||
echo "Unsupported target platform: ${TARGETPLATFORM}" | ||
exit 1 | ||
fi | ||
|
||
rustup target add "${RUST_TARGET}" | ||
cargo build --release --target="${RUST_TARGET}" | ||
cp "target/${RUST_TARGET}/release/weaver" . |