The target is x86_64-apple-darwin, not stable-x86_64-apple-darwin. You will also need a compiler toolchain that can target macOS - GitHub - tpoechtrager/osxcross: Mac OS X cross toolchain for Linux, FreeBSD, OpenBSD and Android (Termux) is a decent way to do that. You can also use cross to handle … Answer from sfackler on users.rust-lang.org
🌐
GitHub
github.com › chinedufn › cross-compile-rust-from-mac-to-linux
GitHub - chinedufn/cross-compile-rust-from-mac-to-linux: An example of how to cross compile Rust from `macOS` to Linux `x86_64-unknown-linux-gnu` · GitHub
This repository is an example of cross compiling from macOS to x86_64-unknown-linux-gnu. rustup target add x86_64-unknown-linux-gnu # Install a pre-built cross compiler brew tap SergioBenitez/osxct brew install x86_64-unknown-linux-gnu # Hop in the repository git clone git@github.com:chinedufn/cross-compile-rust-from-mac-to-linux.git cd cross-compile-rust-from-mac-to-linux # Download libssl-dev so that we can statically link to it during compilation # (reqwest needs this) ./download-libssl-dev.sh # Cross compile to x86_64-unknown-linux-gnu ./build.sh # Run the binary in a Docker image ./run.sh # You should see "It worked." in your terminal.
Starred by 97 users
Forked by 9 users
Languages   Shell 59.8% | Rust 29.5% | Dockerfile 10.7%
🌐
Reddit
reddit.com › r/rust › how do i cross compile on macos?
r/rust on Reddit: How do I cross compile on macOS?
October 28, 2023 -

Edit: It was a PAINSTAKING process that took an entire day of failing numerous times but persevering, so I managed to do it. Here's how I did it in the end:

First I of course had to install cross:

$ cargo install cross

Then I installed Docker Desktop and got the daemon running. After that I added Windows as a target with Rustup:

$ rustup target add x86_64-pc-windows-msvc

Then I had to build the Docker image for my target, following the instructions at https://github.com/cross-rs/cross-toolchains.

$ cd /path/to/dir # any directory you prefer
$ git clone https://github.com/cross-rs/cross
$ cd cross
$ git submodule update --init --remote

Then I followed the instructions to configure:

$ cargo xtask configure-crosstool

I was looking to build for x86_64-pc-windows-msvc, so I checked the table in README.md and built the appropriate image with the local tag:

$ cargo build-docker-image x86_64-pc-windows-msvc-cross --tag local

I then created a file called Cross.toml in my project directory and added the following lines to it:

[target.x86_64-pc-windows-msvc]
image = "ghcr.io/cross-rs/x86_64-pc-windows-msvc-cross:local"

Finally,

$ cross build --release --target x86_64-pc-windows-msvc --verbose

did the job. To be honest, I have no idea how to use Docker and what it's for, and I was just improvising here, which is probably why it took an entire day. Albeit, I'm very happy I managed to get it working, and the resulting .exe works on Windows (I had my friend test it).


I'm on macOS, and I just wrote my first Rust project. My friend and I are both learning different languages (he's learning Python and I'm learning Rust; dw Rust isn't my first language lol). I want to compile my program into an executable that my friend can run on his Windows machine. I would also like if I could compile for Linux so I can have my dad try it out.

🌐
Medium
medium.com › better-programming › cross-compiling-rust-from-mac-to-linux-7fad5a454ab1
Cross-compiling Rust From Mac to Linux | by Merlin Fuchs | Better Programming
June 9, 2022 - TARGET_CC=x86_64-linux-musl-gcc cargo build --release --target x86_64-unknown-linux-musl · That’s it! You can now cross-compile from Mac to Linux.
🌐
Reddit
reddit.com › r/rust › cross compile rust on mac os
r/rust on Reddit: Cross Compile Rust on Mac OS
December 26, 2023 -

I'm joining a project and I was advised that to compile it, I need to run

cargo build --release --target arm-unknown-linux-gnueabihf

I'm on Mac OS (Sonoma 14.2.1). I know I need an ARM toolchain for this but I'm not sure what I need or, more accurately, where/how to install it.

In the project directory, I have been advised to create `.cargo/config.toml`
with this content

[target.arm-unknown-linux-gnueabihf]
linker = "gcc-ar-13" 

I assume I need to change the value for the linker but, as mentioned, I'm unsure what option to put there.

If it matters, I have no issue with cargo build --release by itself.

Here are more details from the output. I recognize in this case that it seems to be issues with the command line arguments but I dont think this is the right linker so Im not too concerned about this specifically. This is lightly redacted

  Compiling cfg-if v1.0.0
  # Omitting lots of lines that start with "Compiling"
  Compiling project v0.1.19 (/Users/USER/repos/project)

error: linking with `gcc-ar-13` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="PATH_REDACTED" VSLANG="1033" "gcc-ar-13" "/var/folders/3z/z7gj1knj2pqf_q17jz7yzc3h0000gq/T/rustcNChRuA/symbols.o" "/Users/USER/repos/project/target/arm-unknown-linux-gnueabihf/release/deps/project-f18b9ac4a98f6089.project.f25b3891c1c0fef8-cgu.15.rcgu.o" "-Wl,--as-needed" "-L" "/Users/USER/repos/project/target/arm-unknown-linux-gnueabihf/release/deps" "-L" "/Users/USER/repos/project/target/release/deps" "-L" "/Users/USER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "-Wl,-Bstatic" "/Users/USER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/arm-unknown-linux-gnueabihf/lib/libcompiler_builtins-31fb99244964ed82.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/Users/USER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "-o" "/Users/USER/repos/project/target/arm-unknown-linux-gnueabihf/release/deps/project-f18b9ac4a98f6089" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: /Library/Developer/CommandLineTools/usr/bin/ar: illegal option -- /           
       usage:
             ar -d [-TLsv] archive file ...
             ar -m [-TLsv] archive file ...
             ar -m [-abiTLsv] position archive file ...
             ar -p [-TLsv] archive [file ...]
             ar -q [-cTLsv] archive file ...
             ar -r [-cuTLsv] archive file ...
             ar -r [-abciuTLsv] position archive file ...
             ar -t [-TLsv] archive [file ...]
             ar -x [-ouTLsv] archive [file ...]
error: could not compile `project` (bin "project") due to previous error
🌐
Saktidwicahyono
saktidwicahyono.name › blogs › cross-compile-to-linux-amd64-from-mac-m1
Cross compile Rust binary to Linux amd64 from Mac M1
July 9, 2023 - $ rustup target list --installed aarch64-apple-darwin aarch64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi ... Beside target toolchain, you also need linker build final executable. For mac to linux you can install · # install pre build cross compiling tool $ brew install SergioBenitez/osxct/x86_64-unknown-linux-gnu
🌐
Crafteo
blog.crafteo.io › 2024 › 02 › 29 › my-rust-cross-compilation-journey
A Rust cross compilation journey - Pierre's blog
February 29, 2024 - Searching for Rust cross compilation tool quickly yields cross, a “Zero setup” cross compilation tool. cross builds from containers (Docker or Podman) so it does not require anything much apart a few dependencies and a container engine (Docker or Podman) - except to target macOS which is another hell of a story I'm getting to below.
Find elsewhere
🌐
Webshed
webshed.org › blog › cross_compiling_rust_code
Cross Compiling Rust Code from macOS to Linux | webshed.org
rustup target add x86_64-unknown-linux-gnu brew tap SergioBenitez/osxct brew install x86_64-unknown-linux-gnu ... Because of some path error I couldn’t debug in the 30 seconds I bothered trying, I just specified the toolchain, etc on the build line in the marko directory. CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc cargo build --release --bin=marko --features=bin --target=x86_64-unknown-linux-gnu
🌐
Rust Programming Language
users.rust-lang.org › help
How cross-compile on mac for linux - help - The Rust Programming Language Forum
December 3, 2018 - Hi, I am trying to cross-compile for linux on a mac. The cross-compilation worked for a simple hello-world program, but I am not able to get it to work for a project which depends on several external crates. What I have done: added a target for linux by runniung: rustup target add x86_64-unknown-linux-musl installed the linker: brew install FiloSottile/musl-cross/musl-cross created ~/.cargo/config file with the wollowing contents: [target.x86_64-unknown-linux-musl] linker = "x86_64-linux...
🌐
Geekabyte
geekabyte.io › 2020 › 06 › how-to-cross-compile-rust-on-macos-and.html
geekAbyte: How to cross compile Rust on MacOs and target Linux using Docker container
June 11, 2020 - I had the option of trying to identify all the required dependencies, but I was really running out of time and frankly, hunting around for the correct dependencies needed to set up a working compiler toolchain is also not fun. So I ended up making use of Docker to help with the build processes. What I did was to create an image based on alpine Linux with the required toolchain. I then use the container spurn based on the image for the build processes. The procedure is as follows: The Dockerfile: FROM alpine:3.11 AS build LABEL maintainer="Dadepo Aderemi" # # -- Install Rust build toolchain # ENV RUSTFLAGS="-C target-feature=+crt-static" RUN apk add rust cargo openssl-dev The +crt-static ensures statically linking of runtime dependencies.
🌐
Sebastian Aigner
sebi.io › posts › 2024-05-02-guide-cross-compiling-rust-from-macos-to-raspberry-pi-2024-apple-silicon
Guide: Cross-compiling Rust from macOS to Raspberry Pi (2024, Apple Silicon) | Sebastian Aigner
May 2, 2024 - This guide builds on the guide from Amarit Rathie, which has been an indispensible resource in getting me started with cross-compilation at all. Mine has been updated for the latest versions of macOS at the time, and I’ve tried it on an M2 Mac – here, I’m the steps (and workarounds) required to get it to work for me – explanations are kept short, and I encourage you to reference the original blogpost to get a better understanding of what’s going on. I’m on a 32-Bit Raspberry Pi 3, so I did the following: rustup target add armv7-unknown-linux-musleabihf ·
🌐
N8henrie
n8henrie.com › 2023 › 09 › crosscompile-rust-for-x86-linux-from-m1-mac-with-nix
Cross-Compile Rust for x86 Linux from M1 Mac with Nix
September 6, 2023 - Unfortunately it doesn’t provide linkers, so even after you’ve added the toolchain, if you try to compile for linux, it’s not going to work: $ cargo new linux-cross-example && cd linux-cross-example $ rustup target add x86_64-unknown-linux-gnu info: component 'rust-std' for target 'x86_64-unknown-linux-gnu' is up to date $ cargo build --target=x86_64-unknown-linux-gnu ...
🌐
Wapl
wapl.es › rust › 2019 › 02 › 17 › rust-cross-compile-linux-to-macos.html
Cross compiling Rust from Linux to macOS - James Waples
February 17, 2019 - Now you should have a binary in target/x86_64-apple-darwin/[debug|release] which works on macOS! You can stop here if none of your crates require any C bindings to function. Quite a few of them do, so read on if you run into compilation or linking errors. The project I'm cross compiling uses the git2 crate which has libz-sys in its dependency tree.
🌐
Merlin
merlin.gg › posts › cross-compiling-rust-from-mac-to-linux
Cross-compiling Rust From Mac to Linux
TARGET_CC=x86_64-linux-musl-gcc cargo build --release --target x86_64-unknown-linux-musl · That's it! You can now cross-compile from Mac to Linux.
🌐
DEV Community
dev.to › mbround18 › rust-cross-compiling-from-linux-to-mac-on-github-actions-2mj8
Rust & Cross-compiling from Linux to Mac on GitHub Actions - DEV Community
August 9, 2022 - You have spent hours if not days googling for the appropriate way to cross-compile from Linux to Mac... Well, I am here to tell you I have been there and now provide an easy solution! # Setup Rust, use the x86_64-apple-darwin target but the rest can be customized.
🌐
Reddit
reddit.com › r/rust › tutorial: cross compiling from linux for osx
r/rust on Reddit: tutorial: cross compiling from Linux for OSX
August 6, 2017 -

I had just posted how to cross compile a gtk program from linux for windows, so thought I'd try to figure out the same process to compile to Mac. After I got part way through cross compiling gtk, I realized you need to sign gui apps for them to run in OSX, and have to do that from a mac anyway. So this process is kind of pointless for that. If you are developing a cli tool though, this can still be useful.

first install the toolchain

rustup target add x86_64-apple-darwin

setup the linker

~/.cargo/config

[target.x86_64-apple-darwin]
linker = "x86_64-apple-darwin15-gcc"
ar = "x86_64-apple-darwin15-ar"

install osxcross. taken from the aur pkgbuild for osxcross-git, you can just install that if you're on arch, but you'll need to modify the pkgbuild and set OSX_MIN_VERSION to 10.7.

git clone https://github.com/tpoechtrager/osxcross
cd osxcross
wget https://s3.dockerproject.org/darwin/v2/MacOSX10.11.sdk.tar.xz
mv MacOSX10.11.sdk.tar.xz tarballs/
sed -i -e 's|-march=native||g' build_clang.sh wrapper/build.sh
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
sudo mkdir -p /usr/local/osx-ndk-x86
sudo mv target/* /usr/local/osx-ndk-x86

then to compile

export PATH=/usr/local/osx-ndk-x86/bin:$PATH
export PKG_CONFIG_ALLOW_CROSS=1
cargo build --target=x86_64-apple-darwin --release

if anyone wants to try to get gtk working you can see the steps I took to build it here, but I'm going to give up on it since you can't sign from linux.

🌐
GitHub
godot-rust.github.io › book › gdnative › export › macosx.html
Mac OS X - The gdnative book
February 17, 2019 - Redirecting to... /gdnative-book/export/macosx.html.
🌐
GitHub
godot-rust.github.io › book › exporting › macosx.html
Redirecting...
May 23, 2020 - Redirecting to... /gdnative-book/export/macosx.html.