Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 86 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,100 @@ jobs:
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu libssl-dev pkg-config

- name: Install OpenSSL (macOS)
- name: Install OpenSSL and Set Vars (macOS)
if: runner.os == 'macOS'
run: |
brew install openssl@3
echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV
echo "LDFLAGS=-L$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV
echo "CPPFLAGS=-I$(brew --prefix openssl@3)/include" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
OPENSSL_VERSION="openssl@3" # Or openssl@1.1 if needed
TARGET_ARCH_TUPLE="${{ matrix.platform.target }}" # e.g., x86_64-apple-darwin or aarch64-apple-darwin

echo "Target architecture for OpenSSL: $TARGET_ARCH_TUPLE"

# Determine Homebrew path and arch command based on GITHUB_RUNNER_ARCH and TARGET_ARCH_TUPLE
# GITHUB_RUNNER_ARCH will be X64 or ARM64
# TARGET_ARCH_TUPLE is x86_64-apple-darwin or aarch64-apple-darwin

BREW_CMD=""
ARCH_CMD=""

if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then
echo "Configuring for x86_64 OpenSSL build."
# If runner is ARM, we need to use arch -x86_64 for an x86_64 brew.
# If runner is Intel, arch -x86_64 is benign.
ARCH_CMD="arch -x86_64"
# Standard Homebrew path for Intel installations, even on ARM runners under Rosetta
BREW_CMD="$ARCH_CMD /usr/local/bin/brew"
# Fallback for older setups or if /usr/local/bin/brew isn't the x86_64 one on an ARM machine.
# However, /usr/local/bin/brew *should* be the Rosetta one on Apple Silicon.
if ! $BREW_CMD --prefix $OPENSSL_VERSION > /dev/null 2>&1; then
# On an ARM runner, an x86_64 brew might also be found via a direct path if it was installed by a user script
# but the standard is /usr/local for Rosetta.
# Let's assume /usr/local/bin/brew invoked with arch -x86_64 is correct.
echo "Attempting to install OpenSSL for x86_64 via $BREW_CMD"
fi
else # aarch64-apple-darwin
echo "Configuring for aarch64 OpenSSL build."
# If runner is ARM, use native brew.
# If runner is Intel, this target cannot be built (cross-compilation aarch64-apple-darwin from Intel macOS is not standard).
# However, matrix.platform.target is aarch64-apple-darwin, so runner should be ARM macos-latest.
ARCH_CMD="" # Native architecture
BREW_CMD="/opt/homebrew/bin/brew" # Standard for ARM64 Homebrew
if ! command -v $BREW_CMD > /dev/null 2>&1; then
# Fallback if /opt/homebrew/bin/brew is not found (e.g. Intel runner, though matrix should prevent this)
BREW_CMD="brew"
fi
echo "Attempting to install OpenSSL for aarch64 via $BREW_CMD"
fi

$ARCH_CMD $BREW_CMD install $OPENSSL_VERSION
OPENSSL_PREFIX=$($ARCH_CMD $BREW_CMD --prefix $OPENSSL_VERSION)

echo "OpenSSL prefix: $OPENSSL_PREFIX"
if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then
echo "::error::Failed to get Homebrew prefix or lib directory for $OPENSSL_VERSION with target $TARGET_ARCH_TUPLE using $BREW_CMD"
echo "Attempting to find openssl installation path manually..."
# Common paths
if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then
if [ -d "/usr/local/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/usr/local/opt/$OPENSSL_VERSION"; fi
else # aarch64
if [ -d "/opt/homebrew/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/opt/homebrew/opt/$OPENSSL_VERSION"; fi
fi
echo "Manual OpenSSL prefix: $OPENSSL_PREFIX"
if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then
echo "::error::Still could not find OpenSSL prefix. Please check Homebrew setup and OpenSSL installation for $TARGET_ARCH_TUPLE."
exit 1
fi
fi

echo "OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV # Prepend to existing

# Set target-specific variables that openssl-sys crate checks
# (e.g., X86_64_APPLE_DARWIN_OPENSSL_DIR)
TARGET_ARCH_ENV_PREFIX=$(echo "$TARGET_ARCH_TUPLE" | tr '[:lower:]-' '[:upper:]_')
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV
# Also set the generic ones as a fallback
echo "OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV


- name: Verify OpenSSL Env Vars (macOS)
if: runner.os == 'macOS'
run: |
echo "OPENSSL_ROOT_DIR is: $OPENSSL_ROOT_DIR"
echo "OPENSSL_DIR is: $OPENSSL_DIR"
echo "OPENSSL_LIB_DIR is: $OPENSSL_LIB_DIR"
echo "LDFLAGS is: $LDFLAGS"
echo "CPPFLAGS is: $CPPFLAGS"
echo "OPENSSL_INCLUDE_DIR is: $OPENSSL_INCLUDE_DIR"
echo "PKG_CONFIG_PATH is: $PKG_CONFIG_PATH"
TARGET_ARCH_TUPLE="${{ matrix.platform.target }}"
TARGET_ARCH_ENV_PREFIX=$(echo "$TARGET_ARCH_TUPLE" | tr '[:lower:]-' '[:upper:]_')
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR)"
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR)"
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR)"
echo "Listing $OPENSSL_DIR/lib/pkgconfig:"
ls -l "$OPENSSL_DIR/lib/pkgconfig" || echo "pkgconfig directory not found or OpenSSL_DIR not set."
echo "Contents of openssl.pc (if found):"
cat "$OPENSSL_DIR/lib/pkgconfig/openssl.pc" || echo "openssl.pc not found."

- name: Build binary
run: cargo build --release --locked --target ${{ matrix.platform.target }}
Expand Down
Loading