@@ -22,7 +22,7 @@ case $(arch) in
22
22
arm64|aarch64)
23
23
OS_ARCH_SUFFIX=-aarch64
24
24
;;
25
- amd64|x86_64)
25
+ i386| amd64|x86_64)
26
26
OS_ARCH_SUFFIX=
27
27
;;
28
28
* )
@@ -31,17 +31,159 @@ case $(arch) in
31
31
;;
32
32
esac
33
33
34
+ SWIFT_VER=6.0
35
+
36
+ # Get the number of CPUs on this system
37
+ NPROC=$( which nproc)
38
+ if [ -x " $NPROC " ]; then
39
+ cpus=$( NPROC)
40
+ elif output=$( sysctl machdep.cpu.core_count 2> /dev/null) ; then
41
+ cpus=$( echo " $output " | cut -d ' :' -f 2 | tr -d ' ' )
42
+ else
43
+ cpus=4
44
+ fi
45
+
46
+ clean=false
47
+ fetch=true
48
+ build_docker=true
49
+ build_volume=
50
+ mem=10G
51
+
52
+ default_mem=$mem
53
+ default_cpus=$cpus
54
+ default_version=$SWIFT_VER
55
+
56
+ while [[ $# -gt 0 ]]; do
57
+ case $1 in
58
+ -h|--help)
59
+ cat << EOF
60
+ usage: build [-s <version>]
61
+
62
+ Build the Static SDK for Linux at-desk.
63
+
64
+ Options:
65
+
66
+ -a
67
+ --archs A list of architectures to build.
68
+
69
+ -c
70
+ --cpus Number of CPUs to build with. (default ${default_cpus} )
71
+
72
+ --clean Clean the build directories first.
73
+
74
+ -m
75
+ --memory Amount of memory to build with. (default ${default_mem} )
76
+
77
+ -s
78
+ --swift-version Specify the Swift version to build (default is ${default_version} )
79
+
80
+ -n
81
+ --no-fetch Don't fetch sources.
82
+
83
+ --skip-build-docker
84
+ Don't rebuild the Docker image.
85
+
86
+ --build-volume Specify the name of a Docker volume to hold the build data.
87
+ EOF
88
+ exit 0
89
+ ;;
90
+ -a|--archs)
91
+ archs=$2
92
+ shift
93
+ shift
94
+ ;;
95
+ -c|--cpus)
96
+ cpus=$2
97
+ shift
98
+ shift
99
+ ;;
100
+ -m|--memory)
101
+ mem=$2
102
+ shift
103
+ shift
104
+ ;;
105
+ -n|--no-fetch)
106
+ fetch=false
107
+ shift
108
+ ;;
109
+ --skip-build-docker)
110
+ build_docker=false
111
+ shift
112
+ ;;
113
+ --clean)
114
+ clean=true
115
+ shift
116
+ ;;
117
+ --build-volume)
118
+ build_volume=" $2 "
119
+ shift
120
+ shift
121
+ ;;
122
+ -s|--swift-version)
123
+ SWIFT_VER=" $2 "
124
+ shift
125
+ shift
126
+ ;;
127
+ -* |--* )
128
+ echo " Unknown argument $1 "
129
+ exit 1
130
+ ;;
131
+ * )
132
+ shift
133
+ ;;
134
+ esac
135
+ done
136
+
137
+ if $clean ; then
138
+ rm -rf source products
139
+ mkdir source products
140
+ fi
141
+
142
+ archs_arg=
143
+ if [ ! -z " $archs " ]; then
144
+ archs_arg=--archs
145
+ fi
146
+
147
+ if [ " ${SWIFT_VER} " = " main" ]; then
148
+ export SWIFT_VERSION=" scheme:main"
149
+ SWIFT_WEBROOT=" https://download.swift.org/development"
150
+ SWIFT_WEBROOT=" https://download.swift.org/swift-6.1-branch"
151
+ else
152
+ export SWIFT_VERSION=" scheme:release/${SWIFT_VER} "
153
+ SWIFT_WEBROOT=" https://download.swift.org/swift-${SWIFT_VER} -branch"
154
+ fi
155
+
34
156
# Build the Docker image
35
- $DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX -t static-swift-linux .
157
+ if $build_docker ; then
158
+ $DOCKER build $DOCKER_EXTRA_ARGS \
159
+ --build-arg " OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX " \
160
+ --build-arg " SWIFT_VERSION=$SWIFT_VERSION " \
161
+ --build-arg " SWIFT_WEBROOT=$SWIFT_WEBROOT " \
162
+ -t static-swift-linux . || exit 1
163
+ fi
36
164
37
165
# Check-out the sources
38
- scripts/fetch-source.sh --clone-with-ssh --source-dir source
166
+ if $fetch ; then
167
+ scripts/fetch-source.sh --clone-with-ssh --source-dir source
168
+ fi
39
169
40
170
mkdir -p products
171
+ build_args=
172
+ build_mount=
173
+ if [ ! -z " $build_volume " ]; then
174
+ build_args=" --build-dir /build"
175
+ build_mount=" -v ${build_volume} :/build"
176
+ fi
41
177
42
178
# Run the build
43
179
$DOCKER run -it --rm \
180
+ -c $cpus \
181
+ -m $mem \
44
182
-v ./source:/source \
45
183
-v ./products:/products \
184
+ --ulimit nofile=204800:256000 \
185
+ $build_mount \
46
186
static-swift-linux \
47
- /scripts/build.sh --source-dir /source --products-dir /products
187
+ /scripts/build.sh --source-dir /source --products-dir /products \
188
+ $build_args \
189
+ $archs_arg $archs
0 commit comments