Failed to cross compile to arm64 and openssl
Hi, I'm creating this issue because i've spend a couple of DAYS trying to solve the following problem but no success.
I got a rust web server which has the following dependency openssl = { version = "=0.10.45", features = ["vendored"] } which is fails to compile when i use cross in Github Action. Previously it was working, but as i understand there is no longer support of openssl in cross so it is just started to fail. I've tried to install openssl, it is present in a system but during compilation i got the following error:
error: failed to run custom build command for `sasl2-sys v0.1.20+2.1.28`
Caused by:
process didn't exit successfully: `/target/release/build/sasl2-sys-f091b2042744285f/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=SASL2_STATIC
cargo:rerun-if-env-changed=LIBSASL2_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_gnu
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-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_gnu
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-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_gnu
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'Unable to find libsasl2 on your system. Hints:
* Have you installed the libsasl2 development package for your platform?
On Debian-based systems, try libsasl2-dev. On RHEL-based systems, try
cyrus-sasl-devel. On macOS with Homebrew, try cyrus-sasl.
* Have you incorrectly set the SASL2_STATIC environment variable when your
system only supports dynamic linking?
* Are you willing to enable the `vendored` feature to instead build and link
against a bundled copy of libsasl2?
', /cargo/registry/src/github.com-1ecc6299db9ec823/sasl2-sys-0.1.20+2.1.28/build.rs:342:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
This is my pipeline which was working previously:
...
jobs:
build:
name: Build for Raspberry PI
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.62.1-x86_64-unknown-linux-gnu
target: aarch64-unknown-linux-gnu
override: true
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target aarch64-unknown-linux-gnu
...
I had another pipeline which doesn't compile due to openssl but it is not cross compiling to another target and it was fixed just but adding those suggested commands.
I've tried adding following configuration but doesn't matter what i do openssl package can't detect openssl on a system
sudo apt install libssl-dev libsasl2-dev
touch $HOME/.cargo/config && cd $HOME/.cargo
echo [target.aarch64-unknown-linux-gnu] >> ./config
echo pre-build = [\"sudo apt install libssl-dev libsasl2-dev\"] >> ./config
and
sudo dpkg --add-architecture arm64
sudo apt-get update && sudo apt install libssl-dev libssl-dev:arm64 libsasl2-dev -y
sudo apt install gcc-aarch64-linux-gnu
sudo apt-get install build-essential gcc make perl dkms
touch $HOME/.cargo/config && cd $HOME/.cargo
echo "[target.aarch64-unknown-linux-gnu]" >> ./config
echo "linker = \"/usr/bin/aarch64-linux-gnu-gcc\"" >> ./config
Looking for help and suggestions for this, thank you very much
It's not clear how you're adding the configuration, but you're using the wrong config file in this example for using cross, the config file for cross is Cross.toml and located next to Cargo.toml, see https://github.com/cross-rs/cross/wiki/Configuration#config-file
.cargo/config is for telling cargo directly how to do stuff, what cross does is set this up for you in docker containers.
Everything needs to happen in the image used by cross, you do that either by creating your own Dockerfile
ARG CROSS_BASE_IMAGE
FROM $CROSS_BASE_IMAGE # shorthand for ghcr.io/cross-rs/aarch64-unknown-linux-gnu:v0.2.4 (or main depending on what cross you're using)
RUN dpkg --add-architecture && \
apt-get update && \
apt-get install --assume-yes libssl-dev libssl-dev:arm64 libsasl2-dev
and in Cross.toml
[target.aarch64-unknown-linux-gnu]
dockerfile = "Dockerfile"
or simply adding to Cross.toml
# Cross.toml
[target.aarch64-unknown-linux-gnu]
pre-build = ["sudo apt install libssl-dev libsasl2-dev"]
@Emilgardis pardon, i've probably forgot to update the section, but i've tried to use Cross.toml with your suggested configurations and all sorts of commands, and had no luck with it
- name: Build
run: |
cargo install --version 0.1.16 cross
cargo build --target aarch64-unknown-linux-gnu
# cross build --target aarch64-unknown-linux-gnu
I've also tried downgraded version of cross which includes openssl but still the same
You're not using cross in that example, but you're installing a cross from 2019
Does this work
- name: Build
run: |
cargo install cross
cross build --target aarch64-unknown-linux-gnu -v
together with
# Cross.toml
[target.aarch64-unknown-linux-gnu]
pre-build = ["sudo apt install libssl-dev libsasl2-dev"]
version 0.1.16 was released 2019, the latest release is from july 10 2022
Is this project available publicly? If not, can you post the logs from the build
You're not using cross in that example, but you're installing a cross from 2019
Does this work
- name: Build run: | cargo install cross cross build --target aarch64-unknown-linux-gnu -vtogether with
# Cross.toml [target.aarch64-unknown-linux-gnu] pre-build = ["sudo apt install libssl-dev libsasl2-dev"]version
0.1.16was released 2019, the latest release is from july 10 2022Is this project available publicly? If not, can you post the logs from the build
I think the problem is that you are missing libssl-dev:arm64 in cross.toml, which is different from Dockerfile you posted😂
There is final sulotion: https://github.com/cross-rs/cross/wiki/Recipes#openssl