forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-script-impl
executable file
·2261 lines (2062 loc) · 90.9 KB
/
build-script-impl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#===--- build-script-impl - Implementation details of build-script ---------===#
#
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See http://swift.org/LICENSE.txt for license information
## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===------------------------------------------------------------------------===#
#
# This script is an implementation detail of other build scripts and should not
# be called directly.
#
# Note: This script will NOT auto-clean before building.
#
set -o pipefail
set -e
umask 0022
#
# Options that can be "configured" by editing this file.
#
# These options are not exposed as command line options on purpose. If you
# need to change any of these, you should do so on trunk or in a branch.
#
LLVM_TARGETS_TO_BUILD="X86;ARM;AArch64"
#
# End of configurable options.
#
# Declare the set of known settings along with each one's description
#
# If you add a user-settable variable, add it to this list.
#
# A default value of "" indicates that the corresponding variable
# will remain unset unless set explicitly.
#
# skip-* parameters do not affect the configuration (CMake parameters).
# You can turn them on and off in different invocations of the script for the
# same build directory.
#
# build-* parameters affect the CMake configuration (enable/disable those
# components).
#
# Each variable name is re-exported into this script in uppercase, where dashes
# are substituded by underscores. For example, `swift-install-components` is
# referred to as `SWIFT_INSTALL_COMPONENTS` in the remainder of this script.
KNOWN_SETTINGS=(
# name default description
build-args "" "arguments to the build tool; defaults to -j8 when CMake generator is \"Unix Makefiles\""
build-dir "" "out-of-tree build directory; default is in-tree. **This argument is required**"
darwin-xcrun-toolchain "default" "the name of the toolchain to use on Darwin"
build-ninja "" "build the Ninja tool"
cmark-build-type "Debug" "the CMake build variant for CommonMark (Debug, RelWithDebInfo, Release, MinSizeRel). Defaults to Debug."
lldb-extra-cmake-args "" "extra command line args to pass to lldb cmake"
lldb-test-with-curses "" "run test lldb test runner using curses terminal control"
lldb-no-debugserver "" "delete debugserver after building it, and don't try to codesign it"
lldb-use-system-debugserver "" "don't try to codesign debugserver, and use the system's debugserver instead"
llvm-build-type "Debug" "the CMake build variant for LLVM and Clang (Debug, RelWithDebInfo, Release, MinSizeRel). Defaults to Debug."
llvm-enable-assertions "1" "enable assertions in LLVM and Clang"
swift-build-type "Debug" "the CMake build variant for Swift"
swift-enable-assertions "1" "enable assertions in Swift"
swift-stdlib-build-type "Debug" "the CMake build variant for Swift"
swift-stdlib-enable-assertions "1" "enable assertions in Swift"
lldb-build-type "Debug" "the CMake build variant for LLDB"
llbuild-build-type "Debug" "the CMake build variant for llbuild"
foundation-build-type "Debug" "the build variant for Foundation"
llbuild-enable-assertions "1" "enable assertions in llbuild"
enable-asan "" "enable AddressSanitizer"
cmake "" "path to the cmake binary"
distcc "" "use distcc in pump mode"
user-config-args "" "User-supplied arguments to cmake when used to do configuration"
cmake-generator "Unix Makefiles" "kind of build system to generate; see output of 'cmake --help' for choices"
verbose-build "" "print the commands executed during the build"
install-prefix "" "installation prefix"
install-destdir "" "the path to use as the filesystem root for the installation"
install-symroot "" "the path to install debug symbols into"
swift-install-components "" "a semicolon-separated list of Swift components to install"
llvm-install-components "" "a semicolon-separated list of LLVM components to install"
installable-package "" "the path to the archive of the installation directory"
test-installable-package "" "whether to run post-packaging tests on the produced package"
symbols-package "" "the path to the archive of the symbols directory"
show-sdks "" "print installed Xcode and SDK versions"
reconfigure "" "force a CMake configuration run even if CMakeCache.txt already exists"
swift-sdks "" "build target binaries only for specified SDKs (semicolon-separated list)"
swift-primary-variant-sdk "" "default SDK for target binaries"
swift-primary-variant-arch "" "default arch for target binaries"
skip-ios "" "set to skip everything iOS-related"
skip-tvos "" "set to skip everything tvOS-related"
skip-watchos "" "set to skip everything watchOS-related"
skip-build "" "set to skip building anything"
skip-build-cmark "" "set to skip building CommonMark"
skip-build-llvm "" "set to skip building LLVM/Clang"
skip-build-swift "" "set to skip building Swift"
skip-build-osx "" "set to skip building Swift stdlibs for OSX"
skip-build-ios "" "set to skip building Swift stdlibs for iOS"
skip-build-ios-device "" "set to skip building Swift stdlibs for iOS devices (i.e. build simulators only)"
skip-build-ios-simulator "" "set to skip building Swift stdlibs for iOS simulators (i.e. build devices only)"
skip-build-tvos "" "set to skip building Swift stdlibs for tvOS"
skip-build-tvos-device "" "set to skip building Swift stdlibs for tvOS devices (i.e. build simulators only)"
skip-build-tvos-simulator "" "set to skip building Swift stdlibs for tvOS simulators (i.e. build devices only)"
skip-build-watchos "" "set to skip building Swift stdlibs for Apple watchOS"
skip-build-watchos-device "" "set to skip building Swift stdlibs for Apple watchOS devices (i.e. build simulators only)"
skip-build-watchos-simulator "" "set to skip building Swift stdlibs for Apple watchOS simulators (i.e. build devices only)"
skip-build-lldb "" "set to skip building LLDB"
skip-build-llbuild "" "set to skip buildling llbuild"
skip-build-swiftpm "" "set to skip buildling swiftpm"
skip-build-xctest "" "set to skip buildling xctest"
skip-build-foundation "" "set to skip buildling foundation"
skip-test-cmark "" "set to skip testing CommonMark"
skip-test-lldb "" "set to skip testing lldb"
skip-test-swift "" "set to skip testing Swift"
skip-test-llbuild "" "set to skip testing llbuild"
skip-test-swiftpm "" "set to skip testing swiftpm"
skip-test-xctest "" "set to skip testing xctest"
skip-test-foundation "" "set to skip testing foundation"
skip-test-osx "" "set to skip testing Swift stdlibs for OSX"
skip-test-ios "" "set to skip testing Swift stdlibs for iOS"
skip-test-ios-simulator "" "set to skip testing Swift stdlibs for iOS simulators (i.e. test devices only)"
skip-test-tvos "" "set to skip testing Swift stdlibs for tvOS"
skip-test-tvos-simulator "" "set to skip testing Swift stdlibs for tvOS simulators (i.e. test devices only)"
skip-test-watchos "" "set to skip testing Swift stdlibs for Apple watchOS"
skip-test-watchos-simulator "" "set to skip testing Swift stdlibs for Apple watchOS simulators (i.e. test devices only)"
skip-test-validation "" "set to skip validation test suite"
skip-test-optimized "" "set to skip testing the test suite in optimized mode"
stress-test-sourcekit "" "set to run the stress-SourceKit target"
xcode-ide-only "" "set to configure Xcode project for IDE use only, not building"
workspace "${HOME}/src" "source directory containing llvm, clang, swift"
enable-llvm-assertions "1" "set to enable llvm assertions"
build-llvm "1" "set to 1 to build LLVM and Clang"
build-swift-tools "1" "set to 1 to build Swift host tools"
build-swift-stdlib "1" "set to 1 to build the Swift standard library"
build-swift-sdk-overlay "1" "set to 1 to build the Swift SDK overlay"
build-swift-static-stdlib "0" "set to 1 to build static versions of the Swift standard library and SDK overlay"
build-swift-examples "1" "set to 1 to build examples"
build-swift-perf-testsuite "0" "set to 1 to build perf test suite"
source-tree-includes-tests "1" "set to 0 to allow the build to proceed when 'test' directory is missing (required for B&I builds)"
native-llvm-tools-path "" "directory that contains LLVM tools that are executable on the build machine"
native-clang-tools-path "" "directory that contains Clang tools that are executable on the build machine"
native-swift-tools-path "" "directory that contains Swift tools that are executable on the build machine"
compiler-vendor "none" "compiler vendor name [none,apple]"
swift-compiler-version "" "string that indicates a compiler version for Swift"
clang-compiler-version "" "string that indicates a compiler version for Clang"
embed-bitcode-section "0" "embed an LLVM bitcode section in stdlib/overlay binaries for supported platforms"
darwin-crash-reporter-client "" "whether to enable CrashReporter integration"
darwin-stdlib-install-name-dir "" "the directory of the install_name for standard library dylibs"
install-cmark "" "whether to install cmark"
install-swift "" "whether to install Swift"
install-lldb "" "whether to install LLDB"
install-llbuild "" "whether to install llbuild"
install-swiftpm "" "whether to install swiftpm"
install-xctest "" "whether to install xctest"
install-foundation "" "whether to install foundation"
darwin-install-extract-symbols "" "whether to extract symbols with dsymutil during installations"
cross-compile-tools-deployment-targets "" "space-separated list of targets to cross-compile host Swift tools for"
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
darwin-deployment-version-osx "10.9" "minimum deployment target version for OS X"
darwin-deployment-version-ios "7.0" "minimum deployment target version for iOS"
darwin-deployment-version-tvos "9.0" "minimum deployment target version for tvOS"
darwin-deployment-version-watchos "2.0" "minimum deployment target version for watchOS"
extra-swift-args "" "Extra arguments to pass to swift modules which match regex. Assumed to be a flattened cmake list consisting of [module_regexp, args, module_regexp, args, ...]"
sil-verify-all "0" "If enabled, run the sil verifier be run after every SIL pass"
swift-enable-ast-verifier "1" "If enabled, and the assertions are enabled, the built Swift compiler will run the AST verifier every time it is invoked"
swift-enable-target-linux "1" "Enable compiler support for targeting Linux"
swift-enable-target-freebsd "1" "Enable compiler support for targeting FreeBSD"
swift-runtime-enable-dtrace "0" "Enable runtime dtrace support"
swift-runtime-enable-leak-checker "0" "Enable leaks checking routines in the runtime"
use-gold-linker "" "Enable using the gold linker"
darwin-toolchain-bundle-identifier "" "CFBundleIdentifier for xctoolchain info plist"
darwin-toolchain-display-name "" "Display Name for xctoolcain info plist"
darwin-toolchain-name "" "Directory name for xctoolchain"
darwin-toolchain-version "" "Version for xctoolchain info plist and installer pkg"
darwin-toolchain-application-cert "" "Application Cert name to codesign xctoolchain"
darwin-toolchain-installer-cert "" "Installer Cert name to create installer pkg"
darwin-toolchain-installer-package "" "The path to installer pkg"
)
function toupper() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}
function to_varname() {
toupper "${1//-/_}"
}
function get_make_parallelism() {
case "$(uname -s)" in
Linux)
nproc
;;
Darwin)
sysctl -n hw.activecpu
;;
*)
echo 8
;;
esac
}
function get_dsymutil_parallelism() {
get_make_parallelism
}
function set_lldb_build_mode() {
LLDB_BUILD_MODE="CustomSwift-${LLDB_BUILD_TYPE}"
}
function set_deployment_target_based_options() {
llvm_cmake_options=()
swift_cmake_options=()
cmark_cmake_options=()
swiftpm_bootstrap_options=()
case $deployment_target in
linux-x86_64)
SWIFT_HOST_VARIANT_ARCH="x86_64"
;;
freebsd-x86_64)
SWIFT_HOST_VARIANT_ARCH="x86_64"
;;
macosx-* | iphoneos-* | iphonesimulator-* | \
appletvos-* | appletvsimulator-* | \
watchos-* | watchsimulator-*)
case ${deployment_target} in
macosx-x86_64)
xcrun_sdk_name="macosx"
llvm_host_triple="x86_64-apple-macosx${DARWIN_DEPLOYMENT_VERSION_OSX}"
llvm_target_arch=""
cmake_osx_deployment_target="${DARWIN_DEPLOYMENT_VERSION_OSX}"
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
-DCMAKE_OSX_DEPLOYMENT_TARGET="${cmake_osx_deployment_target}"
)
swiftpm_bootstrap_options=(
--sysroot="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
;;
iphonesimulator-i386)
xcrun_sdk_name="iphonesimulator"
llvm_host_triple="i386-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="X86"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="iphonesimulator"
-DSWIFT_HOST_VARIANT_SDK="IOS_SIMULATOR"
-DSWIFT_HOST_VARIANT_ARCH="i386"
)
;;
iphonesimulator-x86_64)
xcrun_sdk_name="iphonesimulator"
llvm_host_triple="x86_64-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="X86"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="iphonesimulator"
-DSWIFT_HOST_VARIANT_SDK="IOS_SIMULATOR"
-DSWIFT_HOST_VARIANT_ARCH="x86_64"
)
;;
iphoneos-armv7)
xcrun_sdk_name="iphoneos"
llvm_host_triple="armv7-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="ARM"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="iphoneos"
-DSWIFT_HOST_VARIANT_SDK="IOS"
-DSWIFT_HOST_VARIANT_ARCH="armv7"
)
;;
iphoneos-arm64)
xcrun_sdk_name="iphoneos"
llvm_host_triple="arm64-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="AArch64"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="iphoneos"
-DSWIFT_HOST_VARIANT_SDK="IOS"
-DSWIFT_HOST_VARIANT_ARCH="arm64"
)
;;
appletvsimulator-x86_64)
xcrun_sdk_name="appletvsimulator"
llvm_host_triple="x86_64-apple-tvos${DARWIN_DEPLOYMENT_VERSION_TVOS}"
llvm_target_arch="X86"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="appletvsimulator"
-DSWIFT_HOST_VARIANT_SDK="TVOS_SIMULATOR"
-DSWIFT_HOST_VARIANT_ARCH="x86_64"
)
;;
appletvos-arm64)
xcrun_sdk_name="appletvos"
llvm_host_triple="arm64-apple-tvos${DARWIN_DEPLOYMENT_VERSION_TVOS}"
llvm_target_arch="AArch64"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="appletvos"
-DSWIFT_HOST_VARIANT_SDK="TVOS"
-DSWIFT_HOST_VARIANT_ARCH="arm64"
)
;;
watchsimulator-i386)
xcrun_sdk_name="watchsimulator"
llvm_host_triple="i386-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
llvm_target_arch="X86"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="watchsimulator"
-DSWIFT_HOST_VARIANT_SDK="WATCHOS_SIMULATOR"
-DSWIFT_HOST_VARIANT_ARCH="i386"
)
;;
watchos-armv7k)
xcrun_sdk_name="watchos"
llvm_host_triple="armv7k-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
llvm_target_arch="ARM"
cmake_osx_deployment_target=""
cmark_cmake_options=(
-DCMAKE_C_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_CXX_FLAGS="$(cmark_c_flags $deployment_target)"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
)
swift_cmake_options=(
-DSWIFT_HOST_VARIANT="watchos"
-DSWIFT_HOST_VARIANT_SDK="WATCHOS"
-DSWIFT_HOST_VARIANT_ARCH="armv7k"
)
;;
*)
echo "Unknown deployment target"
exit 1
;;
esac
native_llvm_build=$(build_directory macosx-x86_64 llvm)
llvm_cmake_options=(
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="${cmake_osx_deployment_target}"
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk $xcrun_sdk_name --show-sdk-path)"
-DLLVM_HOST_TRIPLE:STRING="${llvm_host_triple}"
)
swift_cmake_options=(
"${swift_cmake_options[@]}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_OSX="${DARWIN_DEPLOYMENT_VERSION_OSX}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_IOS="${DARWIN_DEPLOYMENT_VERSION_IOS}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS="${DARWIN_DEPLOYMENT_VERSION_TVOS}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS="${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
)
if [[ "${llvm_target_arch}" ]] ; then
llvm_cmake_options=(
"${llvm_cmake_options[@]}"
-DLLVM_TARGET_ARCH="${llvm_target_arch}"
)
fi
;;
*)
echo "Unknown compiler deployment target: $deployment_target"
exit 1
;;
esac
}
# Set up an "associative array" of settings for error checking, and set
# (or unset) each corresponding variable to its default value
# If the Mac's bash were not stuck in the past, we could "declare -A" an
# associative array, but instead we have to hack it by defining variables
# declare -A IS_KNOWN_SETTING
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
setting="${KNOWN_SETTINGS[i]}"
default_value="${KNOWN_SETTINGS[$((i+1))]}"
varname="$(to_varname "${setting}")" # upcase the setting name to get the variable
eval "${varname}_IS_KNOWN_SETTING=1"
if [[ "${default_value}" ]] ; then
# For an explanation of the backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\default_value
else
unset ${varname}
fi
done
COMMAND_NAME="$(basename "$0")"
# Print instructions for using this script to stdout
usage() {
echo "Usage: ${COMMAND_NAME} [--help|-h] [ --SETTING=VALUE | --SETTING VALUE | --SETTING ]*"
echo
echo " Available settings. Each setting corresponds to a variable,"
echo " obtained by upcasing its name, in this script. A variable"
echo " with no default listed here will be unset in the script if"
echo " not explicitly specified. A setting passed in the 3rd form"
echo " will set its corresponding variable to \"1\"."
echo
setting_list="
| |Setting| Default|Description
| |-------| -------|-----------
"
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
setting_list+="\
| |--${KNOWN_SETTINGS[i]}| ${KNOWN_SETTINGS[$((i+1))]}|${KNOWN_SETTINGS[$((i+2))]}
"
done
echo "${setting_list}" | column -x -s'|' -t
echo
echo "Note: when using the form --SETTING VALUE, VALUE must not begin "
echo " with a hyphen."
echo "Note: the \"--release\" option creates a pre-packaged combination"
echo " of settings used by the buildbot."
echo
echo "Cross-compiling Swift host tools"
echo " When building cross-compiled tools, it first builds for the native"
echo " build host machine. Then it proceeds to build the specified cross-compile"
echo " targets. It currently builds the requested variants of stdlib each"
echo " time around, so once for the native build, then again each time for"
echo " the cross-compile tool targets."
echo
echo " When installing cross-compiled tools, it first installs each target"
echo " arch into a separate subdirectory under install-destdir, since you"
echo " can cross-compile for multiple targets at the same time. It then runs"
echo " recursive-lipo to produce fat binaries by merging the cross-compiled"
echo " targets, installing the merged result into the expected location of"
echo " install-destdir. After that, any remaining steps to extract dsyms and"
echo " create an installable package operates on install-destdir as normal."
}
# Scan all command-line arguments
while [[ "$1" ]] ; do
case "$1" in
-h | --help )
usage
exit
;;
--* )
dashless="${1:2}"
# drop suffix beginning with the first "="
setting="${dashless%%=*}"
# compute the variable to set
varname="$(to_varname "${setting}")"
# check to see if this is a known option
known_var_name="${varname}_IS_KNOWN_SETTING"
if [[ ! "${!known_var_name}" ]] ; then
echo "Error: Unknown setting: ${setting}" 1>&2
usage 1>&2
exit 1
fi
# find the intended value
if [[ "${dashless}" == *=* ]] ; then # if there's an '=', the value
value="${dashless#*=}" # is everything after the first '='
elif [[ "$2" ]] && [[ "${2:0:1}" != "-" ]] ; then # else if the next parameter exists
value="$2" # but isn't an option, use that
shift
else # otherwise, the value is 1
value=1
fi
# For explanation of backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\value
;;
*)
usage
exit 1
esac
shift
done
if [[ "$SKIP_BUILD" ]]; then
SKIP_BUILD_CMARK=1
SKIP_BUILD_LLVM=1
SKIP_BUILD_SWIFT=1
SKIP_BUILD_OSX=1
SKIP_BUILD_IOS=1
SKIP_BUILD_IOS_DEVICE=1
SKIP_BUILD_IOS_SIMULATOR=1
SKIP_BUILD_TVOS=1
SKIP_BUILD_TVOS_DEVICE=1
SKIP_BUILD_TVOS_SIMULATOR=1
SKIP_BUILD_WATCHOS=1
SKIP_BUILD_WATCHOS_DEVICE=1
SKIP_BUILD_WATCHOS_SIMULATOR=1
SKIP_BUILD_LLDB=1
SKIP_BUILD_LLBUILD=1
SKIP_BUILD_SWIFTPM=1
SKIP_BUILD_XCTEST=1
SKIP_BUILD_FOUNDATION=1
fi
if [[ "$SKIP_IOS" ]] ; then
SKIP_BUILD_IOS=1
SKIP_BUILD_IOS_DEVICE=1
SKIP_BUILD_IOS_SIMULATOR=1
SKIP_TEST_IOS=1
SKIP_TEST_IOS_SIMULATOR=1
fi
if [[ "$SKIP_TVOS" ]] ; then
SKIP_BUILD_TVOS=1
SKIP_BUILD_TVOS_DEVICE=1
SKIP_BUILD_TVOS_SIMULATOR=1
SKIP_TEST_TVOS=1
SKIP_TEST_TVOS_SIMULATOR=1
fi
if [[ "$SKIP_WATCHOS" ]] ; then
SKIP_BUILD_WATCHOS=1
SKIP_BUILD_WATCHOS_DEVICE=1
SKIP_BUILD_WATCHOS_SIMULATOR=1
SKIP_TEST_WATCHOS=1
SKIP_TEST_WATCHOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_IOS" ]] ; then
SKIP_BUILD_IOS=1
SKIP_BUILD_IOS_DEVICE=1
SKIP_BUILD_IOS_SIMULATOR=1
SKIP_TEST_IOS=1
SKIP_TEST_IOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_TVOS" ]] ; then
SKIP_BUILD_TVOS=1
SKIP_BUILD_TVOS_DEVICE=1
SKIP_BUILD_TVOS_SIMULATOR=1
SKIP_TEST_TVOS=1
SKIP_TEST_TVOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_WATCHOS" ]] ; then
SKIP_BUILD_WATCHOS=1
SKIP_BUILD_WATCHOS_DEVICE=1
SKIP_BUILD_WATCHOS_SIMULATOR=1
SKIP_TEST_WATCHOS=1
SKIP_TEST_WATCHOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_IOS_DEVICE" ]] ; then
SKIP_BUILD_IOS_DEVICE=1
fi
if [[ "$SKIP_BUILD_TVOS_DEVICE" ]] ; then
SKIP_BUILD_TVOS_DEVICE=1
fi
if [[ "$SKIP_BUILD_WATCHOS_DEVICE" ]] ; then
SKIP_BUILD_WATCHOS_DEVICE=1
fi
if [[ "$SKIP_BUILD_IOS_SIMULATOR" ]] ; then
SKIP_BUILD_IOS_SIMULATOR=1
SKIP_TEST_IOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_TVOS_SIMULATOR" ]] ; then
SKIP_BUILD_TVOS_SIMULATOR=1
SKIP_TEST_TVOS_SIMULATOR=1
fi
if [[ "$SKIP_BUILD_WATCHOS_SIMULATOR" ]] ; then
SKIP_BUILD_WATCHOS_SIMULATOR=1
SKIP_TEST_WATCHOS_SIMULATOR=1
fi
if [[ "$SKIP_TEST_IOS" ]] ; then
SKIP_TEST_IOS_SIMULATOR=1
fi
if [[ "$SKIP_TEST_TVOS" ]] ; then
SKIP_TEST_TVOS_SIMULATOR=1
fi
if [[ "$SKIP_TEST_WATCHOS" ]] ; then
SKIP_TEST_WATCHOS_SIMULATOR=1
fi
if [[ "${CMAKE_GENERATOR}" == "Ninja" ]] && [[ -z "$(which ninja)" ]] ; then
BUILD_NINJA=1
fi
# WORKSPACE, BUILD_DIR and INSTALLABLE_PACKAGE must be absolute paths
case "${WORKSPACE}" in
/*) ;;
*)
echo "workspace must be an absolute path (was '${WORKSPACE}')"
exit 1
;;
esac
case "${BUILD_DIR}" in
/*) ;;
"")
echo "the --build-dir option is required"
usage
exit 1
;;
*)
echo "build-dir must be an absolute path (was '${BUILD_DIR}')"
exit 1
;;
esac
case "${INSTALLABLE_PACKAGE}" in
/*) ;;
"") ;;
*)
echo "installable-package must be an absolute path (was '${INSTALLABLE_PACKAGE}')"
exit 1
;;
esac
case "${SYMBOLS_PACKAGE}" in
/*) ;;
"") ;;
*)
echo "symbols-package must be an absolute path (was '${SYMBOLS_PACKAGE}')"
exit 1
;;
esac
# WORKSPACE must exist
if [ ! -e "$WORKSPACE" ] ; then
echo "Workspace does not exist (tried $WORKSPACE)"
exit 1
fi
function xcrun_find_tool() {
xcrun --sdk macosx --toolchain "${DARWIN_XCRUN_TOOLCHAIN}" --find "$@"
}
function not() {
if [[ ! "$1" ]] ; then
echo 1
fi
}
function true_false() {
case "$1" in
false | 0)
echo "FALSE"
;;
true | 1)
echo "TRUE"
;;
*)
echo "true_false: unknown value: $1" >&2
exit 1
;;
esac
}
#
# Set default values for command-line parameters.
#
if [[ "${CMAKE}" == "" ]] ; then
if [[ "$(uname -s)" == "Darwin" ]] ; then
CMAKE="$(xcrun_find_tool cmake)"
else
CMAKE="$(which cmake || echo /usr/local/bin/cmake)"
fi
fi
if [[ "${INSTALL_PREFIX}" == "" ]] ; then
if [[ "$(uname -s)" == "Darwin" ]] ; then
INSTALL_PREFIX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr"
else
INSTALL_PREFIX="/usr"
fi
fi
if [[ "$(uname -s)" == "Darwin" ]] ; then
TOOLCHAIN_PREFIX=$(echo ${INSTALL_PREFIX} | sed -E 's/\/usr$//')
fi
# A list of deployment targets to compile the Swift host tools for, in case when
# we can run the resulting binaries natively on the build machine.
NATIVE_TOOLS_DEPLOYMENT_TARGETS=()
# A list of deployment targets to cross-compile the Swift host tools for.
# We can't run the resulting binaries on the build machine.
CROSS_TOOLS_DEPLOYMENT_TARGETS=()
# Determine the native deployment target for the build machine, that will be
# used to jumpstart the standard library build when cross-compiling.
case "$(uname -s)" in
Linux)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"linux-x86_64"
)
;;
Darwin)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"macosx-x86_64"
)
;;
FreeBSD)
NATIVE_TOOLS_DEPLOYMENT_TARGETS=(
"freebsd-x86_64"
)
;;
*)
echo "Unknown operating system"
exit 1
;;
esac
# Sanitize the list of cross-compilation targets.
for t in ${CROSS_COMPILE_TOOLS_DEPLOYMENT_TARGETS} ; do
case ${t} in
iphonesimulator-i386 | iphonesimulator-x86_64 | \
iphoneos-arm64 | iphoneos-armv7 | \
appletvos-arm64 | appletvsimulator-x86_64 | \
watchos-armv7k | watchsimulator-i386)
CROSS_TOOLS_DEPLOYMENT_TARGETS=(
"${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"
"${t}"
)
;;
*)
echo "Unknown deployment target"
exit 1
;;
esac
done
function is_native_tools_deployment_target() {
local deployment_target="$1"
for t in "${NATIVE_TOOLS_DEPLOYMENT_TARGETS[@]}" ; do
if [ "${deployment_target}" == "${t}" ] ; then
echo 1
fi
done
}
function is_cross_tools_deployment_target() {
local deployment_target="$1"
for t in "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}" ; do
if [ "${deployment_target}" == "${t}" ] ; then
echo 1
fi
done
}
# A list of deployment targets that we compile or cross-compile the
# Swift standard library for.
STDLIB_DEPLOYMENT_TARGETS=()
case "$(uname -s)" in
Linux)
STDLIB_DEPLOYMENT_TARGETS=(
"linux-x86_64"
)
;;
Darwin)
STDLIB_DEPLOYMENT_TARGETS=(
"macosx-x86_64"
"iphonesimulator-i386"
"iphonesimulator-x86_64"
"appletvsimulator-x86_64"
"watchsimulator-i386"
# Put iOS native targets last so that we test them last (it takes a
# long time).
"iphoneos-arm64"
"iphoneos-armv7"
"appletvos-arm64"
"watchos-armv7k"
)
;;
FreeBSD)
STDLIB_DEPLOYMENT_TARGETS=(
"freebsd-x86_64"
)
;;
*)
echo "Unknown operating system"
exit 1
;;
esac
#
# Calculate source directories for each product.
#
NINJA_SOURCE_DIR="$WORKSPACE/ninja"
SWIFT_SOURCE_DIR="$WORKSPACE/swift"
LLVM_SOURCE_DIR="$WORKSPACE/llvm"
CMARK_SOURCE_DIR="$WORKSPACE/cmark"
LLDB_SOURCE_DIR="$WORKSPACE/lldb"
LLBUILD_SOURCE_DIR="$WORKSPACE/llbuild"
SWIFTPM_SOURCE_DIR="$WORKSPACE/swiftpm"
XCTEST_SOURCE_DIR="$WORKSPACE/swift-corelibs-xctest"
FOUNDATION_SOURCE_DIR="$WORKSPACE/swift-corelibs-foundation"
if [[ ! -d $CMARK_SOURCE_DIR ]]; then
echo "$CMARK_SOURCE_DIR not found. Attempting to clone ..."
git clone https://github.com/apple/swift-cmark.git "$CMARK_SOURCE_DIR" || \
(echo "Couldn't clone cmark. Please check README.md and visit https://github.com/apple/swift-cmark for details." && \
exit 1)
fi
if [[ ! "$SKIP_BUILD_LLBUILD" && ! -d $LLBUILD_SOURCE_DIR ]]; then
echo "Couldn't find llbuild source directory."
exit 1
fi
if [[ ! "$SKIP_BUILD_SWIFTPM" && ! -d $SWIFTPM_SOURCE_DIR ]]; then
echo "Couldn't find swiftpm source directory."
exit 1
fi
if [[ ! "$SKIP_BUILD_XCTEST" && ! -d $XCTEST_SOURCE_DIR ]]; then
echo "Couldn't find XCTest source directory."
exit 1
fi
if [[ ! "$SKIP_BUILD_FOUNDATION" && ! -d $FOUNDATION_SOURCE_DIR ]]; then
echo "Couldn't find Foundation source directory."
exit 1
fi
# Symlink clang into the llvm tree.
CLANG_SOURCE_DIR="${LLVM_SOURCE_DIR}/tools/clang"
if [ ! -e "${WORKSPACE}/clang" ] ; then
# If llvm/tools/clang is already a directory, use that and skip the symlink.
if [ ! -d "${CLANG_SOURCE_DIR}" ] ; then
echo "Can't find source directory for clang (tried ${WORKSPACE}/clang and ${CLANG_SOURCE_DIR})"
exit 1
fi
fi
if [ ! -d "${CLANG_SOURCE_DIR}" ] ; then
ln -sf "${WORKSPACE}/clang" "${CLANG_SOURCE_DIR}"
fi
PRODUCTS=(cmark llvm swift)
if [[ ! "${SKIP_BUILD_LLDB}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" lldb)
fi
if [[ ! "${SKIP_BUILD_LLBUILD}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" llbuild)
fi
if [[ ! "${SKIP_BUILD_SWIFTPM}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" swiftpm)
fi
if [[ ! "${SKIP_BUILD_XCTEST}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" xctest)
fi
if [[ ! "${SKIP_BUILD_FOUNDATION}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" foundation)
fi
SWIFT_STDLIB_TARGETS=()
SWIFT_TEST_TARGETS=()
for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
build_for_this_target=1
test_this_target=1
case $deployment_target in
linux-*)
build_for_this_target=1
test_this_target=1
;;
freebsd-*)
build_for_this_target=1
test_this_target=1
;;
macosx-*)
build_for_this_target=$(not $SKIP_BUILD_OSX)
test_this_target=$(not $SKIP_TEST_OSX)
;;
iphoneos-*)
build_for_this_target=$(not $SKIP_BUILD_IOS_DEVICE)
test_this_target=
;;
iphonesimulator-*)
build_for_this_target=$(not $SKIP_BUILD_IOS_SIMULATOR)
test_this_target=$(not $SKIP_TEST_IOS_SIMULATOR)
;;
appletvos-*)
build_for_this_target=$(not $SKIP_BUILD_TVOS_DEVICE)
test_this_target=
;;
appletvsimulator-*)
build_for_this_target=$(not $SKIP_BUILD_TVOS_SIMULATOR)
test_this_target=$(not $SKIP_TEST_TVOS_SIMULATOR)
;;
watchos-*)
build_for_this_target=$(not $SKIP_BUILD_WATCHOS_DEVICE)
test_this_target=
;;
watchsimulator-*)
build_for_this_target=$(not $SKIP_BUILD_WATCHOS_SIMULATOR)
test_this_target=$(not $SKIP_TEST_WATCHOS_SIMULATOR)
;;
*)
echo "Unknown compiler deployment target: $deployment_target"
exit 1
;;
esac
if [[ "$build_for_this_target" ]] ; then
SWIFT_STDLIB_TARGETS=(
"${SWIFT_STDLIB_TARGETS[@]}" "swift-stdlib-${deployment_target}")
fi
if [[ "$test_this_target" ]] ; then
if [[ "$SKIP_TEST_VALIDATION" ]] ; then
SWIFT_TEST_TARGETS=(
"${SWIFT_TEST_TARGETS[@]}" "check-swift-${deployment_target}")
if [[ $(not $SKIP_TEST_OPTIMIZED) ]] ; then
SWIFT_TEST_TARGETS=(
"${SWIFT_TEST_TARGETS[@]}" "check-swift-optimize-${deployment_target}")
fi
else
SWIFT_TEST_TARGETS=(
"${SWIFT_TEST_TARGETS[@]}" "check-swift-all-${deployment_target}")
if [[ $(not $SKIP_TEST_OPTIMIZED) ]] ; then
SWIFT_TEST_TARGETS=(
"${SWIFT_TEST_TARGETS[@]}" "check-swift-all-optimize-${deployment_target}")
fi
fi
fi
done
echo "Building the standard library for: ${SWIFT_STDLIB_TARGETS[@]}"
echo "Running Swift tests for: ${SWIFT_TEST_TARGETS[@]}"
echo
# CMake options used for all targets, including LLVM/Clang
COMMON_CMAKE_OPTIONS=(
-G "${CMAKE_GENERATOR}"
)
COMMON_C_FLAGS=""
COMMON_CXX_FLAGS=""
if [[ "${ENABLE_ASAN}" ]] ; then
COMMON_CMAKE_OPTIONS=(
"${COMMON_CMAKE_OPTIONS[@]}"