Skip to content

Commit 62c8581

Browse files
authored
[Static Linux SDK] Build script improvements. (#417)
* [Static Linux SDK] Build script improvements. When running on an aarch64 host, we need to download a different version of the Swift compiler in order to do the build. If we run the build on a macOS host, we also have to tell the update-checkout script to fetch all the required dependencies (even Linux-only ones). Also tell Foundation where swift-collections lives, to avoid it fetching another copy. * [CI] Run Docker builds in the right directory. Make sure we run the Docker builds in the directory containing the Dockerfile. Also, prefer lists of arguments rather than strings, especially when including filenames.
1 parent cd8fc32 commit 62c8581

File tree

5 files changed

+73
-20
lines changed

5 files changed

+73
-20
lines changed

ci_test.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
import urllib.request
1717
import json
1818
import subprocess
19+
import shlex
1920
import sys
2021
import os
2122

2223

2324
def run_command(cmd, log_file=None):
24-
print("Running: {}".format(cmd))
25+
if isinstance(cmd, str):
26+
cmd = shlex.split(cmd)
27+
print("Running: {}".format(shlex.join(cmd)))
2528
sys.stdout.flush()
2629
if log_file:
2730
file = open(log_file, "w")
28-
p = subprocess.Popen(cmd, shell=True, stdout=file, stderr=file)
2931
else:
30-
p = subprocess.Popen(cmd, shell=True)
31-
32+
file = None
33+
p = subprocess.Popen(cmd, stdout=file, stderr=file)
34+
3235
(output, err) = p.communicate()
3336
return p.wait()
3437

@@ -62,30 +65,47 @@ def main():
6265
results = {}
6366
suite_status = True
6467
dockerfiles = get_dockerfiles()
68+
root_dir = os.path.dirname(os.path.realpath(__file__))
6569
for dockerfile in dockerfiles:
66-
docker_dir = os.path.dirname(os.path.realpath(__file__))
70+
# Make sure everything is relative
71+
dockerfile = os.path.relpath(os.path.realpath(dockerfile), root_dir)
72+
73+
docker_dir, docker_name = os.path.split(dockerfile)
74+
6775
print("Testing {}".format(dockerfile))
6876
sys.stdout.flush()
69-
log_file = dockerfile.replace(docker_dir,"").replace("/", "_")
77+
log_file = dockerfile.replace("/", "_")
7078
log_file = "{}.log".format(log_file)
71-
cmd = "docker build --no-cache=true -f {dockerfile} .".format(dockerfile=dockerfile)
79+
cmd = [
80+
'docker', 'build', '--no-cache=true',
81+
'-f', dockerfile,
82+
docker_dir
83+
]
7284
if "buildx" in dockerfile:
7385
# if "buildx" is part of the path, we want to use the new buildx build system and build
7486
# for both amd64 and arm64.
75-
cmd = "docker buildx create --use"
76-
run_command(cmd, log_file)
77-
cmd = "docker buildx inspect --bootstrap"
78-
run_command(cmd, log_file)
79-
cmd = "docker buildx build --platform linux/arm64,linux/amd64 --no-cache=true -f {dockerfile} .".format(dockerfile=dockerfile)
80-
status = run_command(cmd, log_file)
87+
run_command("docker buildx create --use", log_file=log_file)
88+
run_command("docker buildx inspect --bootstrap", log_file=log_file)
89+
90+
cmd = [
91+
'docker', 'buildx', 'build',
92+
'--platform', 'linux/arm64,linux/amd64',
93+
'--no-cache=true',
94+
'-f', dockerfile,
95+
docker_dir
96+
]
97+
98+
status = run_command(cmd, log_file=log_file)
8199
results[dockerfile] = status
82100
if status != 0:
83101
suite_status = False
84102
results[dockerfile] = "FAILED"
85103
else:
86104
results[dockerfile] = "PASSED"
87105

88-
cmd = "mv {log} {results}{log}".format(log=log_file, results=results[dockerfile])
106+
cmd = [
107+
'mv', log_file, results[dockerfile] + log_file
108+
]
89109
run_command(cmd)
90110
print("[{}] - {}".format(results[dockerfile], dockerfile))
91111
sys.stdout.flush()

swift-ci/sdks/static-linux/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ ARG BORINGSSL_VERSION=fips-20220613
2424
ARG ICU_VERSION=maint/maint-69
2525
ARG ZLIB_VERSION=1.3.1
2626

27+
# Architecture to build on (empty means x86-64)
28+
ARG OS_ARCH_SUFFIX=
29+
2730
# ............................................................................
2831

2932
# Install development tools
@@ -62,7 +65,7 @@ ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
6265
OS_MAJOR_VER=$OS_MAJOR_VER \
6366
OS_MINOR_VER=$OS_MINOR_VER \
6467
OS_VER=$SWIFT_PLATFORM$OS_MAJOR_VER.$OS_MINOR_VER \
65-
SWIFT_WEBROOT="$SWIFT_WEBROOT/$SWIFT_PLATFORM$OS_MAJOR_VER$OS_MINOR_VER"
68+
SWIFT_WEBROOT="$SWIFT_WEBROOT/$SWIFT_PLATFORM$OS_MAJOR_VER$OS_MINOR_VER$OS_ARCH_SUFFIX"
6669

6770
COPY scripts/install-swift.sh /scripts/install-swift.sh
6871
RUN chmod ugo+x /scripts/install-swift.sh

swift-ci/sdks/static-linux/build

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,33 @@
1414
#
1515
# ===----------------------------------------------------------------------===
1616

17-
DOCKER=docker
17+
if [[ "$DOCKER" == "" ]]; then
18+
DOCKER=docker
19+
fi
20+
21+
case $(arch) in
22+
arm64|aarch64)
23+
OS_ARCH_SUFFIX=-aarch64
24+
;;
25+
amd64|x86_64)
26+
OS_ARCH_SUFFIX=
27+
;;
28+
*)
29+
echo "Unknown architecture $(arch)"
30+
exit 1
31+
;;
32+
esac
1833

1934
# Build the Docker image
20-
$(DOCKER) build -t static-swift-linux .
35+
$DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX -t static-swift-linux .
2136

2237
# Check-out the sources
2338
scripts/fetch-source.sh --clone-with-ssh --source-dir source
2439

2540
mkdir -p products
2641

2742
# Run the build
28-
$(DOCKER) run -it --rm \
43+
$DOCKER run -it --rm \
2944
-v ./source:/source \
3045
-v ./products:/products \
3146
static-swift-linux \

swift-ci/sdks/static-linux/scripts/build.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ while [ "$#" -gt 0 ]; do
144144
shift
145145
done
146146

147+
# Work out the host architecture
148+
case $(arch) in
149+
arm64|aarch64)
150+
host_arch=arm64
151+
;;
152+
amd64|x86_64)
153+
host_arch=x86_64
154+
;;
155+
*)
156+
echo "Unknown host architecture $(arch)"
157+
exit 1
158+
;;
159+
esac
160+
147161
# Change the commas for spaces
148162
archs="${archs//,/ }"
149163

@@ -662,7 +676,7 @@ EOF
662676
--compiler-vendor=apple \
663677
--bootstrapping hosttools \
664678
--build-linux-static --install-swift \
665-
--stdlib-deployment-targets linux-x86_64,linux-static-$arch \
679+
--stdlib-deployment-targets linux-$host_arch,linux-static-$arch \
666680
--build-stdlib-deployment-targets all \
667681
--musl-path=${build_dir}/sdk_root \
668682
--linux-static-arch=$arch \
@@ -724,6 +738,7 @@ EOF
724738
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=${build_dir}/$arch/dispatch \
725739
-D_SwiftFoundation_SourceDIR=${source_dir}/swift-project/swift-foundation \
726740
-D_SwiftFoundationICU_SourceDIR=${source_dir}/swift-project/swift-foundation-icu \
741+
-D_SwiftCollections_SourceDIR=${source_dir}/swift-project/swift-collections \
727742
-DCMAKE_Swift_COMPILER_WORKS=YES \
728743
-Ddispatch_DIR=${build_dir}/$arch/dispatch/cmake/modules
729744

swift-ci/sdks/static-linux/scripts/fetch-source.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ cd swift
164164
# Get its dependencies
165165
header "Fetching Swift Dependencies"
166166

167-
extra_args=--skip-history
167+
extra_args="--skip-history --all-repositories"
168168
if [[ $SWIFT_VERSION == scheme:* ]]; then
169169
utils/update-checkout ${clone_arg} --scheme ${SWIFT_VERSION#scheme:} ${extra_args}
170170
elif [[ $SWIFT_VERSION == tag:* ]]; then

0 commit comments

Comments
 (0)