Skip to content

Commit 00139a2

Browse files
authored
Merge pull request #8 from Adriftdev/feat/github-actions-release-workflow
fix: Further refine OpenSSL and Homebrew handling for macOS
2 parents 4329d67 + a1120e5 commit 00139a2

1 file changed

Lines changed: 36 additions & 52 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -65,75 +65,59 @@ jobs:
6565
run: |
6666
OPENSSL_VERSION="openssl@3" # Or openssl@1.1 if needed
6767
TARGET_ARCH_TUPLE="${{ matrix.platform.target }}" # e.g., x86_64-apple-darwin or aarch64-apple-darwin
68-
68+
6969
echo "Target architecture for OpenSSL: $TARGET_ARCH_TUPLE"
70-
71-
# Determine Homebrew path and arch command based on GITHUB_RUNNER_ARCH and TARGET_ARCH_TUPLE
72-
# GITHUB_RUNNER_ARCH will be X64 or ARM64
73-
# TARGET_ARCH_TUPLE is x86_64-apple-darwin or aarch64-apple-darwin
74-
75-
BREW_CMD=""
76-
ARCH_CMD=""
77-
70+
echo "Runner architecture: $(uname -m)"
71+
72+
BREW_EXECUTABLE=""
73+
ARCH_PREFIX=""
74+
7875
if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then
7976
echo "Configuring for x86_64 OpenSSL build."
80-
# If runner is ARM, we need to use arch -x86_64 for an x86_64 brew.
81-
# If runner is Intel, arch -x86_64 is benign.
82-
ARCH_CMD="arch -x86_64"
83-
# Standard Homebrew path for Intel installations, even on ARM runners under Rosetta
84-
BREW_CMD="$ARCH_CMD /usr/local/bin/brew"
85-
# Fallback for older setups or if /usr/local/bin/brew isn't the x86_64 one on an ARM machine.
86-
# However, /usr/local/bin/brew *should* be the Rosetta one on Apple Silicon.
87-
if ! $BREW_CMD --prefix $OPENSSL_VERSION > /dev/null 2>&1; then
88-
# On an ARM runner, an x86_64 brew might also be found via a direct path if it was installed by a user script
89-
# but the standard is /usr/local for Rosetta.
90-
# Let's assume /usr/local/bin/brew invoked with arch -x86_64 is correct.
91-
echo "Attempting to install OpenSSL for x86_64 via $BREW_CMD"
77+
ARCH_PREFIX="arch -x86_64"
78+
# Try standard paths for Homebrew under Rosetta
79+
if $ARCH_PREFIX /usr/local/bin/brew --version > /dev/null 2>&1; then
80+
BREW_EXECUTABLE="/usr/local/bin/brew"
81+
elif $ARCH_PREFIX /usr/local/homebrew/bin/brew --version > /dev/null 2>&1; then # Less common but possible
82+
BREW_EXECUTABLE="/usr/local/homebrew/bin/brew"
83+
else
84+
echo "::error::x86_64 Homebrew not found in /usr/local/bin/brew or /usr/local/homebrew/bin/brew using 'arch -x86_64'."
85+
exit 1
9286
fi
9387
else # aarch64-apple-darwin
9488
echo "Configuring for aarch64 OpenSSL build."
95-
# If runner is ARM, use native brew.
96-
# If runner is Intel, this target cannot be built (cross-compilation aarch64-apple-darwin from Intel macOS is not standard).
97-
# However, matrix.platform.target is aarch64-apple-darwin, so runner should be ARM macos-latest.
98-
ARCH_CMD="" # Native architecture
99-
BREW_CMD="/opt/homebrew/bin/brew" # Standard for ARM64 Homebrew
100-
if ! command -v $BREW_CMD > /dev/null 2>&1; then
101-
# Fallback if /opt/homebrew/bin/brew is not found (e.g. Intel runner, though matrix should prevent this)
102-
BREW_CMD="brew"
89+
# Standard path for ARM64 Homebrew
90+
if /opt/homebrew/bin/brew --version > /dev/null 2>&1; then
91+
BREW_EXECUTABLE="/opt/homebrew/bin/brew"
92+
elif command -v brew > /dev/null 2>&1; then # Fallback to brew in PATH
93+
BREW_EXECUTABLE="brew"
94+
echo "Using brew from PATH for aarch64, assuming it's the native ARM Homebrew."
95+
else
96+
echo "::error::ARM64 Homebrew not found in /opt/homebrew/bin/brew or PATH."
97+
exit 1
10398
fi
104-
echo "Attempting to install OpenSSL for aarch64 via $BREW_CMD"
10599
fi
106100
107-
$ARCH_CMD $BREW_CMD install $OPENSSL_VERSION
108-
OPENSSL_PREFIX=$($ARCH_CMD $BREW_CMD --prefix $OPENSSL_VERSION)
109-
101+
echo "Using Homebrew executable: $BREW_EXECUTABLE with prefix: '$ARCH_PREFIX'"
102+
103+
# Install/update OpenSSL
104+
$ARCH_PREFIX $BREW_EXECUTABLE update || echo "Brew update failed, proceeding with install..."
105+
$ARCH_PREFIX $BREW_EXECUTABLE install $OPENSSL_VERSION
106+
OPENSSL_PREFIX=$($ARCH_PREFIX $BREW_EXECUTABLE --prefix $OPENSSL_VERSION)
107+
110108
echo "OpenSSL prefix: $OPENSSL_PREFIX"
111109
if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then
112-
echo "::error::Failed to get Homebrew prefix or lib directory for $OPENSSL_VERSION with target $TARGET_ARCH_TUPLE using $BREW_CMD"
113-
echo "Attempting to find openssl installation path manually..."
114-
# Common paths
115-
if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then
116-
if [ -d "/usr/local/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/usr/local/opt/$OPENSSL_VERSION"; fi
117-
else # aarch64
118-
if [ -d "/opt/homebrew/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/opt/homebrew/opt/$OPENSSL_VERSION"; fi
119-
fi
120-
echo "Manual OpenSSL prefix: $OPENSSL_PREFIX"
121-
if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then
122-
echo "::error::Still could not find OpenSSL prefix. Please check Homebrew setup and OpenSSL installation for $TARGET_ARCH_TUPLE."
123-
exit 1
124-
fi
110+
echo "::error::Failed to get Homebrew prefix or lib directory for $OPENSSL_VERSION with target $TARGET_ARCH_TUPLE."
111+
exit 1
125112
fi
126-
113+
127114
echo "OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV
128-
echo "PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV # Prepend to existing
129-
130-
# Set target-specific variables that openssl-sys crate checks
131-
# (e.g., X86_64_APPLE_DARWIN_OPENSSL_DIR)
115+
echo "PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
116+
132117
TARGET_ARCH_ENV_PREFIX=$(echo "$TARGET_ARCH_TUPLE" | tr '[:lower:]-' '[:upper:]_')
133118
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV
134119
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV
135120
echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV
136-
# Also set the generic ones as a fallback
137121
echo "OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV
138122
echo "OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV
139123

0 commit comments

Comments
 (0)