Skip to content

Commit 53f48f8

Browse files
committed
Hook compiler-rt up to the swift build system
1 parent f543c33 commit 53f48f8

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

test/SILGen/coverage_smoke.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: %target-build-swift %s -profile-generate -profile-coverage-mapping -o %t/main
3+
// RUN: env LLVM_PROFILE_FILE=%t/default.profraw %target-run %t/main
4+
// RUN: %llvm-profdata merge %t/default.profraw -o %t/default.profdata
5+
// RUN: %llvm-profdata show %t/default.profdata -function=main | FileCheck %s --check-prefix=CHECK-PROF
6+
// RUN: %llvm-cov show %t/main -instr-profile=%t/default.profdata | FileCheck %s --check-prefix=CHECK-COV
7+
// RUN: rm -rf %t
8+
// REQUIRES: profile_runtime
9+
// REQUIRES: OS=macosx
10+
11+
func main() {
12+
// CHECK-PROF: Counters: 2
13+
// CHECK-PROF: Function count: 1
14+
// CHECK-COV: 1|{{.*}}[[@LINE+1]]|{{.*}}if (true)
15+
if (true) {}
16+
}
17+
18+
main()

test/lit.cfg

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ config.swift_reflection_test = inferSwiftBinary('swift-reflection-test')
275275
config.clang = inferSwiftBinary('clang')
276276
config.llvm_link = inferSwiftBinary('llvm-link')
277277
config.swift_llvm_opt = inferSwiftBinary('swift-llvm-opt')
278+
config.llvm_profdata = inferSwiftBinary('llvm-profdata')
279+
config.llvm_cov = inferSwiftBinary('llvm-cov')
278280

279281
config.gyb = os.path.join(config.swift_src_root, 'utils', 'gyb')
280282
config.rth = os.path.join(config.swift_src_root, 'utils', 'rth') # Resilience test helper
@@ -725,6 +727,39 @@ else:
725727

726728
config.substitutions.append(("%target-sdk-name", config.target_sdk_name))
727729

730+
config.compiler_rt_libs = []
731+
config.compiler_rt_platform = {
732+
'iphoneos': 'ios',
733+
'appletvos': 'tvos',
734+
'watchos': 'watchos',
735+
'iphonesimulator': 'iossim',
736+
'watchsimulator': 'watchossim',
737+
'appletvsimulator': 'tvossim',
738+
'macosx': 'osx'
739+
}.get(config.target_sdk_name, run_cpu)
740+
741+
def source_compiler_rt_libs(path):
742+
if os.path.exists(path):
743+
config.compiler_rt_libs.extend([lib for lib in
744+
os.listdir(path)
745+
if lib.startswith('libclang_rt.')
746+
and config.compiler_rt_platform in lib])
747+
748+
source_compiler_rt_libs(os.path.join(test_resource_dir, 'clang', 'lib',
749+
platform.system().lower()))
750+
751+
def check_runtime_feature(name):
752+
for lib in config.compiler_rt_libs:
753+
if lib.startswith('libclang_rt.' + name + '_'):
754+
config.available_features.add(name + '_runtime')
755+
return
756+
757+
check_runtime_feature('profile')
758+
check_runtime_feature('asan')
759+
check_runtime_feature('ubsan')
760+
check_runtime_feature('tsan')
761+
check_runtime_feature('safestack')
762+
728763
if not getattr(config, 'target_run_simple_swift', None):
729764
config.target_run_simple_swift = (
730765
'rm -rf %%t && mkdir -p %%t && '
@@ -833,3 +868,6 @@ config.substitutions.append(('%target-object-format', config.target_object_forma
833868

834869
config.substitutions.append(('%target-resilience-test-wmo', config.target_resilience_test_wmo))
835870
config.substitutions.append(('%target-resilience-test', config.target_resilience_test))
871+
872+
config.substitutions.append(('%llvm-profdata', config.llvm_profdata))
873+
config.substitutions.append(('%llvm-cov', config.llvm_cov))

utils/build-script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ SWIFT_SOURCE_ROOT: a directory containing the source for LLVM, Clang, Swift.
170170
/lldb (optional)
171171
/llbuild (optional)
172172
/swiftpm (optional, requires llbuild)
173+
/compiler-rt (optional)
173174
/swift-corelibs-xctest (optional)
174175
/swift-corelibs-foundation (optional)
175176
/swift-corelibs-libdispatch (optional)

utils/build-script-impl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ function set_deployment_target_based_options() {
488488
-DCMAKE_OSX_SYSROOT:PATH="$(xcrun --sdk ${xcrun_sdk_name} --show-sdk-path)"
489489
-DLLVM_HOST_TRIPLE:STRING="${llvm_host_triple}"
490490
-DLLVM_ENABLE_LIBCXX:BOOL=TRUE
491+
-DCOMPILER_RT_ENABLE_IOS:BOOL=$(false_true ${SKIP_IOS})
492+
-DCOMPILER_RT_ENABLE_WATCHOS:BOOL=FALSE
493+
-DCOMPILER_RT_ENABLE_TVOS:BOOL=FALSE
491494
)
492495
if [[ $(true_false "${LLVM_ENABLE_LTO}") = "TRUE" ]]; then
493496
if [[ $(cmake_needs_to_specify_standard_computed_defaults) = "TRUE" ]]; then
@@ -805,6 +808,10 @@ function true_false() {
805808
esac
806809
}
807810

811+
function false_true() {
812+
true_false $(not "$1")
813+
}
814+
808815
function cmake_version() {
809816
echo $("${CMAKE}" --version | grep "cmake version" | cut -f 3 -d " ")
810817
}
@@ -975,6 +982,14 @@ if [ ! -d "${CLANG_SOURCE_DIR}" ] ; then
975982
ln -sf "${WORKSPACE}/clang" "${CLANG_SOURCE_DIR}"
976983
fi
977984

985+
# Symlink compiler-rt into the llvm tree, if it exists.
986+
COMPILER_RT_SOURCE_DIR="${LLVM_SOURCE_DIR}/projects/compiler-rt"
987+
if [ -e "${WORKSPACE}/compiler-rt" ] ; then
988+
if [ ! -d "${COMPILER_RT_SOURCE_DIR}" ] ; then
989+
ln -sf "${WORKSPACE}/compiler-rt" "${COMPILER_RT_SOURCE_DIR}"
990+
fi
991+
fi
992+
978993
PRODUCTS=(cmark llvm swift)
979994
if [[ ! "${SKIP_BUILD_LLDB}" ]] ; then
980995
PRODUCTS=("${PRODUCTS[@]}" lldb)

utils/update-checkout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ REPOSITORIES = {
3232
'cmark': 'apple/swift-cmark',
3333
'llbuild': 'apple/swift-llbuild',
3434
'swiftpm': 'apple/swift-package-manager',
35+
'compiler-rt': 'apple/swift-compiler-rt',
3536
'swift-corelibs-xctest': 'apple/swift-corelibs-xctest',
3637
'swift-corelibs-foundation': 'apple/swift-corelibs-foundation',
3738
'swift-corelibs-libdispatch': 'apple/swift-corelibs-libdispatch',

0 commit comments

Comments
 (0)