rust-linux-darwin-builder icon indicating copy to clipboard operation
rust-linux-darwin-builder copied to clipboard

Unable to compile for macos

Open oliashish opened this issue 3 years ago • 3 comments
trafficstars

Hi, I'm trying to compile my rust project from Ubuntu 20.04 to MacOS. When I'm trying to follow the instruction in the Readme.md and it gives me the following error.

Caused by: process didn't exit successfully: /app/target/release/build/openssl-sys-5fe4cd3754acf404/build-script-main` (exit status: 101) --- stdout cargo:rustc-cfg=const_fn cargo:rerun-if-env-changed=X86_64_APPLE_DARWIN_OPENSSL_LIB_DIR X86_64_APPLE_DARWIN_OPENSSL_LIB_DIR unset cargo:rerun-if-env-changed=OPENSSL_LIB_DIR OPENSSL_LIB_DIR unset cargo:rerun-if-env-changed=X86_64_APPLE_DARWIN_OPENSSL_INCLUDE_DIR X86_64_APPLE_DARWIN_OPENSSL_INCLUDE_DIR unset cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR OPENSSL_INCLUDE_DIR unset cargo:rerun-if-env-changed=X86_64_APPLE_DARWIN_OPENSSL_DIR X86_64_APPLE_DARWIN_OPENSSL_DIR unset cargo:rerun-if-env-changed=OPENSSL_DIR OPENSSL_DIR unset cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG cargo:rerun-if-env-changed=OPENSSL_STATIC cargo:rerun-if-env-changed=OPENSSL_DYNAMIC cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=SYSROOT cargo:rerun-if-env-changed=OPENSSL_STATIC cargo:rerun-if-env-changed=OPENSSL_DYNAMIC cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC cargo:rustc-link-lib=ssl cargo:rustc-link-lib=dl cargo:rustc-link-lib=crypto cargo:rustc-link-lib=dl cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG cargo:rerun-if-env-changed=OPENSSL_STATIC cargo:rerun-if-env-changed=OPENSSL_DYNAMIC cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-changed=build/expando.c OPT_LEVEL = Some("3") TARGET = Some("x86_64-apple-darwin") HOST = Some("x86_64-unknown-linux-gnu") CC_x86_64-apple-darwin = None CC_x86_64_apple_darwin = None TARGET_CC = None CC = None CROSS_COMPILE = None CFLAGS_x86_64-apple-darwin = None CFLAGS_x86_64_apple_darwin = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3") running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "/usr/include" "-Wall" "-Wextra" "-E" "build/expando.c" cargo:warning=cc: error: x86_64: No such file or directory cargo:warning=cc: error: unrecognized command-line option '-arch' exit status: 1

--- stderr thread 'main' panicked at ' Header expansion error: Error { kind: ToolExecError, message: "Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "/usr/include" "-Wall" "-Wextra" "-E" "build/expando.c" with args "cc" did not execute successfully (status code exit status: 1)." }

Failed to find OpenSSL development headers.

You can try fixing this setting the OPENSSL_DIR environment variable pointing to your OpenSSL installation or installing OpenSSL headers package specific to your distribution:

  # On Ubuntu
  sudo apt-get install libssl-dev
  # On Arch Linux
  sudo pacman -S openssl
  # On Fedora
  sudo dnf install openssl-devel
  # On Alpine Linux
  apk add openssl-dev

See rust-openssl README for more information:

  https://github.com/sfackler/rust-openssl#linux

', /.cargo/config/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.75/build/main.rs:173:13 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace [0m[0m[1m[33mwarning[0m[1m:[0m build failed, waiting for other jobs to finish... The following warnings were emitted during compilation:

[0m[0m[1m[33mwarning[0m[1m:[0m cc: error: x86_64: No such file or directory [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: unrecognized command-line option '-arch' [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: x86_64: No such file or directory [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: unrecognized command-line option '-arch'

[0m[0m[1m[31merror[0m[1m:[0m failed to run custom build command for zstd-sys v1.6.3+zstd.1.5.2

Caused by: process didn't exit successfully: /app/target/release/build/zstd-sys-2c8dc93e5e58689c/build-script-build (exit status: 1) --- stdout TARGET = Some("x86_64-apple-darwin") HOST = Some("x86_64-unknown-linux-gnu") CC_x86_64-apple-darwin = None CC_x86_64_apple_darwin = None TARGET_CC = None CC = None CROSS_COMPILE = None CFLAGS_x86_64-apple-darwin = None CFLAGS_x86_64_apple_darwin = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3") running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-I" "zstd/lib/legacy" "-fvisibility=hidden" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZDICTLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-DZSTD_LEGACY_SUPPORT=1" "-o" "/app/target/x86_64-apple-darwin/release/build/zstd-sys-f44111bc4bb7bc85/out/zstd/lib/common/error_private.o" "-c" "zstd/lib/common/error_private.c" cargo:warning=cc: error: x86_64: No such file or directory cargo:warning=cc: error: unrecognized command-line option '-arch' exit status: 1 running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-I" "zstd/lib/legacy" "-fvisibility=hidden" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZDICTLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-DZSTD_LEGACY_SUPPORT=1" "-o" "/app/target/x86_64-apple-darwin/release/build/zstd-sys-f44111bc4bb7bc85/out/zstd/lib/common/pool.o" "-c" "zstd/lib/common/pool.c" cargo:warning=cc: error: x86_64: No such file or directory cargo:warning=cc: error: unrecognized command-line option '-arch' exit status: 1

--- stderr

error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "zstd/lib/" "-I" "zstd/lib/common" "-I" "zstd/lib/legacy" "-fvisibility=hidden" "-DZSTD_LIB_DEPRECATED=0" "-DXXH_PRIVATE_API=" "-DZSTDLIB_VISIBILITY=" "-DZDICTLIB_VISIBILITY=" "-DZSTDERRORLIB_VISIBILITY=" "-DZSTD_LEGACY_SUPPORT=1" "-o" "/app/target/x86_64-apple-darwin/release/build/zstd-sys-f44111bc4bb7bc85/out/zstd/lib/common/error_private.o" "-c" "zstd/lib/common/error_private.c" with args "cc" did not execute successfully (status code exit status: 1).

The following warnings were emitted during compilation:

[0m[0m[1m[33mwarning[0m[1m:[0m cc: error: x86_64: No such file or directory [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: unrecognized command-line option '-arch' [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: x86_64: No such file or directory [0m[0m[1m[33mwarning[0m[1m:[0m cc: error: unrecognized command-line option '-arch'

[0m[0m[1m[31merror[0m[1m:[0m failed to run custom build command for bzip2-sys v0.1.11+1.0.8

Caused by: process didn't exit successfully: /app/target/release/build/bzip2-sys-235dbcf39348906b/build-script-build (exit status: 1) --- stdout cargo:rerun-if-env-changed=BZIP2_NO_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG cargo:rerun-if-env-changed=BZIP2_STATIC cargo:rerun-if-env-changed=BZIP2_DYNAMIC cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_PATH cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-apple-darwin cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_apple_darwin cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR TARGET = Some("x86_64-apple-darwin") OPT_LEVEL = Some("3") HOST = Some("x86_64-unknown-linux-gnu") CC_x86_64-apple-darwin = None CC_x86_64_apple_darwin = None TARGET_CC = None CC = None CROSS_COMPILE = None CFLAGS_x86_64-apple-darwin = None CFLAGS_x86_64_apple_darwin = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3") running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/app/target/x86_64-apple-darwin/release/build/bzip2-sys-a6f1e00fddd3b885/out/lib/bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" cargo:warning=cc: error: x86_64: No such file or directory cargo:warning=cc: error: unrecognized command-line option '-arch' exit status: 1 running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/app/target/x86_64-apple-darwin/release/build/bzip2-sys-a6f1e00fddd3b885/out/lib/bzip2-1.0.8/huffman.o" "-c" "bzip2-1.0.8/huffman.c" cargo:warning=cc: error: x86_64: No such file or directory cargo:warning=cc: error: unrecognized command-line option '-arch' exit status: 1

--- stderr

error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-arch" "x86_64" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/app/target/x86_64-apple-darwin/release/build/bzip2-sys-a6f1e00fddd3b885/out/lib/bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args "cc" did not execute successfully (status code exit status: 1).

`

Can someone help me with this issue or let me know what I'm doing wrong?

My Dockerfile FROM joseluisq/rust-linux-darwin-builder:1.63.0 WORKDIR /app ENV CARGO_HOME="${HOME}/.cargo/config" COPY . . CMD ["cargo", "build", "--release", "--target", "x86_64-apple-darwin"]

I also tried the docker run command that is in the readme but that too gave me the same error.

oliashish avatar Sep 19 '22 06:09 oliashish

It looks like you're using sys crates that require C binding, so you can try this out https://github.com/joseluisq/rust-linux-darwin-builder#building--sys-crates

joseluisq avatar Sep 19 '22 10:09 joseluisq

@joseluisq Hello, i got same error when building my application. All stuck on dependency osskeys which uses openssl.

warning: osxcross: warning: possibly dangerous include path specified: '-I /usr/include' warning: osxcross: info: you can silence this warning via 'OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1' (env) warning: build/expando.c:2:10: fatal error: 'openssl/opensslconf.h' file not found warning: #include <openssl/opensslconf.h> warning: ^~~~~~~~~~~~~~~~~~~~~~~ warning: 1 error generated.

error: failed to run custom build command for openssl-sys v0.9.76

--- stderr thread 'main' panicked at ' Header expansion error: Error { kind: ToolExecError, message: "Command "o64-clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-apple-darwin" "-I" "/usr/include" "-Wall" "-Wextra" "-E" "build/expando.c" with args "o64-clang" did not execute successfully (status code exit status: 1)." }

Failed to find OpenSSL development headers.

I use the command you propose: CC=o64-clang \ CXX=o64-clang++ \ cargo build --target x86_64-apple-darwin

v-kamerdinerov avatar Oct 18 '22 17:10 v-kamerdinerov

It looks like an issue with this image when targeting darwin. As a workaround, tell your openssl crate to build a copy of OpenSSL itself with the vendored feature.

# ....
[dependencies]
openssl-sys = "0.9"
openssl = { version = "0.10", features = ["vendored"] }

joseluisq avatar Oct 18 '22 21:10 joseluisq