Skip to content

Commit 31a7eda

Browse files
authored
[CI] add test to check libFoundation.so & co are not linked to the bi… (#441)
This adds a test in the `integration_test.yml` workflow to verify that `libFoundation.so`, `libFoundationInternationalization.so`, and `lib_FoundationICU.so` and not linked the the function binary. This is a follow up from the work make by @t089 to ensure that we don't accidentally link Foundation again in the future. Remove Foundation : #436 Add test in CI to ensure we don't link to foundation : #402
1 parent 8c1c1b6 commit 31a7eda

File tree

2 files changed

+81
-24
lines changed

2 files changed

+81
-24
lines changed

.github/workflows/integration_tests.yml

+21-24
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,12 @@ jobs:
8892
COMMAND: ${{ inputs.matrix_linux_command }}
8993
EXAMPLE: ${{ matrix.examples }}
9094
run: |
91-
./scripts/integration_tests.sh
92-
echo "✅ The examples compile correctly"
95+
.github/workflows/scripts/integration_tests.sh
9396
9497
test-archive-plugin:
9598
name: Test archive plugin
9699
if: ${{ inputs.archive_plugin_enabled }}
97100
runs-on: ubuntu-latest
98-
strategy:
99-
fail-fast: false
100101
steps:
101102
- name: Checkout repository
102103
uses: actions/checkout@v4
@@ -106,25 +107,21 @@ jobs:
106107
# https://github.com/actions/checkout/issues/766
107108
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
108109
- 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
113110
run: |
114-
pushd Examples/${EXAMPLE}
111+
.github/workflows/scripts/check-archive-plugin.sh
115112
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
113+
check-foundation:
114+
name: No dependencies on Foundation
115+
if: ${{ inputs.check_foundation_enabled }}
116+
runs-on: ubuntu-latest
117+
steps:
118+
- name: Checkout repository
119+
uses: actions/checkout@v4
120+
with:
121+
persist-credentials: false
122+
- name: Mark the workspace as safe
123+
# https://github.com/actions/checkout/issues/766
124+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
125+
- name: Check for Foundation or ICU dependency
126+
run: |
127+
.github/workflows/scripts/check-link-foundation.sh
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+
fatal "❌ 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)