Skip to content
Merged
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
15 changes: 9 additions & 6 deletions utils/swift_build_support/swift_build_support/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ def __iadd__(self, other):

class CMake(object):

def __init__(self, args, toolchain, prefer_just_built_toolchain=False):
"""If prefer_just_built_toolchain is set to True, we set the clang, clang++,
and Swift compilers from the installed toolchain.
def __init__(self, args, toolchain, prefer_native_toolchain=False):
"""If prefer_native_toolchain is set to True, we set the clang, clang++,
and Swift compilers from the toolchain explicitly specified by the
native-*-tools-path options or just installed toolchain if the options
are not specified. If prefer_native_toolchain is set to False, we use
system defaults.
"""
self.args = args
self.toolchain = toolchain
self.prefer_just_built_toolchain = prefer_just_built_toolchain
self.prefer_native_toolchain = prefer_native_toolchain

def common_options(self, product=None):
"""Return options used for all products, including LLVM/Clang
Expand Down Expand Up @@ -146,8 +149,8 @@ def common_options(self, product=None):
if args.cmake_cxx_launcher:
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", args.cmake_cxx_launcher)

if self.prefer_just_built_toolchain and product:
toolchain_path = product.install_toolchain_path(args.host_target)
if self.prefer_native_toolchain and product:
toolchain_path = product.native_toolchain_path(args.host_target)
cmake_swiftc_path = os.getenv('CMAKE_Swift_COMPILER',
os.path.join(toolchain_path, 'bin', 'swiftc'))
define("CMAKE_C_COMPILER:PATH", os.path.join(toolchain_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def is_verbose(self):
return self.args.verbose_build

def build_with_cmake(self, build_targets, build_type, build_args,
prefer_just_built_toolchain=False):
prefer_native_toolchain=False):
assert self.toolchain.cmake is not None
cmake_build = []
_cmake = cmake.CMake(self.args, self.toolchain,
prefer_just_built_toolchain)
prefer_native_toolchain)

if self.toolchain.distcc_pump:
cmake_build.append(self.toolchain.distcc_pump)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def build(self, host_target):

# Build!
self.build_with_cmake(["swift-stdlib-freestanding"], build_variant, [],
prefer_just_built_toolchain=True)
prefer_native_toolchain=True)

def should_test(self, host_target):
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def should_install(self, host_target):

def build(self, host_target):
build_root = os.path.dirname(self.build_dir)
llvm_build_dir = os.path.join('..', build_root, '%s-%s' % ('llvm', host_target))
llvm_build_bin_dir = os.path.join(
'..', build_root, '%s-%s' % ('llvm', host_target), 'bin')
llvm_tools_path = self.args.native_llvm_tools_path or llvm_build_bin_dir
clang_tools_path = self.args.native_clang_tools_path or llvm_build_bin_dir
build_jobs = self.args.build_jobs or multiprocessing.cpu_count()

sysroot_build_dir = WASILibc.sysroot_build_path(build_root, host_target)
Expand All @@ -66,9 +69,9 @@ def build(self, host_target):
'OBJDIR=' + os.path.join(self.build_dir, 'obj'),
'SYSROOT=' + sysroot_build_dir,
'INSTALL_DIR=' + WASILibc.sysroot_install_path(build_root),
'CC=' + os.path.join(llvm_build_dir, 'bin', 'clang'),
'AR=' + os.path.join(llvm_build_dir, 'bin', 'llvm-ar'),
'NM=' + os.path.join(llvm_build_dir, 'bin', 'llvm-nm'),
'CC=' + os.path.join(clang_tools_path, 'clang'),
'AR=' + os.path.join(llvm_tools_path, 'llvm-ar'),
'NM=' + os.path.join(llvm_tools_path, 'llvm-nm'),
])

@classmethod
Expand Down Expand Up @@ -119,7 +122,10 @@ def should_install(self, host_target):

def build(self, host_target):
build_root = os.path.dirname(self.build_dir)
llvm_build_dir = os.path.join('..', build_root, '%s-%s' % ('llvm', host_target))
llvm_build_bin_dir = os.path.join(
'..', build_root, '%s-%s' % ('llvm', host_target), 'bin')
llvm_tools_path = self.args.native_llvm_tools_path or llvm_build_bin_dir
clang_tools_path = self.args.native_clang_tools_path or llvm_build_bin_dir

self.cmake_options.define('CMAKE_SYSROOT:PATH',
WASILibc.sysroot_build_path(build_root, host_target))
Expand All @@ -144,13 +150,13 @@ def build(self, host_target):
self.cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI')
self.cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32')
self.cmake_options.define('CMAKE_AR:FILEPATH',
os.path.join(llvm_build_dir, 'bin', 'llvm-ar'))
os.path.join(llvm_tools_path, 'llvm-ar'))
self.cmake_options.define('CMAKE_RANLIB:FILEPATH',
os.path.join(llvm_build_dir, 'bin', 'llvm-ranlib'))
os.path.join(llvm_tools_path, 'llvm-ranlib'))
self.cmake_options.define('CMAKE_C_COMPILER:FILEPATH',
os.path.join(llvm_build_dir, 'bin', 'clang'))
os.path.join(clang_tools_path, 'clang'))
self.cmake_options.define('CMAKE_CXX_COMPILER:STRING',
os.path.join(llvm_build_dir, 'bin', 'clang++'))
os.path.join(clang_tools_path, 'clang++'))
# Explicitly disable exceptions even though it's usually implicitly disabled by
# LIBCXX_ENABLE_EXCEPTIONS because the CMake feature check fails to detect
# -fno-exceptions support in clang due to missing compiler-rt while configuring
Expand Down Expand Up @@ -188,7 +194,7 @@ def build(self, host_target):
self.cmake_options.define('UNIX:BOOL', 'TRUE')

self.build_with_cmake([], self.args.build_variant, [],
prefer_just_built_toolchain=True)
prefer_native_toolchain=True)
self.install_with_cmake(
["install"], WASILibc.sysroot_install_path(build_root))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build(self, host_target):
'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant)

# Toolchain configuration
toolchain_path = self.install_toolchain_path(host_target)
toolchain_path = self.native_toolchain_path(host_target)
# Explicitly set the CMake AR and RANLIB to force it to use llvm-ar/llvm-ranlib
# instead of the system ar/ranlib, which usually don't support WebAssembly
# object files.
Expand Down Expand Up @@ -117,7 +117,7 @@ def build(self, host_target):

# Configure with WebAssembly target variant, and build with just-built toolchain
self.build_with_cmake([], self._build_variant, [],
prefer_just_built_toolchain=True)
prefer_native_toolchain=True)

def test(self, host_target):
build_root = os.path.dirname(self.build_dir)
Expand Down