Skip to content

Commit 186717f

Browse files
authored
Merge pull request #34628 from buttaface/native-clang
2 parents d125f3a + 934823a commit 186717f

File tree

12 files changed

+52
-26
lines changed

12 files changed

+52
-26
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,12 @@ if(SWIFT_PATH_TO_CMARK_BUILD)
481481
endif()
482482
message(STATUS "")
483483

484-
if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
485-
set(SWIFT_CROSS_COMPILING FALSE)
484+
# Check if a prebuilt clang path was passed in, as this variable will be
485+
# assigned if not, in SwiftSharedCMakeConfig.
486+
if("${SWIFT_NATIVE_CLANG_TOOLS_PATH}" STREQUAL "")
487+
set(SWIFT_PREBUILT_CLANG FALSE)
486488
else()
487-
set(SWIFT_CROSS_COMPILING TRUE)
489+
set(SWIFT_PREBUILT_CLANG TRUE)
488490
endif()
489491

490492
include(SwiftSharedCMakeConfig)

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro(swift_common_standalone_build_config_llvm product)
5858
fix_imported_targets_for_xcode("${LLVM_EXPORTED_TARGETS}")
5959
endif()
6060

61-
if(NOT CMAKE_CROSSCOMPILING AND NOT SWIFT_CROSS_COMPILING)
61+
if(NOT CMAKE_CROSSCOMPILING)
6262
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
6363
endif()
6464

@@ -159,7 +159,7 @@ endmacro()
159159
macro(swift_common_standalone_build_config_clang product)
160160
find_package(Clang CONFIG REQUIRED NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
161161

162-
if (NOT CMAKE_CROSSCOMPILING)
162+
if (NOT CMAKE_CROSSCOMPILING AND NOT SWIFT_PREBUILT_CLANG)
163163
set(${product}_NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
164164
endif()
165165

stdlib/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ else()
112112
# If we use Clang-cl or MSVC, CMake provides default compiler and linker flags that are incompatible
113113
# with the frontend of Clang or Clang++.
114114
if(SWIFT_COMPILER_IS_MSVC_LIKE)
115-
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang-cl")
116-
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang-cl")
115+
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang-cl")
116+
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang-cl")
117117
else()
118-
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang++")
119-
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang")
118+
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang++")
119+
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang")
120120
endif()
121121

122122
if(CMAKE_C_COMPILER_LAUNCHER MATCHES ".*distcc")

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,8 @@ function(add_swift_target_library name)
16541654
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-warn-implicit-overrides")
16551655
endif()
16561656

1657-
if(NOT SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER AND NOT BUILD_STANDALONE)
1657+
if(NOT SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER AND NOT BUILD_STANDALONE AND
1658+
NOT SWIFT_PREBUILT_CLANG)
16581659
list(APPEND SWIFTLIB_DEPENDS clang)
16591660
endif()
16601661

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ endif()
111111
# First extract the "version" used for Clang's resource directory.
112112
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
113113
"${LLVM_PACKAGE_VERSION}")
114-
if(NOT SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
114+
if(NOT SWIFT_INCLUDE_TOOLS AND
115+
(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER OR SWIFT_PREBUILT_CLANG))
115116
if(SWIFT_COMPILER_IS_MSVC_LIKE)
116117
execute_process(COMMAND ${CMAKE_C_COMPILER} /clang:-print-resource-dir
117118
OUTPUT_VARIABLE clang_headers_location

unittests/runtime/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
1313
# If we use Clang-cl or MSVC, CMake provides default compiler and linker flags that are incompatible
1414
# with the frontend of Clang or Clang++.
1515
if(SWIFT_COMPILER_IS_MSVC_LIKE)
16-
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang-cl")
17-
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang-cl")
16+
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang-cl")
17+
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang-cl")
1818
else()
19-
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang++")
20-
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_LLVM_TOOLS_PATH}/clang")
19+
set(CMAKE_CXX_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang++")
20+
set(CMAKE_C_COMPILER "${SWIFT_NATIVE_CLANG_TOOLS_PATH}/clang")
2121
endif()
2222

2323
if(CMAKE_C_COMPILER_LAUNCHER MATCHES ".*distcc")

utils/build-presets.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,9 @@ skip-build-cmark
22832283
skip-build-benchmarks
22842284
skip-test-cmark
22852285

2286-
# This triggers the stdlib standalone build: Don't build tools (the compiler),
2287-
# assume we are working with the host compiler.
2286+
# This triggers the stdlib standalone build: don't build the native tools from
2287+
# scratch, ie the compiler.
22882288
build-swift-tools=0
2289-
build-runtime-with-host-compiler=1
22902289

22912290
# Then set the paths to our native tools. If compiling against a toolchain,
22922291
# these should all be the ./usr/bin directory.

utils/build-script

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,18 @@ class BuildScriptInvocation(object):
708708
impl_args += [
709709
"--host-libtool", toolchain.libtool,
710710
]
711+
if args.native_clang_tools_path is not None:
712+
impl_args += [
713+
"--native-clang-tools-path=%s" % args.native_clang_tools_path
714+
]
715+
if args.native_llvm_tools_path is not None:
716+
impl_args += [
717+
"--native-llvm-tools-path=%s" % args.native_llvm_tools_path
718+
]
719+
if args.native_swift_tools_path is not None:
720+
impl_args += [
721+
"--native-swift-tools-path=%s" % args.native_swift_tools_path
722+
]
711723

712724
# If we have extra_swift_args, combine all of them together and then
713725
# add them as one command.

utils/build-script-impl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,13 +1485,6 @@ for host in "${ALL_HOSTS[@]}"; do
14851485
fi
14861486
fi
14871487

1488-
if [[ "${NATIVE_CLANG_TOOLS_PATH}" ]] ; then
1489-
common_cmake_options_host+=(
1490-
-DCMAKE_C_COMPILER="${NATIVE_CLANG_TOOLS_PATH}/clang"
1491-
-DCMAKE_CXX_COMPILER="${NATIVE_CLANG_TOOLS_PATH}/clang++"
1492-
)
1493-
fi
1494-
14951488
llvm_cmake_options=(
14961489
"${llvm_cmake_options[@]}"
14971490
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ def create_argument_parser():
374374
option('--host-cxx', store_path(executable=True),
375375
help='the absolute path to CXX, the "clang++" compiler for the '
376376
'host platform. Default is auto detected.')
377+
option('--native-swift-tools-path', store_path,
378+
help='the path to a directory that contains prebuilt Swift tools '
379+
'that are executable on the host platform')
380+
option('--native-clang-tools-path', store_path,
381+
help='the path to a directory that contains prebuilt Clang tools '
382+
'that are executable on the host platform')
383+
option('--native-llvm-tools-path', store_path,
384+
help='the path to a directory that contains prebuilt LLVM tools '
385+
'that are executable on the host platform')
377386
option('--cmake-c-launcher', store_path(executable=True),
378387
default=os.environ.get('C_COMPILER_LAUNCHER', None),
379388
help='the absolute path to set CMAKE_C_COMPILER_LAUNCHER')

utils/build_swift/tests/expected_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
'lto_type': None,
190190
'maccatalyst': False,
191191
'maccatalyst_ios_tests': False,
192+
'native_clang_tools_path': None,
193+
'native_llvm_tools_path': None,
194+
'native_swift_tools_path': None,
192195
'dump_config': False,
193196
'show_sdks': False,
194197
'skip_build': False,
@@ -653,6 +656,9 @@ class BuildScriptImplOption(_BaseOption):
653656
PathOption('--install-symroot'),
654657
PathOption('--install-destdir'),
655658
EnableOption('--install-all'),
659+
PathOption('--native-clang-tools-path'),
660+
PathOption('--native-llvm-tools-path'),
661+
PathOption('--native-swift-tools-path'),
656662
PathOption('--symbols-package'),
657663
PathOption('--cmake-c-launcher'),
658664
PathOption('--cmake-cxx-launcher'),

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ def install_toolchain_path(self, host_target):
167167
"""toolchain_path() -> string
168168
169169
Returns the path to the toolchain that is being created as part of this
170-
build.
170+
build, or to a native prebuilt toolchain that was passed in.
171171
"""
172+
if self.args.native_swift_tools_path is not None:
173+
return os.path.split(self.args.native_swift_tools_path)[0]
174+
172175
install_destdir = self.args.install_destdir
173176
if self.args.cross_compile_hosts:
174177
build_root = os.path.dirname(self.build_dir)

0 commit comments

Comments
 (0)