Skip to content

Commit 15f6410

Browse files
committed
[CI] add test to check libFoundation.so & co are not linked to the binary
1 parent 5ec9a90 commit 15f6410

File tree

4 files changed

+121
-23
lines changed

4 files changed

+121
-23
lines changed

.github/workflows/integration_tests.yml

+24-23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ on:
2323
type: boolean
2424
description: "Boolean to enable the test of the archive plugin. Defaults to true."
2525
default: true
26+
check_foundation_enabled:
27+
type: boolean
28+
description: "Boolean to enable the check for Foundation dependency. Defaults to true."
29+
default: true
2630
matrix_linux_command:
2731
type: string
2832
description: "The command of the current Swift version linux matrix job to execute."
@@ -88,15 +92,14 @@ jobs:
8892
COMMAND: ${{ inputs.matrix_linux_command }}
8993
EXAMPLE: ${{ matrix.examples }}
9094
run: |
91-
./scripts/integration_tests.sh
95+
# curl is already installed on Amazon Linux 2
96+
curl -s https://raw.githubusercontent.com/swift-server/swift-aws-lambda-runtime/refs/heads/main/.github/workflows/scripts/integration_tests.sh | bash
9297
echo "✅ The examples compile correctly"
9398
9499
test-archive-plugin:
95100
name: Test archive plugin
96101
if: ${{ inputs.archive_plugin_enabled }}
97102
runs-on: ubuntu-latest
98-
strategy:
99-
fail-fast: false
100103
steps:
101104
- name: Checkout repository
102105
uses: actions/checkout@v4
@@ -106,25 +109,23 @@ jobs:
106109
# https://github.com/actions/checkout/issues/766
107110
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
108111
- name: Test the archive plugin
109-
env:
110-
EXAMPLE: HelloWorld
111-
OUTPUT_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/bootstrap
112-
ZIP_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip
113112
run: |
114-
pushd Examples/${EXAMPLE}
113+
which curl || (apt -q update && apt -yq install curl)
114+
curl -s https://raw.githubusercontent.com/swift-server/swift-aws-lambda-runtime/refs/heads/main/.github/workflows/scripts/check-archive-plugin.sh | bash
115115
116-
# package the example (docker and swift toolchain are installed on the GH runner)
117-
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker
118-
119-
# did the plugin generated a Linux binary?
120-
[ -f ${OUTPUT_FILE} ]
121-
file ${OUTPUT_FILE} | grep --silent ELF
122-
123-
# did the plugin created a ZIP file?
124-
[ -f ${ZIP_FILE} ]
125-
126-
# does the ZIP file contain the bootstrap?
127-
unzip -l ${ZIP_FILE} | grep --silent bootstrap
128-
129-
echo "✅ The archive plugin is OK"
130-
popd
116+
check-foundation:
117+
name: No dependencies on Foundation
118+
if: ${{ inputs.check_foundation_enabled }}
119+
runs-on: ubuntu-latest
120+
steps:
121+
- name: Checkout repository
122+
uses: actions/checkout@v4
123+
with:
124+
persist-credentials: false
125+
- name: Mark the workspace as safe
126+
# https://github.com/actions/checkout/issues/766
127+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
128+
- name: Check for Foundation or ICU dependency
129+
run: |
130+
which curl || (apt -q update && apt -yq install curl)
131+
curl -s https://raw.githubusercontent.com/swift-server/swift-aws-lambda-runtime/refs/heads/main/.github/workflows/scripts/check-link-foundation.sh | bash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2017-2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
EXAMPLE=HelloWorld
17+
OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager
18+
OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap
19+
ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip
20+
21+
pushd Examples/${EXAMPLE} || exit 1
22+
23+
# package the example (docker and swift toolchain are installed on the GH runner)
24+
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1
25+
26+
# did the plugin generated a Linux binary?
27+
[ -f "${OUTPUT_FILE}" ]
28+
file "${OUTPUT_FILE}" | grep --silent ELF
29+
30+
# did the plugin created a ZIP file?
31+
[ -f "${ZIP_FILE}" ]
32+
33+
# does the ZIP file contain the bootstrap?
34+
unzip -l "${ZIP_FILE}" | grep --silent bootstrap
35+
36+
echo "✅ The archive plugin is OK"
37+
popd || exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2017-2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
EXAMPLE=APIGateway
21+
OUTPUT_DIR=.build/release
22+
OUTPUT_FILE=${OUTPUT_DIR}/APIGatewayLambda
23+
LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
24+
25+
pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}."
26+
27+
# recompile the example without the --static-swift-stdlib flag
28+
LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example."
29+
30+
# check if the binary exists
31+
if [ ! -f "${OUTPUT_FILE}" ]; then
32+
error "${OUTPUT_FILE} does not exist."
33+
fi
34+
35+
# Checking for Foundation or ICU dependencies
36+
echo "Checking for Foundation or ICU dependencies in ${OUTPUT_DIR}/${OUTPUT_FILE}."
37+
LIBRARIES=$(ldd ${OUTPUT_FILE} | awk '{print $1}')
38+
for LIB in ${LIBS_TO_CHECK}; do
39+
echo -n "Checking for ${LIB}... "
40+
41+
# check if the binary has a dependency on Foundation or ICU
42+
echo "${LIBRARIES}" | grep "${LIB}" # return 1 if not found
43+
44+
# 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
45+
SUCCESS=$?
46+
if [ "$SUCCESS" -eq 0 ]; then
47+
log "${LIB} found." && break
48+
else
49+
log "${LIB} not found."
50+
fi
51+
done
52+
53+
popd || fatal "Failed to change directory back to the root directory."
54+
55+
# exit code is the opposite of the grep exit code
56+
if [ "$SUCCESS" -eq 0 ]; then
57+
error "❌ At least one foundation lib was found, reporting the error."
58+
else
59+
log "✅ No foundation lib found, congrats!" && exit 0
60+
fi

0 commit comments

Comments
 (0)