|  | 
| 1 | 1 | #!/bin/bash | 
| 2 | 2 | 
 | 
| 3 |  | -set -ex | 
|  | 3 | +set -exo pipefail | 
| 4 | 4 | 
 | 
| 5 |  | -# --- Declare the following variables for tests | 
| 6 |  | -# export TARGET=x86_64-unknown-linux-gnu | 
| 7 |  | -# export TARGET=aarch64-apple-darwin | 
| 8 |  | -# export DEBUG_OR_RELEASE=debug | 
| 9 |  | -# export OPENSSL_DIR=/usr/local/openssl | 
| 10 |  | -# export SKIP_SERVICES_TESTS="--skip hsm" | 
| 11 |  | - | 
| 12 |  | -ROOT_FOLDER=$(pwd) | 
| 13 |  | - | 
| 14 |  | -if [ "$DEBUG_OR_RELEASE" = "release" ]; then | 
| 15 |  | -  # First build the Debian and RPM packages. It must come at first since | 
| 16 |  | -  rm -rf target/"$TARGET"/debian | 
| 17 |  | -  rm -rf target/"$TARGET"/generate-rpm | 
| 18 |  | - | 
| 19 |  | -  if [ -f /etc/redhat-release ]; then | 
| 20 |  | -    cargo build --features non-fips --target "$TARGET" --release | 
| 21 |  | -    cargo install --version 0.16.0 cargo-generate-rpm --force | 
| 22 |  | -    cargo generate-rpm --target "$TARGET" -p crate/cli | 
| 23 |  | -  elif [ -f /etc/debian_version ]; then | 
| 24 |  | -    cargo install --version 2.4.0 cargo-deb --force | 
| 25 |  | -    cargo deb --target "$TARGET" -p cosmian_cli | 
| 26 |  | -  fi | 
| 27 |  | -fi | 
|  | 5 | +# export FEATURES="non-fips" | 
| 28 | 6 | 
 | 
| 29 | 7 | if [ -z "$TARGET" ]; then | 
| 30 |  | -  echo "Error: TARGET is not set." | 
|  | 8 | +  echo "Error: TARGET is not set. Examples of TARGET are x86_64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin." | 
| 31 | 9 |   exit 1 | 
| 32 | 10 | fi | 
| 33 | 11 | 
 | 
| 34 | 12 | if [ "$DEBUG_OR_RELEASE" = "release" ]; then | 
| 35 | 13 |   RELEASE="--release" | 
| 36 | 14 | fi | 
| 37 | 15 | 
 | 
| 38 |  | -if [ -z "$SKIP_SERVICES_TESTS" ]; then | 
| 39 |  | -  echo "Info: SKIP_SERVICES_TESTS is not set." | 
| 40 |  | -  unset SKIP_SERVICES_TESTS | 
|  | 16 | +if [ -n "$FEATURES" ]; then | 
|  | 17 | +  FEATURES="--features $FEATURES" | 
| 41 | 18 | fi | 
| 42 | 19 | 
 | 
| 43 |  | -rustup target add "$TARGET" | 
| 44 |  | - | 
| 45 |  | -if [ -f /etc/lsb-release ]; then | 
| 46 |  | -  bash .github/reusable_scripts/test_utimaco.sh | 
|  | 20 | +if [ -z "$FEATURES" ]; then | 
|  | 21 | +  echo "Info: FEATURES is not set." | 
|  | 22 | +  unset FEATURES | 
| 47 | 23 | fi | 
| 48 | 24 | 
 | 
| 49 |  | -cd "$ROOT_FOLDER" | 
| 50 |  | - | 
| 51 | 25 | if [ -z "$OPENSSL_DIR" ]; then | 
| 52 |  | -  echo "Error: OPENSSL_DIR is not set." | 
|  | 26 | +  echo "Error: OPENSSL_DIR is not set. Example OPENSSL_DIR=/usr/local/openssl" | 
| 53 | 27 |   exit 1 | 
| 54 | 28 | fi | 
| 55 | 29 | 
 | 
|  | 30 | +rustup target add "$TARGET" | 
|  | 31 | + | 
| 56 | 32 | # shellcheck disable=SC2086 | 
| 57 |  | -cargo build --target $TARGET $RELEASE \ | 
| 58 |  | -  --features non-fips \ | 
| 59 |  | -  -p cosmian_cli \ | 
| 60 |  | -  -p cosmian_pkcs11 | 
|  | 33 | +cargo build -p cosmian_cli -p cosmian_pkcs11 --target $TARGET $RELEASE $FEATURES | 
|  | 34 | + | 
|  | 35 | +COSMIAN_CLI_EXE="target/$TARGET/$DEBUG_OR_RELEASE/cosmian" | 
| 61 | 36 | 
 | 
| 62 |  | -TARGET_FOLDER=./target/"$TARGET/$DEBUG_OR_RELEASE" | 
| 63 |  | -"${TARGET_FOLDER}"/cosmian -h | 
|  | 37 | +# Test binary functionality | 
|  | 38 | +."/$COSMIAN_CLI_EXE" --help | 
| 64 | 39 | 
 | 
|  | 40 | +# Check for dynamic OpenSSL linkage | 
| 65 | 41 | if [ "$(uname)" = "Linux" ]; then | 
| 66 |  | -  ldd "${TARGET_FOLDER}"/cosmian | grep ssl && exit 1 | 
|  | 42 | +  LDD_OUTPUT=$(ldd "$COSMIAN_CLI_EXE") | 
|  | 43 | +  echo "$LDD_OUTPUT" | 
|  | 44 | +  if echo "$LDD_OUTPUT" | grep -qi ssl; then | 
|  | 45 | +    echo "Error: Dynamic OpenSSL linkage detected on Linux (ldd | grep ssl)." | 
|  | 46 | +    exit 1 | 
|  | 47 | +  fi | 
| 67 | 48 | else | 
| 68 |  | -  otool -L "${TARGET_FOLDER}"/cosmian | grep openssl && exit 1 | 
|  | 49 | +  OTOOL_OUTPUT=$(otool -L "$COSMIAN_CLI_EXE") | 
|  | 50 | +  echo "$OTOOL_OUTPUT" | 
|  | 51 | +  if echo "$OTOOL_OUTPUT" | grep -qi ssl; then | 
|  | 52 | +    echo "Error: Dynamic OpenSSL linkage detected on macOS (otool -L | grep openssl)." | 
|  | 53 | +    exit 1 | 
|  | 54 | +  fi | 
| 69 | 55 | fi | 
| 70 |  | - | 
| 71 |  | -find . -type d -name cosmian-findex-server -exec rm -rf \{\} \; -print || true | 
| 72 |  | -rm -f /tmp/*.json /tmp/*.toml | 
| 73 |  | - | 
| 74 |  | -export RUST_LOG="fatal,cosmian_cli=error,cosmian_findex_client=debug,cosmian_kms_client=debug" | 
| 75 |  | - | 
| 76 |  | -# shellcheck disable=SC2086 | 
| 77 |  | -cargo test --target $TARGET $RELEASE \ | 
| 78 |  | -  --features non-fips \ | 
| 79 |  | -  -p cosmian_cli \ | 
| 80 |  | -  -p cosmian_pkcs11 \ | 
| 81 |  | -  -- --nocapture $SKIP_SERVICES_TESTS | 
0 commit comments