rust-lang/backtrace-rs

Cross-Compile to `x86_64-unknown-linux-musl` from macOS Fails

davidbarsky opened this issue · 6 comments

Hi! I'm opening this issue despite #25 existing. When trying to cross-compile a project that has backtrace-rs as a transitive dependency, I get the following error:

Standard
minimum-failure:master >> cargo build --release --target=x86_64-unknown-linux-musl
   Compiling backtrace-sys v0.1.16
   Compiling failure_derive v0.1.1
error: failed to run custom build command for `backtrace-sys v0.1.16`
process didn't exit successfully: `/Users/dbarsky/Developer/Rust/minimum-failure/target/release/build/backtrace-sys-d00ffb83df7137b6/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
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
HOST = Some("x86_64-apple-darwin")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "sh" "/Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/src/libbacktrace/configure" "--with-pic" "--disable-multilib" "--disable-shared" "--disable-host-shared" "--host=x86_64-unknown-linux-musl" "--build=x86_64-apple-darwin"
checking build system type... x86_64-apple-darwin
checking host system type... x86_64-unknown-linux-musl
checking target system type... x86_64-unknown-linux-musl
checking for x86_64-unknown-linux-musl-gcc... musl-gcc
checking for C compiler default output file name...

--- stderr
configure: error: in `/Users/dbarsky/Developer/Rust/minimum-failure/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-0faeb9e02c25b08d/out':
configure: error: C compiler cannot create executables
See `config.log' for more details.
thread 'main' panicked at 'failed with: exit code: 77', /Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/build.rs:176:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
With Backtrace
minimum-failure:master >> cargo build --release --target=x86_64-unknown-linux-musl
   Compiling backtrace-sys v0.1.16
   Compiling failure_derive v0.1.1
error: failed to run custom build command for `backtrace-sys v0.1.16`
process didn't exit successfully: `/Users/dbarsky/Developer/Rust/minimum-failure/target/release/build/backtrace-sys-d00ffb83df7137b6/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
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
HOST = Some("x86_64-apple-darwin")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "sh" "/Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/src/libbacktrace/configure" "--with-pic" "--disable-multilib" "--disable-shared" "--disable-host-shared" "--host=x86_64-unknown-linux-musl" "--build=x86_64-apple-darwin"
checking build system type... x86_64-apple-darwin
checking host system type... x86_64-unknown-linux-musl
checking target system type... x86_64-unknown-linux-musl
checking for x86_64-unknown-linux-musl-gcc... musl-gcc
checking for C compiler default output file name...

--- stderr
configure: error: in `/Users/dbarsky/Developer/Rust/minimum-failure/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-0faeb9e02c25b08d/out':
configure: error: C compiler cannot create executables
See `config.log' for more details.
thread 'main' panicked at 'failed with: exit code: 77', /Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/build.rs:176:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
minimum-failure:master >> env RUST_BACKTRACE=1 cargo build --release --target=x86_64-unknown-linux-musl
   Compiling backtrace-sys v0.1.16
error: failed to run custom build command for `backtrace-sys v0.1.16`
process didn't exit successfully: `/Users/dbarsky/Developer/Rust/minimum-failure/target/release/build/backtrace-sys-d00ffb83df7137b6/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
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
HOST = Some("x86_64-apple-darwin")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "sh" "/Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/src/libbacktrace/configure" "--with-pic" "--disable-multilib" "--disable-shared" "--disable-host-shared" "--host=x86_64-unknown-linux-musl" "--build=x86_64-apple-darwin"
checking build system type... x86_64-apple-darwin
checking host system type... x86_64-unknown-linux-musl
checking target system type... x86_64-unknown-linux-musl
checking for x86_64-unknown-linux-musl-gcc... musl-gcc
checking for C compiler default output file name...

--- stderr
configure: error: in `/Users/dbarsky/Developer/Rust/minimum-failure/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-0faeb9e02c25b08d/out':
configure: error: C compiler cannot create executables
See `config.log' for more details.
thread 'main' panicked at 'failed with: exit code: 77', /Users/dbarsky/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/build.rs:176:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
   6: std::panicking::begin_panic_fmt
   7: build_script_build::run
   8: build_script_build::main
   9: std::rt::lang_start::{{closure}}
  10: std::panicking::try::do_call
  11: __rust_maybe_catch_panic
  12: std::rt::lang_start_internal
  13: main

The project that I'm building just has a dependency on withoutboats/failure 0.1.1. The config.log is reproduced here.

Thanks for your work on this! Let me know if I can help you triage this in any way!

Oh, I should mention that I'm on macOS Sierra, version 10.12.6. Don't recall which version of the command-line tools, that's managed by my employer in a weird way. I wonder if I'm just using an outdated version of Apple's developer tools.

It looks like musl-gcc, the default selected compiler for musl compilation, may not exist?

Update: I ended up using Docker with this image. It turned out to integrate better with my employer's build system and doesn't doesn't require having a local copy of musl-gcc. I am a bit unfamiliar/naive with cross-building with Rust, but Docker turned out to be a good solution.

Thanks for your help, Alex! It was greatly appreciated.

Can we reopen this? Hitting the same problem.

❯ musl-gcc --version
musl-gcc (GCC) 6.3.0

❯ x86_64-linux-musl-objcopy --version
GNU objcopy (GNU Binutils) 2.27

configure run:

error: failed to run custom build command for `backtrace-sys v0.1.16`
process didn't exit successfully: `/Users/farcaller/src/mdserver/target/release/build/backtrace-sys-67157ba78218bcef/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("3")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
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
HOST = Some("x86_64-apple-darwin")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("false")
running: "sh" "/Users/farcaller/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/src/libbacktrace/configure" "--with-pic" "--disable-multilib" "--disable-shared" "--disable-host-shared" "--host=x86_64-unknown-linux-musl" "--build=x86_64-apple-darwin"
checking build system type... x86_64-apple-darwin
checking host system type... x86_64-unknown-linux-musl
checking target system type... x86_64-unknown-linux-musl
checking for x86_64-unknown-linux-musl-gcc... musl-gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... yes
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether musl-gcc accepts -g... yes
checking for musl-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... musl-gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for a BSD-compatible install... /Users/farcaller/.homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for x86_64-unknown-linux-musl-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /Users/farcaller/.homebrew/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for x86_64-unknown-linux-musl-gcc... (cached) musl-gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether musl-gcc accepts -g... (cached) yes
checking for musl-gcc option to accept ISO C89... (cached) none needed
checking for x86_64-unknown-linux-musl-ranlib... ranlib
checking for gawk... (cached) awk
checking how to print strings... printf
checking for a sed that does not truncate output... /Users/farcaller/.homebrew/bin/gsed
checking for fgrep... /usr/bin/grep -F
checking for ld used by musl-gcc... /Users/farcaller/.homebrew/Cellar/musl-cross/0.9.5/libexec/x86_64-linux-musl/bin/ld
checking if the linker (/Users/farcaller/.homebrew/Cellar/musl-cross/0.9.5/libexec/x86_64-linux-musl/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... no
checking for x86_64-unknown-linux-musl-dumpbin... no
checking for x86_64-unknown-linux-musl-link... no
checking for dumpbin... no
checking for link... link -dump
checking the name lister (nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /Users/farcaller/.homebrew/Cellar/musl-cross/0.9.5/libexec/x86_64-linux-musl/bin/ld option to reload object files... -r
checking for x86_64-unknown-linux-musl-objdump... no
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for x86_64-unknown-linux-musl-ar... ar
checking for x86_64-unknown-linux-musl-strip... strip
checking for x86_64-unknown-linux-musl-ranlib... (cached) ranlib
checking command to parse nm output from musl-gcc object... ok
checking for dlfcn.h... yes
checking for objdir... .libs
checking if musl-gcc supports -fno-rtti -fno-exceptions... no
checking for musl-gcc option to produce PIC... -fPIC -DPIC
checking if musl-gcc PIC flag -fPIC -DPIC works... yes
checking if musl-gcc static flag -static works... yes
checking if musl-gcc supports -c -o file.o... yes
checking if musl-gcc supports -c -o file.o... (cached) yes
checking whether the musl-gcc linker (/Users/farcaller/.homebrew/Cellar/musl-cross/0.9.5/libexec/x86_64-linux-musl/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... no
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking unwind.h usability... yes
checking unwind.h presence... yes
checking for unwind.h... yes
checking for _Unwind_Backtrace... yes
checking for -funwind-tables option... yes
checking for -frandom-seed=string option... yes
checking whether musl-gcc supports -W... yes
checking whether musl-gcc supports -Wall... yes
checking whether musl-gcc supports -Wwrite-strings... yes
checking whether musl-gcc supports -Wstrict-prototypes... yes
checking whether musl-gcc supports -Wmissing-prototypes... yes
checking whether musl-gcc supports -Wold-style-definition... yes
checking whether musl-gcc supports -Wmissing-format-attribute... yes
checking whether musl-gcc supports -Wcast-qual... yes
checking for _Unwind_GetIPInfo... yes
checking __sync extensions... yes
checking __atomic extensions... yes
checking output filetype... elf64
looking for a compliant stdint.h in stdint.h, checking for uintmax_t... yes
checking for uintptr_t... yes
checking for int_least32_t... yes
checking for int_fast32_t... yes
checking for uint64_t... yes
checking what to include in gstdint.h... stdint.h (already complete)
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for mmap... yes
checking link.h usability... yes
checking link.h presence... yes
checking for link.h... yes
checking for dl_iterate_phdr... yes
checking for fcntl... yes
checking whether strnlen is declared... yes
checking for getexecname... no
checking whether tests can run... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating backtrace-supported.h
config.status: creating config.h
config.status: executing libtool commands
config.status: executing gstdint.h commands
config.status: executing default commands
running: "make" "INCDIR=/Users/farcaller/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-sys-0.1.16/src/libbacktrace"

Fails at:

/bin/sh ./libtool --tag=CC   --mode=link musl-gcc -funwind-tables -frandom-seed=libbacktrace.la -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -fPIC -O3 -ffunction-sections -fdata-sections -fPIC -m64 -static -Wall -Wextra   -o libbacktrace.la  atomic.lo dwarf.lo fileline.lo posix.lo print.lo sort.lo state.lo backtrace.lo simple.lo elf.lo mmapio.lo alloc.lo
libtool: link: ar cru .libs/libbacktrace.a  atomic.o dwarf.o fileline.o posix.o print.o sort.o state.o backtrace.o simple.o elf.o mmapio.o alloc.o
libtool: link: ranlib .libs/libbacktrace.a
libtool: link: ( cd ".libs" && rm -f "libbacktrace.la" && ln -s "../libbacktrace.la" "libbacktrace.la" )
cargo:rustc-link-search=native=/Users/farcaller/src/mdserver/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-b53046f6b2f1ebf7/out/.libs
cargo:rustc-link-lib=static=backtrace
running: "ar" "x" "/Users/farcaller/src/mdserver/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-b53046f6b2f1ebf7/out/.libs/libbacktrace.a"
running: "objcopy" "--redefine-syms=symbol-map" "/Users/farcaller/src/mdserver/target/x86_64-unknown-linux-musl/release/build/backtrace-sys-b53046f6b2f1ebf7/out/__tmp/simple.o"

--- stderr
configure: WARNING: using cross tools not prefixed with host triplet
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: .libs/libbacktrace.a the table of contents is empty (no object file members in the library define global symbols)
thread 'main' panicked at '

failed to execute command: No such file or directory (os error 2)
Is `objcopy` not installed?

After quickly skimming through the build.rs I figured that AR=x86_64-linux-musl-ar OBJCOPY=x86_64-linux-musl-objcopy cargo build ... works as expected.

I guess the problem is that cargo uses quadruplet x86_64-unknown-linux-musl, while the complier is named after the triplet.