mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
95 lines
5.6 KiB
INI
95 lines
5.6 KiB
INI
# Make a local copy of the substitutions.
|
|
config.substitutions = list(config.substitutions)
|
|
|
|
def get_target_os():
|
|
import re
|
|
(run_cpu, run_vendor, run_os, run_version) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
|
|
return run_os
|
|
|
|
clang_compile_opt = '-I' + config.swiftlib_dir + ' '
|
|
clang_opt = clang_compile_opt
|
|
|
|
is_cf_options_interop_updated = True
|
|
|
|
if config.variant_sdk and config.variant_sdk != "":
|
|
# Check if CF_OPTIONS macro has been updated to be imported into Swift in C++ mode correctly.
|
|
cf_avail_path = os.path.join(config.variant_sdk, 'System', 'Library', 'Frameworks', 'CoreFoundation.framework', 'Versions', 'A', 'Headers', 'CFAvailability.h')
|
|
cf_avail_path_embedded = os.path.join(config.variant_sdk, 'System', 'Library', 'Frameworks', 'CoreFoundation.framework', 'Headers', 'CFAvailability.h')
|
|
if os.path.exists(cf_avail_path) or os.path.exists(cf_avail_path_embedded):
|
|
cf_avail_path_use = cf_avail_path if os.path.exists(cf_avail_path) else cf_avail_path_embedded
|
|
with open(cf_avail_path_use, 'r') as file:
|
|
contents = file.read()
|
|
import re
|
|
regex = r'^#define CF_OPTIONS\(_type, _name\) _type _name; enum __CF_OPTIONS_ATTRIBUTES'
|
|
if re.search(regex, contents, re.MULTILINE):
|
|
is_cf_options_interop_updated = False
|
|
|
|
if is_cf_options_interop_updated:
|
|
config.available_features.add('cxx-interop-fixed-cf_options')
|
|
|
|
if get_target_os() in ['windows-msvc']:
|
|
import os
|
|
config.substitutions.insert(0, ('%target-abi', 'WIN'))
|
|
# Clang should build object files with link settings equivalent to -libc MD
|
|
# when building for the MSVC target.
|
|
clang_opt = clang_compile_opt + '-D_MT -D_DLL -Xclang --dependent-lib=msvcrt -Xclang --dependent-lib=oldnames '
|
|
# ucrt.modulemap currently requires -fbuiltin-headers-in-system-modules. -strict-implicit-module-context
|
|
# is necessary for -Xcc arguments to be passed through ModuleInterfaceLoader.
|
|
config.substitutions.insert(0, ('%target-swift-flags', '-vfsoverlay {} -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules'.format(
|
|
os.path.join(config.swift_obj_root,
|
|
'stdlib',
|
|
'windows-vfs-overlay.yaml'))))
|
|
else:
|
|
# FIXME(compnerd) do all the targets we currently support use SysV ABI?
|
|
config.substitutions.insert(0, ('%target-abi', 'SYSV'))
|
|
config.substitutions.insert(0, ('%target-swift-flags', ''))
|
|
|
|
if get_target_os() in ['linux-gnu']:
|
|
if os.path.exists('/usr/include/c++/v1') or os.path.exists('/usr/local/include/c++/v1'):
|
|
config.available_features.add('system_wide_libcxx')
|
|
|
|
if config.target_sdk_libcxx_path != '':
|
|
if os.path.exists(os.path.join(config.target_sdk_libcxx_path, "span")):
|
|
config.available_features.add('std_span')
|
|
elif get_target_os() in ['linux-gnu']:
|
|
for p in ['/usr/include/c++/', '/usr/local/include/c++/']:
|
|
if not os.path.isdir(p):
|
|
continue
|
|
for subdir in os.listdir(p):
|
|
if not subdir.isdigit():
|
|
# skip paths libc++ paths like /usr/include/c++/v1, we want libstdc++ paths only (like /usr/include/c++/13)
|
|
continue
|
|
if os.path.exists(os.path.join(p, subdir, "span")):
|
|
config.available_features.add('std_span')
|
|
elif get_target_os() in ['windows-msvc']:
|
|
# We don't test on any versions of MSVC without std::span support.
|
|
# FIXME: figure out where to do lookup for C++ stdlib headers on Windows - we'll probably need it eventually
|
|
config.available_features.add('std_span')
|
|
|
|
# Enable C++ interop when compiling Swift sources.
|
|
config.substitutions.insert(0, ('%target-interop-build-swift',
|
|
'%target-build-swift -cxx-interoperability-mode=default '))
|
|
|
|
# Build C files disallowing implicit functions and with matching link settings, if required by the target.
|
|
config.substitutions.insert(0, ('%target-interop-build-clang', '%target-clang -x c -Werror=implicit-function-declaration ' + clang_opt))
|
|
|
|
# Build C++ files with matching link settings, if required by the target.
|
|
config.substitutions.insert(0, ('%target-interop-build-clangxx', '%target-clangxx --std=gnu++14 ' + clang_opt))
|
|
|
|
# Test parsing of the generated C++ header in different C++ language modes.
|
|
config.substitutions.insert(0, (r'%check-interop-cxx-header-in-clang\(([^)]+)\)',
|
|
SubstituteCaptures(r'%check-cxx-header-in-clang -std=c++14 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB ' + clang_compile_opt + r'\1 && '
|
|
r'%check-cxx-header-in-clang -std=c++17 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB ' + clang_compile_opt + r'\1 && '
|
|
r'%check-cxx-header-in-clang -std=c++20 -Wno-padded -Wno-c11-extensions -D_LIBCPP_CSTDLIB ' + clang_compile_opt + r'\1')))
|
|
|
|
# Test parsing of the generated C header in different C language modes.
|
|
config.substitutions.insert(0, (
|
|
r'%check-interop-c-header-in-clang\(([^)]+)\)',
|
|
SubstituteCaptures(
|
|
r'%check-c-header-in-clang -std=c99 -Wno-padded -Wno-c++-keyword -Wno-unknown-warning-option -Wno-c11-extensions -Wno-pre-c11-compat \1 && '
|
|
r'%check-c-header-in-clang -std=c11 -Wno-padded -Wno-c++-keyword -Wno-unknown-warning-option -Wno-pre-c11-compat \1'
|
|
)
|
|
))
|
|
|
|
config.substitutions.insert(0, ('%bridging-path', '%swift_src_root%{fs-sep}lib%{fs-sep}ClangImporter%{fs-sep}SwiftBridging'))
|