Skip to content

Commit deee8a9

Browse files
committed
figure out where Swift lib paths are on CI
1 parent e93c785 commit deee8a9

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

.github/scripts/prep-gh-action.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# This script does a bit of extra preparation of the docker containers used to run the GitHub workflows
4+
# that are specific to this project's needs when building/testing. Note that this script runs on
5+
# every supported Linux distribution and macOS so it must adapt to the distribution that it is running.
6+
7+
if [[ "$(uname -s)" == "Linux" ]]; then
8+
# Install the basic utilities depending on the type of Linux distribution
9+
apt-get --help && apt-get update && TZ=Etc/UTC apt-get -y install curl make gpg tzdata
10+
yum --help && (curl --help && yum -y install curl) && yum install make gpg
11+
fi
12+
13+
set -e
14+
15+
while [ $# -ne 0 ]; do
16+
arg="$1"
17+
case "$arg" in
18+
--install-swiftly)
19+
installSwiftly=true
20+
;;
21+
--swift-main-snapshot)
22+
swiftMainSnapshot=true
23+
;;
24+
*)
25+
;;
26+
esac
27+
shift
28+
done
29+
30+
if [ "$installSwiftly" == true ]; then
31+
echo "Installing swiftly"
32+
33+
if [[ "$(uname -s)" == "Linux" ]]; then
34+
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && tar zxf swiftly-*.tar.gz && ./swiftly init -y --skip-install
35+
. "/root/.local/share/swiftly/env.sh"
36+
else
37+
export SWIFTLY_HOME_DIR="$(pwd)/swiftly-bootstrap"
38+
export SWIFTLY_BIN_DIR="$SWIFTLY_HOME_DIR/bin"
39+
export SWIFTLY_TOOLCHAINS_DIR="$SWIFTLY_HOME_DIR/toolchains"
40+
41+
curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && pkgutil --check-signature swiftly.pkg && pkgutil --verbose --expand swiftly.pkg "${SWIFTLY_HOME_DIR}" && tar -C "${SWIFTLY_HOME_DIR}" -xvf "${SWIFTLY_HOME_DIR}"/swiftly-*/Payload && "$SWIFTLY_HOME_DIR/bin/swiftly" init -y --skip-install
42+
43+
. "$SWIFTLY_HOME_DIR/env.sh"
44+
fi
45+
46+
hash -r
47+
48+
if [ -n "$GITHUB_ENV" ]; then
49+
echo "Updating GitHub environment"
50+
echo "PATH=$PATH" >> "$GITHUB_ENV" && echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_TOOLCHAINS_DIR=$SWIFTLY_TOOLCHAINS_DIR" >> "$GITHUB_ENV"
51+
fi
52+
53+
selector=()
54+
runSelector=()
55+
56+
if [ "$swiftMainSnapshot" == true ]; then
57+
echo "Installing latest main-snapshot toolchain"
58+
selector=("main-snapshot")
59+
runSelector=("+main-snapshot")
60+
elif [ -f .swift-version ]; then
61+
echo "Installing selected swift toolchain from .swift-version file"
62+
selector=()
63+
runSelector=()
64+
else
65+
echo "Installing latest toolchain"
66+
selector=("latest")
67+
runSelector=("+latest")
68+
fi
69+
70+
swiftly install --post-install-file=post-install.sh "${selector[@]}"
71+
72+
if [ -f post-install.sh ]; then
73+
echo "Performing swift toolchain post-installation"
74+
chmod u+x post-install.sh && ./post-install.sh
75+
fi
76+
77+
echo "Displaying swift version"
78+
swiftly run "${runSelector[@]}" swift --version
79+
80+
if [[ "$(uname -s)" == "Linux" ]]; then
81+
CC=clang swiftly run "${runSelector[@]}" "$(dirname "$0")/install-libarchive.sh"
82+
fi
83+
else
84+
if [[ "$(uname -s)" == "Linux" ]]; then
85+
"$(dirname "$0")/install-libarchive.sh"
86+
fi
87+
fi

.github/scripts/validate_sample.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ declare -r RESET='\033[0m'
1111
declare -r sampleDir="$1"
1212
declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'
1313

14+
echo "Using Swift: $(which swift)"
15+
1416
echo ""
1517
echo ""
1618
echo "========================================================================"

Samples/SwiftAndJavaJarSampleLib/ci-validate.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ echo "CLASSPATH = ${CLASSPATH}"
3434

3535
$JAVAC -cp "${CLASSPATH}" Example.java
3636

37-
# TODO: move all this into Gradle or SwiftPM and make it easier to get the right classpath for running
37+
# FIXME: move all this into Gradle or SwiftPM and make it easier to get the right classpath for running
3838
if [ "$(uname -s)" = 'Linux' ]
3939
then
4040
SWIFT_LIB_PATHS=/usr/lib/swift/linux
@@ -44,6 +44,7 @@ then
4444
SWIFT_CORE_LIB=$(find "$HOME"/.local -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1)
4545
if [ -n "$SWIFT_CORE_LIB" ]; then
4646
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(dirname "$SWIFT_CORE_LIB")"
47+
ls "$SWIFT_LIB_PATHS"
4748
else
4849
# maybe there is one installed system-wide in /usr/lib?
4950
SWIFT_CORE_LIB2=$(find /usr/lib -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1)
@@ -53,8 +54,14 @@ then
5354
fi
5455
elif [ "$(uname -s)" = 'Darwin' ]
5556
then
56-
SWIFT_LIB_PATHS=$(find "$(swiftly use --print-location)" | grep dylib$ | grep libswiftCore | grep macos | xargs dirname)
57+
SWIFT_LIB_PATHS=$(find "$(swiftly use --print-location)" | grep dylib$ | grep libswiftCore | grep macos | head -n1 | xargs dirname)
58+
if [ -z "${SWIFT_LIB_PATHS}" ]
59+
then
60+
# last resort; on CI we just search where we have swift libs
61+
SWIFT_LIB_PATHS=$(find / 2> /dev/null | grep dylib$ | grep libswiftCore | grep macos | xargs dirname)
62+
fi
5763
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(pwd)/$(find . | grep libMySwiftLibrary.dylib$ | sort | head -n1 | xargs dirname)"
64+
5865
fi
5966
echo "SWIFT_LIB_PATHS = ${SWIFT_LIB_PATHS}"
6067

0 commit comments

Comments
 (0)