Skip to content

Commit 3f44233

Browse files
committed
Add OpenSSL installation to GCC setup for cross-compilation
1 parent e4d989d commit 3f44233

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

.github/workflows/graphs/build-test-publish.act

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ nodes:
7171
x: -3030
7272
y: 4770
7373
inputs:
74-
install: mingw-w64-ucrt-x86_64-gcc
74+
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-openssl
7575
- id: concurrent-for-each-loop-v1-starfish-white-whale
7676
type: core/concurrent-for-each-loop@v1
7777
position:
@@ -86,7 +86,7 @@ nodes:
8686
y: 4830
8787
inputs:
8888
script: |-
89-
echo "$RUNNER_TEMP\\msys64\\ucrt64\\bin" >> "$GITHUB_PATH"
89+
echo "$RUNNER_TEMP\\msys64\\mingw64\\bin" >> "$GITHUB_PATH"
9090
gcc --version
9191
shell: bash
9292
comment: Set gcc to PATH
@@ -96,7 +96,7 @@ nodes:
9696
x: 700
9797
y: 2310
9898
inputs:
99-
script: >
99+
script: |-
100100
if [[ -z "$CURRENT_OS" || -z "$ARCH" || -z "$OUTPUT_DIR" ]]; then
101101
echo "CURRENT_OS, ARCH and OUTPUT_DIR must be set."
102102
echo "CURRENT_OS: $CURRENT_OS"
@@ -107,12 +107,14 @@ nodes:
107107

108108

109109
export CC=gcc
110+
export CXX=g++
110111

111112
# Cgo requires a cross-compiler that is not installed on GitHub runners
112113
as of now.
113114

114115
[[ "$CURRENT_OS" == "linux" && "$ARCH" == "arm64" ]] &&
115-
CC=aarch64-linux-gnu-gcc
116+
CC=aarch64-linux-gnu-gcc &&
117+
CXX=aarch64-linux-gnu-g++
116118

117119

118120
# Download P4 API SDK for the target platform
@@ -137,12 +139,18 @@ nodes:
137139
linux)
138140
[[ "$ARCH" == "arm64" ]] && P4_LIB="$(pwd)/p4api/linux-aarch64/lib" || P4_LIB="$(pwd)/p4api/linux-x86_64/lib"
139141
P4_CGO_CPPFLAGS="-I$P4_INCLUDE"
140-
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api -lssl -lcrypto"
142+
if [[ "$ARCH" == "arm64" ]]; then
143+
# Cross-compile needs static OpenSSL (no arm64 libssl-dev on x64 runner)
144+
SSL_LIB="$(pwd)/p4api/ssl-linux-${ARCH}/lib"
145+
bash setup-openssl.sh linux "$ARCH" "$SSL_LIB"
146+
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api $SSL_LIB/libssl.a $SSL_LIB/libcrypto.a"
147+
else
148+
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api -lssl -lcrypto"
149+
fi
141150
;;
142151
macos)
143152
P4_LIB="$(pwd)/p4api/macos/lib"
144153
P4_CGO_CPPFLAGS="-I$P4_INCLUDE"
145-
# Build static OpenSSL for macOS (not available on the runner)
146154
SSL_LIB="$(pwd)/p4api/ssl-macos-${ARCH}/lib"
147155
bash setup-openssl.sh macos "$ARCH" "$SSL_LIB"
148156
P4_CGO_LDFLAGS="-L$P4_LIB -lp4api $SSL_LIB/libssl.a $SSL_LIB/libcrypto.a -framework ApplicationServices -framework Foundation -framework Security -framework CoreFoundation"
@@ -196,7 +204,7 @@ nodes:
196204
cp "$OUTPUT_CLI" "$TMP_ACTRUN"
197205
# encoding needed since default on Windows is cp1252
198206
PYTHONIOENCODING=utf-8 python tests_e2e/tests_e2e.py
199-
rm "$TMP_ACTRUN"
207+
rm "$TMP_ACTRUN" || true
200208
else
201209
echo "OS and ARCH do not match the current system ($OS != $CURRENT_OS $ARCH != $CURRENT_ARCH). Skipping e2e tests."
202210
fi
@@ -223,6 +231,8 @@ nodes:
223231
build_lib
224232

225233
run_e2e_tests
234+
235+
exit 0
226236
env: []
227237
comment: build the cli and dll
228238
- id: length-v1-nectarine-squirrel-peacock
@@ -288,8 +298,8 @@ nodes:
288298
inputs:
289299
script: |-
290300
# check the build node script
291-
sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
292-
comment: Install a GCC version capable of cross-compiling
301+
sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
302+
comment: Install a GCC/G++ version capable of cross-compiling
293303
- id: switch-platform-v1-dog-snake-ivory
294304
type: core/switch-platform@v1
295305
position:

setup-openssl.sh

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -euo pipefail
88
# Examples:
99
# ./setup-openssl.sh macos arm64 ./ssl-libs
1010
# ./setup-openssl.sh macos x64 ./ssl-libs
11+
# ./setup-openssl.sh linux arm64 ./ssl-libs (uses aarch64-linux-gnu-gcc)
1112

1213
OPENSSL_VERSION="3.5.0"
1314

@@ -20,29 +21,15 @@ if [[ -f "$OUTPUT_LIB_DIR/libssl.a" ]]; then
2021
exit 0
2122
fi
2223

23-
# Determine OpenSSL configure target
24-
case "$OS" in
25-
macos)
26-
if [[ "$ARCH" == "arm64" ]]; then
27-
OPENSSL_TARGET="darwin64-arm64-cc"
28-
else
29-
OPENSSL_TARGET="darwin64-x86_64-cc"
30-
fi
31-
;;
32-
linux)
33-
if [[ "$ARCH" == "arm64" ]]; then
34-
OPENSSL_TARGET="linux-aarch64"
35-
else
36-
OPENSSL_TARGET="linux-x86_64"
37-
fi
38-
;;
39-
windows)
40-
OPENSSL_TARGET="mingw64"
41-
;;
42-
*)
43-
echo "Unsupported OS: $OS"
44-
exit 1
45-
;;
24+
# Determine OpenSSL configure target and cross-compiler
25+
OPENSSL_CC=""
26+
case "$OS/$ARCH" in
27+
macos/arm64) OPENSSL_TARGET="darwin64-arm64-cc" ;;
28+
macos/x64) OPENSSL_TARGET="darwin64-x86_64-cc" ;;
29+
linux/arm64) OPENSSL_TARGET="linux-aarch64"; OPENSSL_CC="aarch64-linux-gnu-gcc" ;;
30+
linux/x64) OPENSSL_TARGET="linux-x86_64" ;;
31+
windows/x64) OPENSSL_TARGET="mingw64" ;;
32+
*) echo "Unsupported: $OS/$ARCH"; exit 1 ;;
4633
esac
4734

4835
echo "Building static OpenSSL $OPENSSL_VERSION ($OPENSSL_TARGET) for $OS/$ARCH..."
@@ -56,10 +43,16 @@ tar xzf "$TMPDIR_SSL/openssl.tar.gz" -C "$TMPDIR_SSL"
5643

5744
OPENSSL_SRC="$TMPDIR_SSL/openssl-${OPENSSL_VERSION}"
5845

46+
# Build in a subshell with clean CC to avoid cross-compile-prefix doubling
5947
BUILD_LOG="$TMPDIR_SSL/build.log"
6048
(
6149
cd "$OPENSSL_SRC"
62-
./Configure "$OPENSSL_TARGET" no-shared no-tests no-apps no-docs --libdir=lib >> "$BUILD_LOG" 2>&1
50+
unset CC CXX
51+
CONFIGURE_ARGS="$OPENSSL_TARGET no-shared no-tests no-apps no-docs --libdir=lib"
52+
if [[ -n "$OPENSSL_CC" ]]; then
53+
CONFIGURE_ARGS="$CONFIGURE_ARGS CC=$OPENSSL_CC"
54+
fi
55+
./Configure $CONFIGURE_ARGS >> "$BUILD_LOG" 2>&1
6356
make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" build_libs >> "$BUILD_LOG" 2>&1
6457
) || { echo "OpenSSL build failed. Last 30 lines of build log:"; tail -30 "$BUILD_LOG"; exit 1; }
6558

0 commit comments

Comments
 (0)