Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

project(XCTest LANGUAGES Swift)

if(UNIX)
enable_language(C)
endif()

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(USE_FOUNDATION_FRAMEWORK "Use Foundation.framework on Darwin" NO)

Expand Down Expand Up @@ -35,7 +39,6 @@ set(XCTest_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_S
set(XCTest_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${XCTest_PLATFORM_SUBDIR}")

if(UNIX)
enable_language(C)
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
endif()

Expand Down Expand Up @@ -88,6 +91,11 @@ if(SwiftTesting_FOUND)
_TestingInterop)
target_compile_definitions(XCTest PRIVATE
XCT_BUILD_WITH_INTEROP)
if(NOT BUILD_SHARED_LIBS)
target_compile_options(XCTest PRIVATE
"SHELL:-Xfrontend -public-autolink-library -Xfrontend _TestingInterop"
"SHELL:-Xfrontend -public-autolink-library -Xfrontend _TestingInternals")
endif()
endif()

if(USE_FOUNDATION_FRAMEWORK)
Expand Down Expand Up @@ -150,6 +158,7 @@ if(ENABLE_TESTING)
LIBDISPATCH_OVERLAY_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}/src/swift
SWIFT_TESTING_BUILD_DIR=${SwiftTesting_BUILD_DIR}
SWIFT_TESTING_MACRO_BUILD_DIR=${SwiftTesting_MACRO_DIR}
XCTEST_BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
SWIFT_EXEC=${CMAKE_Swift_COMPILER}
$<TARGET_FILE:Python3::Interpreter> ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
COMMENT
Expand Down
71 changes: 47 additions & 24 deletions Tests/Functional/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ def _getenv(name):
return value

built_products_dir = _getenv('BUILT_PRODUCTS_DIR')
build_shared_libs = os.getenv('XCTEST_BUILD_SHARED_LIBS', 'YES').lower() in (
'1', 'on', 'true', 'yes')
# Force tests to build with -swift-version 5 for now.
swift_exec = [ '"' + _getenv('SWIFT_EXEC') + '"', '-swift-version', '5', ]
swift_exec.extend(shlex.split(os.getenv('SWIFT_FLAGS', '')))
if not platform.system() == 'Windows':
if not build_shared_libs:
swift_exec.append('-static-stdlib')
elif not platform.system() == 'Windows':
swift_exec.extend(['-Xlinker', '-rpath', '-Xlinker', built_products_dir,])
swift_exec.extend([
'-L', built_products_dir,
Expand Down Expand Up @@ -80,9 +84,12 @@ else:
'-I', os.path.join(swift_testing_dir, 'swift'),
'-L', os.path.join(swift_testing_dir, 'lib'),
'-l_TestingInterop',
'-plugin-path', swift_testing_macros_dir,
])
if not platform.system() == 'Windows':
if swift_testing_macros_dir:
swift_exec.extend(['-plugin-path', swift_testing_macros_dir])
if not build_shared_libs:
swift_exec.append('-l_TestingInternals')
elif not platform.system() == 'Windows':
swift_exec.extend([
'-Xlinker', '-rpath', '-Xlinker', os.path.join(swift_testing_dir, 'lib'),
])
Expand All @@ -94,7 +101,7 @@ else:
if sdkroot:
swift_exec.extend(['-sdk', '"' + sdkroot + '"'])
swift_exec.extend(['-Xlinker', '-nodefaultlib:libcmt'])
else:
elif build_shared_libs:
swift_exec.extend([
'-Xlinker', '-rpath', '-Xlinker', foundation_dir,
'-Xlinker', '-rpath', '-Xlinker', os.path.join(foundation_dir, 'Foundation'),
Expand All @@ -113,27 +120,43 @@ else:
'-I', os.path.join(foundation_dir, '_CModulesForClients'),
'-Xcc', '-F', '-Xcc', foundation_dir,
])
else:
swift_exec.extend([
'-L', foundation_dir,
'-L', os.path.join(foundation_dir, 'Foundation'),
'-L', os.path.join(foundation_dir, 'Sources', 'Foundation'),
'-L', os.path.join(foundation_dir, 'Sources', 'FoundationNetworking'),
'-L', os.path.join(foundation_dir, 'Sources', 'FoundationXML'),
'-L', os.path.join(foundation_dir, 'lib'),
'-I', foundation_dir,
'-I', os.path.join(foundation_dir, 'swift'),
'-I', os.path.join(foundation_dir, '_CModulesForClients'),
'-Xcc', '-F', '-Xcc', foundation_dir,
])

# We also need to link swift-corelibs-libdispatch, if
# swift-corelibs-foundation is using it.
libdispatch_src_dir = os.getenv('LIBDISPATCH_SRC_DIR')
libdispatch_build_dir = os.getenv('LIBDISPATCH_BUILD_DIR')
libdispatch_overlay_dir = os.getenv('LIBDISPATCH_OVERLAY_DIR')
if ((libdispatch_src_dir is not None)
and (libdispatch_build_dir is not None)
and (libdispatch_overlay_dir is not None)):
swift_exec.extend([
'-Xcc', '-fblocks',
'-I', libdispatch_src_dir,
'-I', libdispatch_overlay_dir,
'-I', os.path.join(libdispatch_overlay_dir, 'swift'),
'-L', libdispatch_build_dir,
'-L', os.path.join(libdispatch_build_dir, 'src'),
'-L', os.path.join(libdispatch_build_dir, 'src', 'BlocksRuntime'),
'-L', os.path.join(libdispatch_build_dir, 'src', 'swift'),
'-vfsoverlay', os.path.join(libdispatch_build_dir, 'dispatch-vfs-overlay.yaml'),
'-Xlinker', '-rpath', '-Xlinker', libdispatch_build_dir,
])
# We also need to link swift-corelibs-libdispatch, if
# swift-corelibs-foundation is using it.
libdispatch_src_dir = os.getenv('LIBDISPATCH_SRC_DIR')
libdispatch_build_dir = os.getenv('LIBDISPATCH_BUILD_DIR')
libdispatch_overlay_dir = os.getenv('LIBDISPATCH_OVERLAY_DIR')
if ((libdispatch_src_dir is not None)
and (libdispatch_build_dir is not None)
and (libdispatch_overlay_dir is not None)):
swift_exec.extend([
'-Xcc', '-fblocks',
'-I', libdispatch_src_dir,
'-I', libdispatch_overlay_dir,
'-I', os.path.join(libdispatch_overlay_dir, 'swift'),
'-L', libdispatch_build_dir,
'-L', os.path.join(libdispatch_build_dir, 'src'),
'-L', os.path.join(libdispatch_build_dir, 'src', 'BlocksRuntime'),
'-L', os.path.join(libdispatch_build_dir, 'src', 'swift'),
'-vfsoverlay', os.path.join(libdispatch_build_dir, 'dispatch-vfs-overlay.yaml'),
])
if build_shared_libs:
swift_exec.extend([
'-Xlinker', '-rpath', '-Xlinker', libdispatch_build_dir,
])

# Having prepared the swiftc command, we set the substitution.
config.substitutions.append(('%{swiftc}', ' '.join(swift_exec)))
Expand Down