Skip to content

Commit a72de7a

Browse files
Copilotf2calv
andcommitted
fix: remove invalid rustup toolchain install for cross-compile targets
rustup toolchain install stable-<cross-target> attempts to install and run binaries for the target platform on the build host, which fails with "may not be able to run on this system". Cross-compilation only requires rustup target add <target> (stdlib for the target) plus the system cross-linker from apt. Removed the three rustup toolchain install lines. +semver:feature Co-authored-by: f2calv <16097639+f2calv@users.noreply.github.com>
1 parent 9c3cdd3 commit a72de7a

4 files changed

Lines changed: 6 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "multi-arch-container-rust"
33
authors = ["Alex Vincent <alex@far2cool.com>"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55
edition = "2021"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
1010
echo 'TODO: need to complete and test building x86_64 FROM an arm platform??... ' ; \
1111
apt-get install -y g++-x86-64-linux-gnu libc6-dev-amd64-cross ; \
1212
rustup target add x86_64-unknown-linux-gnu ; \
13-
rustup toolchain install stable-x86_64-unknown-linux-gnu ; \
1413
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
1514
apt-get install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross ; \
1615
rustup target add aarch64-unknown-linux-gnu ; \
17-
rustup toolchain install stable-aarch64-unknown-linux-gnu ; \
1816
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
1917
apt-get install -y g++-arm-linux-gnueabihf libc6-dev-armhf-cross ; \
2018
rustup target add armv7-unknown-linux-gnueabihf ; \
21-
rustup toolchain install stable-armv7-unknown-linux-gnueabihf ; \
2219
fi
2320

2421

@@ -41,7 +38,7 @@ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
4138
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
4239
TARGET=armv7-unknown-linux-gnueabihf ; \
4340
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc ; \
44-
export CC_armv7_unknown_Linux_gnueabihf=arm-linux-gnueabihf-gcc ; \
41+
export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc ; \
4542
export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ ; \
4643
fi \
4744
&& cargo fetch --target $TARGET
@@ -69,7 +66,7 @@ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
6966
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
7067
TARGET=armv7-unknown-linux-gnueabihf ; \
7168
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc ; \
72-
export CC_armv7_unknown_Linux_gnueabihf=arm-linux-gnueabihf-gcc ; \
69+
export CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc ; \
7370
export CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ ; \
7471
fi \
7572
&& cargo build --release --target $TARGET && mv /app/target/$TARGET /app/target/final

src/main.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,8 @@ impl<T: std::fmt::Display> std::fmt::Display for DisplayOption<'_, T> {
9797
}
9898
}
9999

100-
fn get_arch() -> String {
101-
#[cfg(target_arch = "x86")]
102-
let arch = String::from("x86");
103-
#[cfg(target_arch = "x86_64")]
104-
let arch = String::from("x86_64");
105-
#[cfg(target_arch = "arm")]
106-
let arch = String::from("arm");
107-
#[cfg(target_arch = "aarch64")]
108-
let arch = String::from("aarch64");
109-
arch
100+
fn get_arch() -> &'static str {
101+
std::env::consts::ARCH
110102
}
111103

112104
fn get_app_name() -> String {

0 commit comments

Comments
 (0)