Skip to content

Commit

Permalink
Merge pull request #392 from ionut-arm/update-bindgen
Browse files Browse the repository at this point in the history
Update bindgen
  • Loading branch information
Superhepper authored Feb 5, 2023
2 parents ce608d4 + 81b539a commit 9dac753
Show file tree
Hide file tree
Showing 9 changed files with 5,676 additions and 4,957 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Build the container
run: docker build -t ubuntucontainer tss-esapi/tests/ --file tss-esapi/tests/Dockerfile-ubuntu
- name: Run the container
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi --env RUST_TOOLCHAIN_VERSION=1.56.0 ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/all-ubuntu.sh
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi --env RUST_TOOLCHAIN_VERSION=1.57.0 ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/all-ubuntu.sh
# All in one job as I think it is a big overhead to build and run the Docker
# container?
tests-ubuntu:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ At the moment we test (via CI) and support the following Rust compiler versions:

* On Ubuntu we test with:
- The latest stable compiler version, as accessible through `rustup`.
- The 1.56 compiler version.
- The 1.57 compiler version.
* On Fedora we test with the compiler version included with the Fedora 35 release.

If you need support for other versions of the compiler, get in touch with us to see what we can do!
Expand Down
2 changes: 1 addition & 1 deletion tss-esapi-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://docs.rs/crate/tss-esapi-sys"
links = "tss2-esys"

[build-dependencies]
bindgen = { version = "0.59.1", optional = true }
bindgen = { version = "0.63.0", optional = true }
pkg-config = "0.3.18"
target-lexicon = "0.12.0"

Expand Down
1 change: 1 addition & 0 deletions tss-esapi-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn generate_from_system(esapi_out: PathBuf) {
.expect("Error converting OsString to String.");

bindgen::Builder::default()
.size_t_is_usize(false)
.clang_arg(format!("-I{}/tss2/", tss2_esys_include_path))
.clang_arg(format!("-I{}/tss2/", tss2_tctildr_include_path))
.clang_arg(format!("-I{}/tss2/", tss2_mu_include_path))
Expand Down
96 changes: 55 additions & 41 deletions tss-esapi-sys/regenerate-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,81 @@

set -euf -o pipefail

OPENSSL_GIT="https://github.com/openssl/openssl.git"
OPENSSL_VERSION="OpenSSL_1_1_1j"
TPM2_TSS_GIT="https://github.com/tpm2-software/tpm2-tss.git"
TPM2_TSS_VERSION="2.3.3"

cross-compile-openssl() {
# Prepare directory for cross-compiled OpenSSL files
mkdir -p /tmp/openssl-$1
export INSTALL_DIR=/tmp/openssl-$1
export SYSROOT="/tmp/sysroot"

git_checkout() {
if [ ! -d "/tmp/$(basename "$1" ".git")" ]; then
pushd /tmp
git clone "$1" --branch "$2"
popd
fi
}

prepare_sysroot() {
# Prepare the SYSROOT
[ -d "$SYSROOT" ] && rm -fr "$SYSROOT"
mkdir -p "$SYSROOT"

# Allow the `pkg-config` crate to cross-compile
export PKG_CONFIG_ALLOW_CROSS=1
export PKG_CONFIG_PATH="$SYSROOT"/lib/pkgconfig:"$SYSROOT"/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR="$SYSROOT"
}

cross-compile-openssl() {
pushd /tmp/openssl
# Compile and copy files over
./Configure $2 shared --prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR/openssl --cross-compile-prefix=$1-
./Configure $2 shared --prefix="$SYSROOT" --openssldir="$SYSROOT"/openssl --cross-compile-prefix=$1-
make clean
make depend
make -j$(nproc)
make install
make install_sw
popd

export INSTALL_DIR=
}

cross-compile-tpm2-tss() {
# Prepare directory for cross-compiled TSS lib
# `DESTDIR` is used in `make install` below to set the root of the installation paths.
# The `./configure` script accepts a `--prefix` input variable which sets the same root,
# but also adds it to the paths in `.pc` files used by `pkg-config`. This prevents the
# use of `PKG_CONFIG_SYSROOT_DIR`.
mkdir -p /tmp/tpm2-tss-$1
export DESTDIR=/tmp/tpm2-tss-$1
# Set sysroot to be used by the `pkg-config` wrapper
export SYSROOT=/tmp/tpm2-tss-$1

pushd /tpm2-tss
# Compile and copy files over
./configure --build=x86_64-pc-linux-gnu --host=$1 --target=$1 CC=$1-gcc \
LIBCRYPTO_CFLAGS="-I/tmp/openssl-$1/include" LIBCRYPTO_LIBS="-L/tmp/openssl-$1/lib -lcrypto"
pushd /tmp/tpm2-tss
[ ! -f configure ] && ./bootstrap
./configure --enable-fapi=no --prefix=/ --build=x86_64-pc-linux-gnu --host=$1 --target=$1 CC=$1-gcc
make clean
make -j$(nproc)
make install
make DESTDIR="$SYSROOT" install
popd

export DESTDIR=
}

# Download cross-compilers
apt update
apt install -y gcc-multilib
apt install -y gcc-arm-linux-gnueabi
apt install -y gcc-aarch64-linux-gnu

# Download OpenSSL source code
if [ ! -d "/tmp/openssl" ]; then
pushd /tmp
git clone https://github.com/openssl/openssl.git --branch $OPENSSL_VERSION
popd
fi
sudo apt update
sudo apt install -y gcc-multilib
sudo apt install -y gcc-arm-linux-gnueabi
sudo apt install -y gcc-aarch64-linux-gnu

# Download development version for tpm2-tss
sudo apt install -y libtss2-dev

# Download other dependencies
sudo apt install -y autoconf
sudo apt install -y autoconf-archive
sudo apt install -y cmake
sudo apt install -y libclang-dev
sudo apt install -y libtool
sudo apt install -y pkgconf

# Download OpenSSL, tpm2-tss and dependencies source code
git_checkout "$OPENSSL_GIT" "$OPENSSL_VERSION"
git_checkout "$TPM2_TSS_GIT" "$TPM2_TSS_VERSION"

# Regenerate bindings for x86_64-unknown-linux-gnu
cargo clean
cargo build --features generate-bindings
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/x86_64-unknown-linux-gnu.rs \;

# Allow the `pkg-config` crate to cross-compile
export PKG_CONFIG_ALLOW_CROSS=1
# Make the `pkg-config` crate use our wrapper
export PKG_CONFIG=$(pwd)/../tss-esapi/tests/pkg-config
# Clean and prepare SYSROOT
prepare_sysroot

# Regenerate bindings for aarch64-unknown-linux-gnu
cross-compile-openssl aarch64-linux-gnu linux-generic64
Expand All @@ -82,11 +93,14 @@ cargo clean
cargo build --features generate-bindings --target aarch64-unknown-linux-gnu
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/aarch64-unknown-linux-gnu.rs \;

# Clean and prepare SYSROOT
prepare_sysroot

# Regenerate bindings for armv7-unknown-linux-gnueabi
cross-compile-openssl arm-linux-gnueabi linux-generic32
cross-compile-tpm2-tss arm-linux-gnueabi

rustup target add armv7-unknown-linux-gnueabi
cargo clean
cargo build --features generate-bindings --target armv7-unknown-linux-gnueabi
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/arm-unknown-linux-gnueabi.rs \;
find ../target -name tss_esapi_bindings.rs -exec cp {} ./src/bindings/arm-unknown-linux-gnueabi.rs \;
Loading

0 comments on commit 9dac753

Please sign in to comment.