@@ -97,7 +97,7 @@ function declare_package
97
97
}
98
98
99
99
declare_package static_linux_sdk \
100
- " Swift statically linked SDK for Linux" \
100
+ " Swift Static SDK for Linux" \
101
101
" Apache-2.0" " https://swift.org/install/sdk"
102
102
declare_package swift " swift" " Apache-2.0" " https://swift.org"
103
103
declare_package musl " musl" " MIT" " https://musl.org"
@@ -109,9 +109,13 @@ declare_package curl "curl" "MIT" "https://curl.se"
109
109
declare_package boringssl " boringssl" " OpenSSL AND ISC AND MIT" \
110
110
" https://boringssl.googlesource.com/boringssl/"
111
111
declare_package zlib " zlib" " Zlib" " https://zlib.net"
112
+ declare_package bzip2 " bzip2" " bzip2-1.0.6" " https://sourceware.org/bzip2/"
113
+ declare_package xz " XZ Utils" " 0BSD" " https://tukaani.org/xz"
114
+ declare_package libarchive " libarchive" " BSD-2-Clause" " https://www.libarchive.org"
115
+ declare_package mimalloc " mimalloc" " MIT" " https://microsoft.github.io/mimalloc/"
112
116
113
117
# Parse command line arguments
114
- static_linux_sdk_version=0.0.1
118
+ static_linux_sdk_version=0.1.0
115
119
sdk_name=
116
120
archs=x86_64,aarch64
117
121
build_type=RelWithDebInfo
@@ -208,6 +212,15 @@ boringssl_version=$(describe ${source_dir}/boringssl)
208
212
209
213
zlib_version=$( versionFromTag ${source_dir} /zlib)
210
214
215
+ bzip2_desc=$( describe ${source_dir} /bzip2)
216
+ bzip2_version=${bzip2_desc# bzip2-}
217
+
218
+ libarchive_version=$( versionFromTag ${source_dir} /libarchive)
219
+
220
+ mimalloc_version=$( versionFromTag ${source_dir} /mimalloc)
221
+
222
+ xz_version=$( versionFromTag ${source_dir} /xz)
223
+
211
224
function quiet_pushd {
212
225
pushd " $1 " > /dev/null 2>&1
213
226
}
@@ -233,6 +246,10 @@ echo " - libxml2 ${libxml2_version}"
233
246
echo " - curl ${curl_version} "
234
247
echo " - BoringSSL ${boringssl_version} "
235
248
echo " - zlib ${zlib_version} "
249
+ echo " - bzip2 ${bzip2_version} "
250
+ echo " - xz ${xz_version} "
251
+ echo " - libarchive ${libarchive_version} "
252
+ echo " - mimalloc ${mimalloc_version} "
236
253
237
254
function run() {
238
255
echo " $@ "
@@ -268,6 +285,19 @@ else
268
285
exit 1
269
286
fi
270
287
288
+ echo " Applying Musl security patches... "
289
+ for patch in $( realpath " ${resource_dir} /patches/musl" ) /* ; do
290
+ echo -n " $( basename $patch ) ..."
291
+ if git -C ${source_dir} /musl apply --reverse --check " $patch " > /dev/null 2>&1 ; then
292
+ echo " already patched"
293
+ elif git -C ${source_dir} /musl apply " $patch " > /dev/null 2>&1 ; then
294
+ echo " done"
295
+ else
296
+ echo " failed"
297
+ exit 1
298
+ fi
299
+ done
300
+
271
301
for arch in $archs ; do
272
302
273
303
# Fix architecture names
@@ -299,7 +329,7 @@ for arch in $archs; do
299
329
cat > $sdk_root /SDKSettings.json << EOF
300
330
{
301
331
"DisplayName": "Swift SDK for Statically Linked Linux ($arch )",
302
- "Version": "0.0.1 ",
332
+ "Version": "${static_linux_sdk_version} ",
303
333
"VersionMap": {},
304
334
"CanonicalName": "${arch} -swift-linux-musl"
305
335
}
499
529
500
530
# -----------------------------------------------------------------------
501
531
532
+ header " Building mimalloc for $arch "
533
+
534
+ run cmake -G Ninja -S ${source_dir} /mimalloc \
535
+ -B ${build_dir} /$arch /mimalloc \
536
+ -DCMAKE_TOOLCHAIN_FILE=${build_dir} /$arch /toolchain.cmake \
537
+ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
538
+ -DCMAKE_INSTALL_PREFIX=" $sdk_root /usr" \
539
+ -DMI_LIBC_MUSL=ON \
540
+ -DMI_BUILD_SHARED=OFF \
541
+ -DMI_BUILD_STATIC=ON \
542
+ -DMI_BUILD_TESTS=OFF \
543
+ -DMI_INSTALL_TOPLEVEL=ON
544
+
545
+ quiet_pushd ${build_dir} /$arch /mimalloc
546
+ run ninja -j$parallel_jobs
547
+ quiet_popd
548
+
549
+ header " Installing mimalloc for ${arch} "
550
+
551
+ quiet_pushd ${build_dir} /$arch /mimalloc
552
+ run ninja -j$parallel_jobs install
553
+ quiet_popd
554
+
555
+ # Make sure we link mimalloc
556
+ ldflags=" -lmimalloc $ldflags "
557
+ cxxldflags=" -lmimalloc $cxxldflags "
558
+ sed -i -e ' s/-lc++ /-lmimalloc -lc++ /g' \
559
+ ${build_dir} /${arch} /toolchain.cmake
560
+
561
+ # -----------------------------------------------------------------------
562
+
502
563
header " Building zlib for $arch "
503
564
504
565
mkdir -p $build_dir /$arch /zlib
@@ -524,17 +585,67 @@ EOF
524
585
525
586
# -----------------------------------------------------------------------
526
587
588
+ header " Building bzip2 for $arch "
589
+
590
+ rm -rf ${build_dir} /$arch /bzip2
591
+ cp -R ${source_dir} /bzip2 ${build_dir} /$arch /bzip2
592
+ quiet_pushd $build_dir /$arch /bzip2
593
+ run make \
594
+ CC=" $cc " \
595
+ CXX=" $cxx " \
596
+ LDFLAGS=" $ldflags " \
597
+ CXXLDFLAGS=" $cxxldflags " \
598
+ AS=" $as " \
599
+ AR=" ar" RANLIB=" ranlib" \
600
+ PREFIX=$sdk_root /usr
601
+ quiet_popd
602
+
603
+ header " Installing bzip2 for $arch "
604
+
605
+ quiet_pushd $build_dir /$arch /bzip2
606
+ run make install \
607
+ CC=" $cc " \
608
+ CXX=" $cxx " \
609
+ LDFLAGS=" $ldflags " \
610
+ CXXLDFLAGS=" $cxxldflags " \
611
+ AS=" $as " \
612
+ AR=" ar" RANLIB=" ranlib" \
613
+ PREFIX=$sdk_root /usr
614
+ quiet_popd
615
+
616
+ # -----------------------------------------------------------------------
617
+
618
+ header " Building xz for $arch "
619
+
620
+ run cmake -G Ninja -S ${source_dir} /xz -B ${build_dir} /$arch /xz \
621
+ -DCMAKE_TOOLCHAIN_FILE=${build_dir} /$arch /toolchain.cmake \
622
+ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
623
+ -DCMAKE_INSTALL_PREFIX=$sdk_root /usr \
624
+ -DBUILD_SHARED_LIBS=NO
625
+
626
+ quiet_pushd ${build_dir} /$arch /xz
627
+ run ninja -j$parallel_jobs
628
+ quiet_popd
629
+
630
+ header " Installing xz for $arch "
631
+
632
+ quiet_pushd ${build_dir} /$arch /xz
633
+ run ninja -j$parallel_jobs install
634
+ quiet_popd
635
+
636
+ # -----------------------------------------------------------------------
637
+
527
638
header " Building libxml2 for $arch "
528
639
529
640
run cmake -G Ninja -S ${source_dir} /libxml2 -B ${build_dir} /$arch /libxml2 \
530
641
-DCMAKE_TOOLCHAIN_FILE=${build_dir} /$arch /toolchain.cmake \
531
- -DCMAKE_EXTRA_LINK_FLAGS=" -rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi" \
642
+ -DCMAKE_EXTRA_LINK_FLAGS=" -rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lmimalloc - lc++ -lc++abi" \
532
643
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
533
644
-DCMAKE_INSTALL_PREFIX=$sdk_root /usr \
534
645
-DBUILD_SHARED_LIBS=NO \
535
646
-DLIBXML2_WITH_PYTHON=NO \
536
647
-DLIBXML2_WITH_ICU=NO \
537
- -DLIBXML2_WITH_LZMA=NO
648
+ -DLIBXML2_WITH_LZMA=YES
538
649
539
650
quiet_pushd ${build_dir} /$arch /libxml2
540
651
run ninja -j$parallel_jobs
548
659
549
660
# -----------------------------------------------------------------------
550
661
662
+ header " Building libarchive for $arch "
663
+
664
+ run cmake -G Ninja -S ${source_dir} /libarchive \
665
+ -B ${build_dir} /$arch /libarchive \
666
+ -DCMAKE_TOOLCHAIN_FILE=${build_dir} /$arch /toolchain.cmake \
667
+ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
668
+ -DCMAKE_INSTALL_PREFIX=$sdk_root /usr \
669
+ -DCMAKE_INSTALL_LIBDIR=$sdk_root /usr/lib \
670
+ -DBUILD_SHARED_LIBS=NO \
671
+ -DENABLE_OPENSSL=NO
672
+
673
+ quiet_pushd ${build_dir} /$arch /libarchive
674
+ run ninja -j$parallel_jobs
675
+ quiet_popd
676
+
677
+ header " Installing libarchive for $arch "
678
+
679
+ quiet_pushd ${build_dir} /$arch /libarchive
680
+ run ninja -j$parallel_jobs install
681
+ quiet_popd
682
+
683
+ # -----------------------------------------------------------------------
684
+
551
685
header " Building BoringSSL for $arch "
552
686
553
687
run cmake -G Ninja -S ${source_dir} /boringssl -B ${build_dir} /$arch /boringssl \
576
710
-DCMAKE_INSTALL_PREFIX=$sdk_root /usr \
577
711
-DBUILD_SHARED_LIBS=NO \
578
712
-DBUILD_STATIC_LIBS=YES \
579
- -DBUILD_CURL_EXE=NO
713
+ -DBUILD_CURL_EXE=NO \
714
+ -DCURL_USE_PKGCONFIG=OFF \
715
+ -DCURL_USE_LIBPSL=OFF
580
716
581
717
quiet_pushd ${build_dir} /$arch /curl
582
718
ninja -j$parallel_jobs
619
755
-stdlib=libc++
620
756
-fuse-ld=lld
621
757
-unwindlib=libunwind
758
+ -lmimalloc
622
759
-lc++abi
623
760
-static
624
761
EOF
@@ -750,7 +887,7 @@ header "Bundling SDK"
750
887
751
888
spdx_uuid=$( uuidgen)
752
889
spdx_doc_uuid=$( uuidgen)
753
- spdx_timestamp=$( date -Iseconds)
890
+ spdx_timestamp=$( date -Iseconds -z Z | sed ' s/\+00:00$/Z/g ' )
754
891
755
892
sdk_name=swift-${swift_version} _static-linux-${static_linux_sdk_version}
756
893
bundle=" ${sdk_name} .artifactbundle"
@@ -771,7 +908,7 @@ cat > info.json <<EOF
771
908
"path": "$sdk_name /swift-linux-musl"
772
909
}
773
910
],
774
- "version": "0.0.1 ",
911
+ "version": "${static_linux_sdk_version} ",
775
912
"type": "swiftSDK"
776
913
}
777
914
}
0 commit comments