From 29de93de018488a2dc233a01acafabbf3e9740bf Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Tue, 18 Mar 2025 16:04:28 -0700 Subject: [PATCH 1/2] Split file copying Splitting the file copying out of the library copying. This allows us to list a specific set of files to copy into the new stdlib build from specific locations. --- Runtimes/Resync.cmake | 70 +++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/Runtimes/Resync.cmake b/Runtimes/Resync.cmake index d9f474005986f..21b67ab0c7b6f 100644 --- a/Runtimes/Resync.cmake +++ b/Runtimes/Resync.cmake @@ -8,39 +8,21 @@ cmake_minimum_required(VERSION 3.21) # Where the standard library lives today set(StdlibSources "${CMAKE_CURRENT_LIST_DIR}/../stdlib") -message(STATUS "Source dir: ${StdlibSources}") - -# Copy the files under the "name" directory in the standard library into the new -# location under Runtimes -function(copy_library_sources name from_prefix to_prefix) - message(STATUS "${name}[${StdlibSources}/${from_prefix}/${name}] -> ${to_prefix}/${name} ") +# Copy a list of files +function(copy_files from_prefix to_prefix) + cmake_parse_arguments(ARG "" "ROOT" "FILES" ${ARGN}) + if(NOT ARG_ROOT) + set(ARG_ROOT ${StdlibSources}) + endif() set(full_to_prefix "${CMAKE_CURRENT_LIST_DIR}/${to_prefix}") - file(GLOB_RECURSE filenames - FOLLOW_SYMLINKS - LIST_DIRECTORIES FALSE - RELATIVE "${StdlibSources}/${from_prefix}" - "${StdlibSources}/${from_prefix}/${name}/*.swift" - "${StdlibSources}/${from_prefix}/${name}/*.h" - "${StdlibSources}/${from_prefix}/${name}/*.cpp" - "${StdlibSources}/${from_prefix}/${name}/*.c" - "${StdlibSources}/${from_prefix}/${name}/*.mm" - "${StdlibSources}/${from_prefix}/${name}/*.m" - "${StdlibSources}/${from_prefix}/${name}/*.def" - "${StdlibSources}/${from_prefix}/${name}/*.gyb" - "${StdlibSources}/${from_prefix}/${name}/*.apinotes" - "${StdlibSources}/${from_prefix}/${name}/*.yaml" - "${StdlibSources}/${from_prefix}/${name}/*.inc" - "${StdlibSources}/${from_prefix}/${name}/*.modulemap" - "${StdlibSources}/${from_prefix}/${name}/*.json") - - foreach(file ${filenames}) + foreach(file ${ARG_FILES}) # Get and create the directory get_filename_component(dirname ${file} DIRECTORY) file(MAKE_DIRECTORY "${full_to_prefix}/${dirname}") file(COPY_FILE - "${StdlibSources}/${from_prefix}/${file}" # From + "${ARG_ROOT}/${from_prefix}/${file}" # From "${full_to_prefix}/${file}" # To RESULT _output ONLY_IF_DIFFERENT) @@ -51,6 +33,42 @@ function(copy_library_sources name from_prefix to_prefix) endforeach() endfunction() +# Copy the files under the "name" directory in the standard library into the new +# location under Runtimes +function(copy_library_sources name from_prefix to_prefix) + cmake_parse_arguments(ARG "" "ROOT" "" ${ARGN}) + + if(NOT ARG_ROOT) + set(ARG_ROOT ${StdlibSources}) + endif() + + message(STATUS "${name}[${ARG_ROOT}/${from_prefix}/${name}] -> ${to_prefix}/${name} ") + + set(full_to_prefix "${CMAKE_CURRENT_LIST_DIR}/${to_prefix}") + + file(GLOB_RECURSE filenames + FOLLOW_SYMLINKS + LIST_DIRECTORIES FALSE + RELATIVE "${ARG_ROOT}/${from_prefix}" + "${ARG_ROOT}/${from_prefix}/${name}/*.swift" + "${ARG_ROOT}/${from_prefix}/${name}/*.h" + "${ARG_ROOT}/${from_prefix}/${name}/*.cpp" + "${ARG_ROOT}/${from_prefix}/${name}/*.c" + "${ARG_ROOT}/${from_prefix}/${name}/*.mm" + "${ARG_ROOT}/${from_prefix}/${name}/*.m" + "${ARG_ROOT}/${from_prefix}/${name}/*.def" + "${ARG_ROOT}/${from_prefix}/${name}/*.gyb" + "${ARG_ROOT}/${from_prefix}/${name}/*.apinotes" + "${ARG_ROOT}/${from_prefix}/${name}/*.yaml" + "${ARG_ROOT}/${from_prefix}/${name}/*.inc" + "${ARG_ROOT}/${from_prefix}/${name}/*.modulemap" + "${ARG_ROOT}/${from_prefix}/${name}/*.json") + + copy_files("${from_prefix}" "${to_prefix}" + ROOT "${ARG_ROOT}" + FILES ${filenames}) +endfunction() + # Directories in the existing standard library that make up the Core project # Copy shared core headers From 960779f5561e93880105d761219ce91494358295 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Tue, 18 Mar 2025 16:31:19 -0700 Subject: [PATCH 2/2] Fold individual file copies into copy_files Use the new copy_files to copy specific files into the appropriate places without needing to duplicate as much code. --- Runtimes/Resync.cmake | 106 ++++++++++-------------------------------- 1 file changed, 24 insertions(+), 82 deletions(-) diff --git a/Runtimes/Resync.cmake b/Runtimes/Resync.cmake index 21b67ab0c7b6f..ce5fb5f1709b3 100644 --- a/Runtimes/Resync.cmake +++ b/Runtimes/Resync.cmake @@ -28,7 +28,7 @@ function(copy_files from_prefix to_prefix) ONLY_IF_DIFFERENT) if(_output) message(SEND_ERROR - "Copy ${from_prefix}/${file} -> ${full_to_prefix}/${file} Failed: ${_output}") + "Copy ${ARG_ROOT}/${from_prefix}/${file} -> ${full_to_prefix}/${file} Failed: ${_output}") endif() endforeach() endfunction() @@ -77,63 +77,6 @@ copy_library_sources(include "" "Core") # Copy magic linker symbols copy_library_sources("linker-support" "" "Core") -# Copy Plist -message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in") -file(COPY_FILE - "${StdlibSources}/Info.plist.in" # From - "${CMAKE_CURRENT_LIST_DIR}/Core/Info.plist.in" # To - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy ${StdlibSources}/Info.plist.in] -> Core/Info.plist.in Failed: ${_output}") -endif() - -# Copy Windows clang overlays -message(STATUS "modulemap[${StdlibSources}/Windows/ucrt.modulemap] -> Overlay/Windows/clang") -file(COPY_FILE - "${StdlibSources}/public/Platform/ucrt.modulemap" # From - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/ucrt.modulemap" # To - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy ${StdlibSources}/public/Platform/ucrt.modulemap -> Overlay/Windows/clang/ucrt.modulemap Failed: ${_output}") -endif() - -message(STATUS "modulemap[${StdlibSources}/Windows/winsdk.modulemap] -> Overlay/Windows/clang") -file(COPY_FILE - "${StdlibSources}/public/Platform/winsdk.modulemap" # From - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/winsdk.modulemap" # To - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy ${StdlibSources}/public/Platform/winsdk.modulemap -> Overlay/Windows/clang/winsdk.modulemap Failed: ${_output}") -endif() - -message(STATUS "modulemap[${StdlibSources}/Windows/vcruntime.modulemap] -> Overlay/Windows/clang") -file(COPY_FILE - "${StdlibSources}/public/Platform/vcruntime.modulemap" # From - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/vcruntime.modulemap" # To - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy ${StdlibSources}/public/Platform/vcruntime.modulemap -> Overlay/Windows/clang/vcruntime.modulemap Failed: ${_output}") -endif() - -message(STATUS "APINotes[${StdlibSources}/Windows/vcruntime.apinotes] -> Overlay/Windows/clang") -file(COPY_FILE - "${StdlibSources}/public/Platform/vcruntime.apinotes" # From - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/vcruntime.apinotes" # To - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy ${StdlibSources}/public/Platform/vcruntime.apinotes -> Overlay/Windows/clang/vcruntime.modulemap Failed: ${_output}") -endif() - set(CoreLibs LLVMSupport SwiftShims @@ -146,36 +89,35 @@ set(CoreLibs Concurrency Concurrency/InternalShims) - # Add these as we get them building - # Demangling - foreach(library ${CoreLibs}) copy_library_sources(${library} "public" "Core") endforeach() -message(STATUS "CRT[${StdlibSources}/public/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT") -foreach(file ucrt.swift Platform.swift POSIXError.swift TiocConstants.swift tgmath.swift.gyb) - file(COPY_FILE - "${StdlibSources}/public/Platform/${file}" - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT/${file}" - RESULT _output - ONLY_IF_DIFFERENT) - if(_output) - message(SEND_ERROR - "Copy Platform/${file} -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT/${file} Failed: ${_output}") - endif() -endforeach() +message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in") +copy_files("" "Core" FILES "Info.plist.in") + +# Platform Overlays +# Windows Overlay message(STATUS "WinSDK[${StdlibSources}/public/Windows] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK") -file(COPY_FILE - "${StdlibSources}/public/Windows/WinSDK.swift" - "${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK/WinSDK.swift" - RESULT _output - ONLY_IF_DIFFERENT) -if(_output) - message(SEND_ERROR - "Copy Windows/WinSDK.swift -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK/WinSDK.swift Failed: ${_output}") -endif() +copy_files(public/Windows Overlay/Windows/WinSDK FILES WinSDK.swift) + +message(STATUS "Windows Modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang") +copy_files(public/Platform Overlay/Windows/clang + FILES + ucrt.modulemap + winsdk.modulemap + vcruntime.modulemap + vcruntime.apinotes) + +message(STATUS "CRT[${StdlibSources}/public/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT") +copy_files(public/Platform Overlay/Windows/CRT + FILES + ucrt.swift + Platform.swift + POSIXError.swift + TiocConstants.swift + tgmath.swift.gyb) # TODO: Add source directories for the platform overlays, supplemental # libraries, and test support libraries.