Skip to content

Commit 76caa54

Browse files
authored
Update cross-compilation SDK script for Swift 5.7 (#5820)
### Motivation: `Utilities/build_ubuntu_cross_compilation_toolchain` is currently outdated. ### Modifications: Updated the script to use Swift 5.7, Ubuntu 22.04 (Jammy), and LLVM/clang 13.0.1. ### Result: Cross-compilation SDK script is working for latest versions of Swift and Ubuntu.
1 parent 28ee192 commit 76caa54

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Utilities/build_ubuntu_cross_compilation_toolchain

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
set -eu
1515

16-
export PATH="/bin:/usr/bin"
17-
VERSION=${VERSION:-4.1-RELEASE}
16+
export PATH="/bin:/usr/bin:$(brew --prefix)/bin"
17+
VERSION=${VERSION:-5.7-RELEASE}
1818
if [[ -z "${VERSION##*RELEASE*}" ]]; then
1919
branch=swift-${VERSION%%RELEASE}release
2020
elif [[ -z "${VERSION##DEVELOPMENT-SNAPSHOT*}" ]]; then
@@ -26,21 +26,20 @@ fi
2626
function usage() {
2727
echo >&2 "Usage: $0 TMP-DIR SWIFT-FOR-MACOS.pkg SWIFT-FOR-LINUX.tar.gz"
2828
echo >&2
29-
echo >&2 "Example: $0 /tmp/ ~/Downloads/swift-${VERSION}-osx.pkg ~/Downloads/swift-${VERSION}-ubuntu16.04.tar.gz"
29+
echo >&2 "Example: $0 /tmp/ ~/Downloads/swift-${VERSION}-osx.pkg ~/Downloads/swift-${VERSION}-ubuntu22.04.tar.gz"
3030
echo >&2
3131
echo >&2 "Complete example:"
3232
echo >&2 " # Download the Swift binaries for Ubuntu and macOS"
33-
echo >&2 " curl -o ~/Downloads/swift-${VERSION}-ubuntu16.04.tar.gz https://swift.org/builds/${branch}/ubuntu1604/swift-${VERSION}/swift-${VERSION}-ubuntu16.04.tar.gz"
33+
echo >&2 " curl -o ~/Downloads/swift-${VERSION}-ubuntu22.04.tar.gz https://swift.org/builds/${branch}/ubuntu2204/swift-${VERSION}/swift-${VERSION}-ubuntu22.04.tar.gz"
3434
echo >&2 " curl -o ~/Downloads/swift-${VERSION}-osx.pkg https://swift.org/builds/${branch}/xcode/swift-${VERSION}/swift-${VERSION}-osx.pkg"
3535
echo >&2 " # Compile the SDK and toolchain from that"
36-
echo >&2 " $0 /tmp/ ~/Downloads/swift-${VERSION}-osx.pkg ~/Downloads/swift-${VERSION}-ubuntu16.04.tar.gz"
36+
echo >&2 " $0 /tmp/ ~/Downloads/swift-${VERSION}-osx.pkg ~/Downloads/swift-${VERSION}-ubuntu22.04.tar.gz"
3737
echo >&2 " # Create a test application"
3838
echo >&2 " mkdir my-test-app"
3939
echo >&2 " cd my-test-app"
4040
echo >&2 " swift package init --type=executable"
4141
echo >&2 " # Build it for Ubuntu"
42-
echo >&2 " swift build --destination /tmp/cross-toolchain/ubuntu-xenial-destination.json"
43-
42+
echo >&2 " swift build --destination /tmp/cross-toolchain/ubuntu-jammy-destination.json"
4443
}
4544

4645
if [[ $# -ne 3 ]]; then
@@ -112,12 +111,12 @@ test -f "$linux_swift_pkg"
112111
# config
113112
blocks_h_url="https://raw.githubusercontent.com/apple/swift-corelibs-libdispatch/main/src/BlocksRuntime/Block.h"
114113
xc_tc_name="swift.xctoolchain"
115-
linux_sdk_name="ubuntu-xenial.sdk"
114+
linux_sdk_name="ubuntu-jammy.sdk"
116115
cross_tc_basename="cross-toolchain"
117-
clang_package_url="https://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz"
116+
clang_package_url="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz"
118117
ubuntu_mirror="http://gb.archive.ubuntu.com/ubuntu"
119-
packages_file="$ubuntu_mirror/dists/xenial/main/binary-amd64/Packages.gz"
120-
pkg_names=( libc6-dev linux-libc-dev libicu55 libgcc-5-dev libicu-dev libc6 libgcc1 libstdc++-5-dev libstdc++6 zlib1g-dev )
118+
packages_file="$ubuntu_mirror/dists/jammy/main/binary-amd64/Packages.gz"
119+
pkg_names=( libc6-dev linux-libc-dev libicu70 libgcc-12-dev libicu-dev libc6 libgcc-s1 libstdc++-12-dev libstdc++6 zlib1g-dev )
121120
pkgs=()
122121

123122
# url
@@ -131,7 +130,8 @@ function download_with_cache() {
131130
local out
132131
out="$dest/cache/$2"
133132
if [[ ! -f "$out" ]]; then
134-
curl --fail -s -o "$out" "$1"
133+
# Download with curl, also follow redirects.
134+
curl -L --fail -s -o "$out" "$1"
135135
fi
136136
echo "$out"
137137
}
@@ -221,7 +221,7 @@ find "$linux_sdk_name" -type l | while read -r line; do
221221
ln -s "${fixedlink#./}" "${line#./}"
222222
fi
223223
done
224-
ln -s 5 "$linux_sdk_name/usr/lib/gcc/x86_64-linux-gnu/5.4.0"
224+
ln -s 5 "$linux_sdk_name/usr/lib/gcc/x86_64-linux-gnu/9"
225225

226226
tmp=$(mktemp -d "$dest/tmp_pkgs_XXXXXX")
227227
unpack "$tmp" "$macos_swift_pkg"
@@ -244,17 +244,19 @@ fi
244244
# fix up glibc modulemap
245245
fix_glibc_modulemap "$cross_tc_basename/$xc_tc_name/usr/lib/swift/linux/x86_64/glibc.modulemap"
246246

247-
cat > "$cross_tc_basename/ubuntu-xenial-destination.json" <<EOF
247+
cat > "$cross_tc_basename/ubuntu-jammy-destination.json" <<EOF
248248
{
249249
"version": 1,
250250
"sdk": "$(pwd)/$cross_tc_basename/$linux_sdk_name",
251251
"toolchain-bin-dir": "$(pwd)/$cross_tc_basename/$xc_tc_name/usr/bin",
252-
"target": "x86_64-unknown-linux",
252+
"target": "x86_64-unknown-linux-gnu",
253253
"extra-cc-flags": [
254254
"-fPIC"
255255
],
256256
"extra-swiftc-flags": [
257-
"-use-ld=lld", "-tools-directory", "$(pwd)/$cross_tc_basename/$xc_tc_name/usr/bin"
257+
"-use-ld=lld",
258+
"-tools-directory", "$(pwd)/$cross_tc_basename/$xc_tc_name/usr/bin",
259+
"-sdk", "$(pwd)/$cross_tc_basename/$linux_sdk_name",
258260
],
259261
"extra-cpp-flags": [
260262
"-lstdc++"
@@ -263,7 +265,7 @@ cat > "$cross_tc_basename/ubuntu-xenial-destination.json" <<EOF
263265
EOF
264266

265267
echo
266-
echo "OK, your cross compilation toolchain for Ubuntu Xenial is now ready to be used"
268+
echo "OK, your cross compilation toolchain for Ubuntu Jammy is now ready to be used"
267269
echo " - SDK: $(pwd)/$cross_tc_basename/$linux_sdk_name"
268270
echo " - toolchain: $(pwd)/$cross_tc_basename/$xc_tc_name"
269-
echo " - SwiftPM destination.json: $(pwd)/$cross_tc_basename/ubuntu-xenial-destination.json"
271+
echo " - SwiftPM destination.json: $(pwd)/$cross_tc_basename/ubuntu-jammy-destination.json"

0 commit comments

Comments
 (0)