Skip to content

Can't build on Apple Silicone, cross doesn't use custom image or hangs #558

Open
@ChzenChzen

Description

@ChzenChzen

I built custom docker image for solving openssl issues.
Dockerfile

FROM rustembedded/cross:aarch64-unknown-linux-musl
#FROM rustembedded/cross:aarch64-unknown-linux-musl-0.2.1 - the same issue
COPY openssl.sh /
RUN bash /openssl.sh linux-aarch64 aarch64-linux-musl-

ENV OPENSSL_DIR=/openssl \
    OPENSSL_INCLUDE_DIR=/openssl/include \
    OPENSSL_LIB_DIR=/openssl/lib

openssl.sh

set -ex

main() {
  local version=1.0.2t
  local os=$1 \
    triple=$2

  local dependencies=(
    ca-certificates
    curl
    m4
    make
    perl
  )

  # NOTE cross toolchain must be already installed
  apt-get update
  local purge_list=()
  for dep in ${dependencies[@]}; do
    if ! dpkg -L $dep; then
      apt-get install --no-install-recommends -y $dep
      purge_list+=($dep)
    fi
  done

  td=$(mktemp -d)

  pushd $td
  curl https://www.openssl.org/source/openssl-$version.tar.gz |
    tar --strip-components=1 -xz
  AR=${triple}ar CC=${triple}gcc ./Configure \
    --prefix=/openssl \
    no-dso \
    $os \
    -fPIC \
    ${@:3}
  nice make -j$(nproc)
  make install

  # clean up
  apt-get purge --auto-remove -y ${purge_list[@]}

  popd

  rm -rf $td
  rm $0
}

main "${@}"

My docker build command: docker build -t fomotoshi/openssl:latest cross/

Cross.toml

[target.aarch64-unknown-linux-musl]
image = "fomotoshi/openssl:latest"

my issue:

cross build --target aarch64-unknown-linux-musl
cross build --target aarch64-unknown-linux-musl
   Compiling openssl-sys v0.9.63
   Compiling socket2 v0.4.0
   Compiling aho-corasick v0.7.18
   Compiling atty v0.2.14
   Compiling futures-util v0.3.15
   Compiling indexmap v1.6.2
   Compiling futures-channel v0.3.15
   Compiling syn v1.0.72
   Compiling parking_lot v0.11.1
error: failed to run custom build command for `openssl-sys v0.9.63`

Caused by:
  process didn't exit successfully: `/Users/fomotoshi/Documents/projects/bitcoin_mixer/target/debug/build/openssl-sys-c7100d1a7e5f4dbd/build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR
  AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR
  AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR
  AARCH64_UNKNOWN_LINUX_MUSL_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_aarch64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_musl
  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_aarch64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "pkg-config has not been configured to support cross-compilation.\n\n                Install a sysroot for the target platform and configure it via\n                PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\n                cross-compiling wrapper for pkg-config and set it via\n                PKG_CONFIG environment variable."

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = aarch64-apple-darwin
  $TARGET = aarch64-unknown-linux-musl
  openssl-sys = 0.9.63

  ', /Users/fomotoshi/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.63/build/find_normal.rs:174:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

It looks like cross doesn't use my custom image for building.

I also tried to downgrade rustup to 1.49. and use minimal profile, but had the same issue.

rustup show 
Default host: aarch64-apple-darwin
rustup home:  /Users/fomotoshi/.rustup

installed toolchains
--------------------

stable-aarch64-apple-darwin
nightly-aarch64-apple-darwin
1.49-aarch64-apple-darwin (default)

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
aarch64-unknown-linux-musl

active toolchain
----------------

1.49-aarch64-apple-darwin (default)
rustc 1.49.0 (e1884a8e3 2020-12-29)
cross --version
cross 0.2.1
cargo 1.49.0 (d00d64df9 2020-12-05)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions