1+ #! /bin/bash
2+ # #===----------------------------------------------------------------------===##
3+ # #
4+ # # This source file is part of the Swift Bedrock Library open source project
5+ # #
6+ # # Copyright (c) 2025 Amazon.com, Inc. or its affiliates
7+ # # and the Swift Bedrock Library project authors
8+ # # Licensed under Apache License v2.0
9+ # #
10+ # # See LICENSE.txt for license information
11+ # # See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors
12+ # #
13+ # # SPDX-License-Identifier: Apache-2.0
14+ # #
15+ # #===----------------------------------------------------------------------===##
16+
17+ log () { printf -- " ** %s\n" " $* " >&2 ; }
18+ error () { printf -- " ** ERROR: %s\n" " $* " >&2 ; }
19+ fatal () { error " $@ " ; exit 1; }
20+
21+ EXAMPLE=converse
22+ OUTPUT_DIR=.build/release
23+ OUTPUT_FILE=${OUTPUT_DIR} /converse
24+ LIBS_TO_CHECK=" libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
25+
26+ pushd Examples/${EXAMPLE} || fatal " Failed to change directory to Examples/${EXAMPLE} ."
27+
28+ # recompile the example without the --static-swift-stdlib flag
29+ LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal " Failed to build the example."
30+
31+ # check if the binary exists
32+ if [ ! -f " ${OUTPUT_FILE} " ]; then
33+ error " ❌ ${OUTPUT_FILE} does not exist."
34+ fi
35+
36+ # Checking for Foundation or ICU dependencies
37+ echo " Checking for Foundation or ICU dependencies in ${OUTPUT_DIR} /${OUTPUT_FILE} ."
38+ LIBRARIES=$( ldd ${OUTPUT_FILE} | awk ' {print $1}' )
39+ for LIB in ${LIBS_TO_CHECK} ; do
40+ echo -n " Checking for ${LIB} ... "
41+
42+ # check if the binary has a dependency on Foundation or ICU
43+ echo " ${LIBRARIES} " | grep " ${LIB} " # return 1 if not found
44+
45+ # 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
46+ SUCCESS=$?
47+ if [ " $SUCCESS " -eq 0 ]; then
48+ log " ❌ ${LIB} found." && break
49+ else
50+ log " ✅ ${LIB} not found."
51+ fi
52+ done
53+
54+ popd || fatal " Failed to change directory back to the root directory."
55+
56+ # exit code is the opposite of the grep exit code
57+ if [ " $SUCCESS " -eq 0 ]; then
58+ fatal " ❌ At least one foundation lib was found, reporting the error."
59+ else
60+ log " ✅ No foundation lib found, congrats!" && exit 0
61+ fi
0 commit comments