Skip to content

Commit b6e3a53

Browse files
Add support for compiling the provider on aarch64
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
1 parent 3d988e9 commit b6e3a53

File tree

5 files changed

+111
-3
lines changed

5 files changed

+111
-3
lines changed

parsec-openssl-sys2/build.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ fn main() -> std::io::Result<()> {
3232
.size_t_is_usize(true);
3333

3434
// Build the bindings
35-
let openssl_bindings = openssl_builder
36-
.generate()
37-
.map_err(|_| Error::new(ErrorKind::Other, "Unable to generate bindings to openssl"))?;
35+
let openssl_bindings = openssl_builder.generate().map_err(|e| {
36+
Error::new(
37+
ErrorKind::Other,
38+
format!("Unable to generate bindings to openssl: {}", e),
39+
)
40+
})?;
3841

3942
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
4043
openssl_bindings.write_to_file(out_path.join("openssl_bindings.rs"))?;

tests/cross-compile.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 Contributors to the Parsec project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -xeuf -o pipefail
7+
8+
# Allow the `pkg-config` crate to cross-compile
9+
export PKG_CONFIG_ALLOW_CROSS=1
10+
# Make the `pkg-config` crate use our wrapper
11+
export PKG_CONFIG=/tmp/parsec-openssl-provider/tests/pkg-config
12+
13+
export SYSROOT=/tmp/aarch64-linux-gnu
14+
export RUSTFLAGS="-lcrypto -L/tmp/aarch64-linux-gnu/lib"
15+
cd /tmp/parsec-openssl-provider
16+
cargo build --target aarch64-unknown-linux-gnu \
17+
--config 'target.aarch64-unknown-linux-gnu.linker="aarch64-linux-gnu-gcc"'
18+
19+
cd parsec-openssl-provider-shared
20+
cargo build --target aarch64-unknown-linux-gnu \
21+
--config 'target.aarch64-unknown-linux-gnu.linker="aarch64-linux-gnu-gcc"'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 Contributors to the Parsec project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Cross compile the OpenSSL library for a given target
7+
8+
set -xeuf -o pipefail
9+
10+
rustup target add aarch64-unknown-linux-gnu
11+
12+
OPENSSL_VERSION="openssl-3.0.2"
13+
git clone https://github.com/openssl/openssl.git --branch $OPENSSL_VERSION
14+
15+
# Prepare directory for cross-compiled OpenSSL files
16+
mkdir -p /tmp/$1
17+
export INSTALL_DIR=/tmp/$1
18+
19+
pushd /tmp/openssl
20+
# Compile and copy files over
21+
./Configure $2 shared --prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR/openssl --cross-compile-prefix=$1-
22+
make clean
23+
make depend
24+
make -j$(nproc)
25+
make install
26+
popd
27+
28+
unset INSTALL_DIR
29+
30+
pushd /usr/include/openssl
31+
ln -s /tmp/$1/include/openssl/opensslconf.h .
32+
ln -s /tmp/$1/include/openssl/configuration.h .
33+
popd
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2024 Contributors to the Parsec project.
2+
# SPDX-License-Identifier: Apache-2.0
3+
FROM ubuntu:22.04
4+
5+
RUN apt update && apt-get -y upgrade
6+
RUN apt install -y autoconf-archive libcmocka0 libcmocka-dev procps
7+
RUN apt install -y iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev doxygen libjson-c-dev
8+
RUN apt install -y --fix-missing wget python3 cmake clang
9+
RUN apt install -y libini-config-dev curl libgcc1
10+
RUN apt install -y python3-distutils libclang-11-dev protobuf-compiler python3-pip
11+
RUN apt install -y libgcrypt20-dev uuid-dev
12+
RUN apt install -y git gcc
13+
14+
15+
# Setup git config
16+
RUN git config --global user.email "some@email.com"
17+
RUN git config --global user.name "Parsec Team"
18+
19+
WORKDIR /tmp
20+
21+
# Install Rust toolchain for all users
22+
# This way of installing allows all users to call the same binaries, but non-root
23+
# users cannot modify the toolchains or install new ones.
24+
# See: https://github.com/rust-lang/rustup/issues/1085
25+
ENV RUSTUP_HOME /opt/rust
26+
ENV CARGO_HOME /opt/rust
27+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path
28+
ENV PATH="/root/.cargo/bin:/opt/rust/bin:${PATH}"
29+
30+
# Install aarch64-none-linux-gnu cross compilation toolchain
31+
RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766 -O aarch64-gcc.tar.xz
32+
RUN tar --strip-components=1 -C /usr/ -xvf aarch64-gcc.tar.xz
33+
RUN rm aarch64-gcc.tar.xz
34+
35+
# Install cross-compilers
36+
RUN apt install -y gcc-multilib
37+
RUN apt install -y gcc-arm-linux-gnueabihf
38+
RUN apt install -y gcc-aarch64-linux-gnu
39+
40+
WORKDIR /tmp
41+
42+
# Copy OpenSSL cross-compilation script
43+
COPY cross-compile-openssl.sh /tmp/
44+
# Cross-compile OpenSSL for Linux on aarch64
45+
RUN ./cross-compile-openssl.sh aarch64-linux-gnu linux-generic64

tests/pkg-config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
unset PKG_CONFIG_PATH
4+
export PKG_CONFIG_LIBDIR=${SYSROOT}/lib/pkgconfig:${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig:${SYSROOT}/usr/local/lib/pkgconfig
5+
6+
exec pkg-config "$@"

0 commit comments

Comments
 (0)