How cross-compile on mac for linux


#1

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-musl-gcc"

When I cross-compile:
When I run the command to cross-compile: cargo build --target=x86_64-unknown-linux-musl, I get the following errors:


warning: build failed, waiting for other jobs to finish…
error: failed to run custom build command for libz-sys v1.0.25
process didn’t exit successfully: /Users/tw2016/Documents/workspace/rust/newspull/target/debug/build/libz-sys-0074e55ee9f8b965/build-script-build (exit code: 101)
— stdout
cargo:rerun-if-env-changed=LIBZ_SYS_STATIC
cargo:rerun-if-changed=build.rs
TARGET = Some(“x86_64-unknown-linux-musl”)
OPT_LEVEL = Some(“0”)
HOST = Some(“x86_64-apple-darwin”)
CC_x86_64-unknown-linux-musl = None
CC_x86_64_unknown_linux_musl = None
TARGET_CC = None
CC = None
CROSS_COMPILE = None
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some(“true”)
running: “musl-gcc” “-O0” “-ffunction-sections” “-fdata-sections” “-fPIC” “-g” “-fno-omit-frame-pointer” “-m64” “-static” “-I” “src/zlib” “-fvisibility=hidden” “-DSTDC” “-D_LARGEFILE64_SOURCE” “-D_POSIX_SOURCE” “-o” “/Users/tw2016/Documents/workspace/rust/newspull/target/x86_64-unknown-linux-musl/debug/build/libz-sys-22a028ca550cd081/out/build/src/zlib/adler32.o” “-c” “src/zlib/adler32.c”

— stderr
thread ‘main’ panicked at ’

Internal error occurred: Failed to find tool. Is musl-gcc installed?


The following are the dependencies in my cargo.
mongodb = “0.3.10”
bson = “0.12.3”
serde = “1.0”
serde_derive = “1.0.80”
serde_json = “1.0.33”
reqwest = “0.9.4”
webpage = “0.1.3”
zip = “0.4.2”
csv = “1.0.2”
toml = “0.4.2”
scraper = “0.8.1”
select = “0.4.2”
slugify = “0.1.0”
regex = “1.0.6”
chrono = {version = “0.4.6”, features = [“serde”]}

Thanks,


#2

Not on Mac, but try linking x86_64-linux-musl-gcc to musl-gcc somewhere in your PATH?