Skip to content

Commit

Permalink
build: adjust the early swift-driver handling
Browse files Browse the repository at this point in the history
Windows has a strict limit on the file path, and use of extended names
for the build is not possible. Rather than hardcoding the location of
the early swift-driver build, allow the user to specify the path. If the
path is specified, we will attempt to copy `swift-driver` and
`swift-help` from that location. Adjust the code to account for the
build executable suffix. This should allow Windows to experiment with an
early swift-driver build.
  • Loading branch information
compnerd committed Nov 13, 2024
1 parent d2d830f commit cc27c83
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
44 changes: 19 additions & 25 deletions cmake/modules/SwiftUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -190,33 +190,27 @@ endfunction()
# we create a `swift-driver` symlink adjacent to the `swift` and `swiftc` executables
# to ensure that `swiftc` forwards to the standalone driver when invoked.
function(swift_create_early_driver_copies target)
# Early swift-driver is built adjacent to the compiler (swift build dir)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(driver_package_configuration_dir "release")
else()
set(driver_package_configuration_dir "debug")
endif()

set(driver_bin_dir "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/bin")
set(swift_bin_dir "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
# If early swift-driver wasn't built, nothing to do here.
if(NOT EXISTS "${driver_bin_dir}/swift-driver" OR NOT EXISTS "${driver_bin_dir}/swift-help")
message(STATUS "Skipping creating early SwiftDriver symlinks - no early SwiftDriver build found at: ${driver_bin_dir}.")
return()
set(SWIFT_EARLY_SWIFT_DRIVER_BUILD "" CACHE PATH "Path to early swift-driver build")

if(NOT SWIFT_EARLY_SWIFT_DRIVER_BUILD)
return()
endif()

message(STATUS "Copying over early SwiftDriver executable.")
message(STATUS "From: ${driver_bin_dir}/swift-driver")
message(STATUS "To: ${swift_bin_dir}/swift-driver")
# Use configure_file instead of file(COPY...) to establish a dependency.
# Further Changes to `swift-driver` will cause it to be copied over.
configure_file(${driver_bin_dir}/swift-driver ${swift_bin_dir}/swift-driver COPYONLY)

message(STATUS "From: ${driver_bin_dir}/swift-help")
message(STATUS "To: ${swift_bin_dir}/swift-help")
# Use configure_file instead of file(COPY...) to establish a dependency.
# Further Changes to `swift-driver` will cause it to be copied over.
configure_file(${driver_bin_dir}/swift-help ${swift_bin_dir}/swift-help COPYONLY)
if(EXISTS ${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-driver${CMAKE_EXECUTABLE_SUFFIX})
message(STATUS "Creating early SwiftDriver symlinks")

# Use `configure_file` instead of `file(COPY ...)` to establish a
# dependency. Further changes to `swift-driver` will cause it to be copied
# over.
configure_file(${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-driver${CMAKE_EXECUTABLE_SUFFIX}
COPYONLY)
configure_file(${SWIFT_EARLY_SWIFT_DRIVER_BUILD}/swift-help${CMAKE_EXECUTABLE_SUFFIX}
${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-help${CMAKE_EXECUTABLE_SUFFIX}
COPYONLY)
else()
message(STATUS "Not creating early SwiftDriver symlinks (swift-driver not found)")
endif()
endfunction()

function(dump_swift_vars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ def convert_to_impl_arguments(self):
args.extra_cmake_options.append(
'-DSWIFTSYNTAX_ENABLE_ASSERTIONS:BOOL=TRUE')

if args.build_early_swift_driver:
configuration = 'release' if str(args.swift_build_variant) in [
'Release',
'RelWithDebInfo'
] else 'debug'
directory = 'earlyswiftdriver-{}'.format(self.args.host_target)

swift_driver_build = os.path.join(self.workspace.build_root,
directory,
configuration,
'bin')
args.extra_cmake_options.append(
'-DSWIFT_EARLY_SWIFT_DRIVER_BUILD={}'.format(swift_driver_build))

# Then add subproject install flags that either skip building them /or/
# if we are going to build them and install_all is set, we also install
# them.
Expand All @@ -275,7 +289,7 @@ def convert_to_impl_arguments(self):
(args.build_libdispatch, "libdispatch"),
(args.build_libxml2, 'libxml2'),
(args.build_zlib, 'zlib'),
(args.build_curl, 'curl')
(args.build_curl, 'curl'),
]
for (should_build, string_name) in conditional_subproject_configs:
if not should_build and not self.args.infer_dependencies:
Expand Down

0 comments on commit cc27c83

Please sign in to comment.