Last active
January 16, 2022 06:45
-
-
Save rene-d/5d8dfe52be7177acb6ff4c999420bb02 to your computer and use it in GitHub Desktop.
Rust cross-compilation example (on Apple Silicon with Docker)
This file contains hidden or 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
| [package] | |
| name = "hello" | |
| version = "0.1.0" | |
| edition = "2021" | |
| [dependencies] | |
| [[bin]] | |
| name = "hello" | |
| path = "hello.rs" |
This file contains hidden or 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
| FROM rust | |
| RUN rustup update | |
| RUN rustup target add x86_64-pc-windows-gnu | |
| RUN rustup target add x86_64-unknown-linux-gnu | |
| RUN rustup target add aarch64-unknown-linux-gnu | |
| RUN rustup target add x86_64-unknown-linux-musl | |
| RUN rustup target add aarch64-unknown-linux-musl | |
| RUN rustup +nightly component add rustfmt | |
| RUN rustup component add clippy | |
| RUN apt-get update | |
| RUN apt-get upgrade | |
| RUN apt-get install -y vim | |
| RUN apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64 pev | |
| RUN apt-get install -y gcc-x86-64-linux-gnu | |
| RUN apt-get install -y musl-tools musl-dev | |
| COPY Cargo.toml hello.rs /demo/ | |
| WoRKDIR /demo/ | |
| RUN cargo build | |
| RUN env RUSTFLAGS='-C linker=x86_64-linux-gnu-gcc' cargo build --target=x86_64-unknown-linux-gnu | |
| RUN env RUSTFLAGS='-C linker=x86_64-linux-gnu-gcc' cargo build --target=x86_64-unknown-linux-musl | |
| RUN cargo build --target=aarch64-unknown-linux-gnu | |
| RUN cargo build --target=aarch64-unknown-linux-musl | |
| RUN cargo build --target=x86_64-pc-windows-gnu | |
| RUN find target -type f -regextype posix-egrep -regex '.*/(hello|hello\.exe)' -ls -exec file {} + |
This file contains hidden or 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
| // hello.rs | |
| fn type_of<T>(_: &T) -> &'static str { | |
| std::any::type_name::<T>() | |
| } | |
| fn main() { | |
| let a = 1; | |
| println!("a = {} : {}", a, type_of(&a)); | |
| let f = 3.14; | |
| println!("f = {} : {}", f, type_of(&f)); | |
| let s = "abc"; | |
| println!("s = {} : {}", s, type_of(&s)); | |
| println!("main : {}", type_of(&main)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment