1

I have a CLI that I wrote and am trying to have it built for these targets in a Docker image based from the rust:1.53-slim image:

  • x86_64-unknown-linux-gnu
  • x86_64-apple-darwin
  • x86_64-pc-windows-gnu

The Linux and Windows targets are building properly, but when I try to do the cross compile for the Darwin target, the hyper crate continues to fail to compile because of the following error:

$ cargo build --locked --release --target x86_64-apple-darwin

# ...
# OMITTED COMPILE OUTPUTS
# ...

= note: cc: error: x86_64: No such file or directory
          cc: error: unrecognized command line option '-arch'; did you mean '-march='?
          

error: aborting due to previous error

error: could not compile `hyper`

I've scoured the internet looking for clues or solutions to this but can't find anything thats helpful. Has anyone experienced or solved this before? Any guidance would be great!


EDIT:

Is there a GCC linker that I need to have installed via apt-get for it to properly compile for darwin?

m_callens
  • 6,100
  • 8
  • 32
  • 54

1 Answers1

0

Cross-compiling still requires a native linker which supports the requested target (which in turns needs the system libraries).

You may have some luck with osxcross or crossbuild and overriding the linker (andc compiler) using a target-specific section in .cargo/config.toml such as:

[target.x86_64-apple-darwin]
linker = "linker-path-here"

And/or setting the CC env var to the right cross-compiler.

Mathieu Rene
  • 924
  • 5
  • 11
  • 1
    Is there something i need to have installed via `apt-get` on the docker image for the darwin linker to be available or is it installed when the rustup target is added? – m_callens Jul 10 '21 at 19:01