Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cross compilation for applications #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ ENV TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown
RUN rustup target add ${TARGETS}

# needed for cargo-chef and cargo-sbom, as well as many other compilations
RUN apk add musl-dev linux-headers make
RUN cargo install [email protected] [email protected]
RUN apk add musl-dev linux-headers make clang mold
RUN cargo install cargo-chef cargo-sbom
# we define target specific rustc flags for cross-compilation
ADD config.toml /usr/local/cargo/
28 changes: 28 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[target.aarch64-unknown-linux-musl]
linker = "/usr/bin/clang"
rustflags = [
"-C",
"link-arg=--ld-path=/usr/bin/mold",
"-C",
"link-arg=--target=aarch64-unknown-linux-musl",
]

[target.x86_64-unknown-linux-musl]
linker = "/usr/bin/clang"
rustflags = [
"-C",
"link-arg=--ld-path=/usr/bin/mold",
"-C",
"link-arg=--target=x86_64-unknown-linux-musl",
]

# FIXME: riscv64 is not yet available in rust:1.80.1-alpine3.20
# but both clang and mold support it. Alos musl-dev is available in Alpine 3.20
# [target.riscv64gc-unknown-linux-gnu]
# linker = "/usr/bin/clang"
# rustflags = [
# "-C",
# "link-arg=--ld-path=/usr/bin/mold",
# "-C",
# "link-arg=--target=riscv64-unknown-linux-musl",
# ]