Skip to content

Commit e062f52

Browse files
committed
stdlib: remove VS injection for Swift development
Inject the necessary module maps and apinotes via the VFS. This cleans up the developer build in preparation for a secondary change to remove this need for deployed scenarios as well. Injecting the content via the VFS will enable us restore the ability to work with a pristine installation of Visual Studio, dropping the custom action for the Swift installer, and open the pathway to per-user installation of Swift. Use the development path as a high pass filter to identify issues that might come from this injection. This identified a potential issue due to case sensitivity and areas that would break down under tests.
1 parent fedf86f commit e062f52

File tree

6 files changed

+72
-37
lines changed

6 files changed

+72
-37
lines changed

stdlib/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ else()
2424
set(SWIFT_BUILD_TEST_SUPPORT_MODULES_default FALSE)
2525
endif()
2626

27+
# TODO(compnerd) use a target to avoid re-creating this file all the time
28+
function(generate_windows_vfs_overlay)
29+
file(TO_CMAKE_PATH ${VCToolsInstallDir} VCToolsInstallDir)
30+
file(TO_CMAKE_PATH ${UniversalCRTSdkDir} UniversalCRTSdkDir)
31+
configure_file("${PROJECT_SOURCE_DIR}/cmake/WindowsVFS.yaml.in"
32+
"${CMAKE_CURRENT_BINARY_DIR}/windows-vfs-overlay.yaml"
33+
@ONLY)
34+
endfunction()
35+
generate_windows_vfs_overlay()
36+
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/windows-vfs-overlay.yaml"
37+
SWIFT_WINDOWS_VFS_OVERLAY)
38+
2739
#
2840
# User-configurable options for the standard library.
2941
#

stdlib/cmake/WindowsVFS.yaml.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
version: 0
3+
case-sensitive: false
4+
use-external-names: false
5+
roots:
6+
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\um"
7+
type: directory
8+
contents:
9+
- name: module.modulemap
10+
type: file
11+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk.modulemap"
12+
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\ucrt"
13+
type: directory
14+
contents:
15+
- name: module.modulemap
16+
type: file
17+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\ucrt.modulemap"
18+
- name: "@VCToolsInstallDir@\\include"
19+
type: directory
20+
contents:
21+
- name: module.modulemap
22+
type: file
23+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\vcruntime.modulemap"
24+
- name: vcruntime.apinotes
25+
type: file
26+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\vcruntime.apinotes"
27+

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ function(add_swift_target_library_single target name)
875875
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS
876876
-Xcc;-Xclang;-Xcc;-ivfsoverlay;-Xcc;-Xclang;-Xcc;${SWIFTLIB_SINGLE_VFS_OVERLAY})
877877
endif()
878+
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS
879+
-Xcc;-ivfsoverlay;-Xcc;"${SWIFT_WINDOWS_VFS_OVERLAY}")
878880
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
879881
foreach(directory ${SWIFTLIB_INCLUDE})
880882
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-isystem;-Xcc;${directory})

test/lit.cfg

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ if test_resource_dir:
364364
config.resource_dir_opt = ("-resource-dir %s" % test_resource_dir)
365365
else:
366366
test_resource_dir = make_path(config.swift_lib_dir, 'swift')
367+
config.swift_system_overlay_opt = ""
368+
config.clang_system_overlay_opt = ""
369+
if kIsWindows:
370+
config.swift_system_overlay_opt = "-vfsoverlay {}".format(
371+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
372+
)
373+
config.clang_system_overlay_opt = "-Xcc -ivfsoverlay -Xcc {}".format(
374+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
375+
)
367376
stdlib_resource_dir_opt = config.resource_dir_opt
368377
sourcekitd_framework_dir = config.swift_lib_dir
369378
config.substitutions.append( ('%test-resource-dir', test_resource_dir) )
@@ -1355,20 +1364,22 @@ elif run_os in ['windows-msvc']:
13551364
config.target_env_prefix = ''
13561365

13571366
config.target_build_swift = \
1358-
('%r -target %s %s %s %s %s -libc %s' % \
1359-
(config.swiftc, config.variant_triple, config.resource_dir_opt, \
1367+
('%r -target %s %s %s %s %s %s -libc %s' % \
1368+
(config.swiftc, config.variant_triple, \
1369+
config.resource_dir_opt, config.swift_system_overlay_opt, \
13601370
config.swift_test_options, config.swift_driver_test_options,\
13611371
swift_execution_tests_extra_flags, \
13621372
config.swift_stdlib_msvc_runtime))
13631373

13641374
config.target_run = ''
13651375

13661376
config.target_swift_frontend = \
1367-
('%r -target %s %s %s %s %s' % (config.swift_frontend, \
1368-
config.variant_triple, \
1369-
config.resource_dir_opt, mcp_opt, \
1370-
config.swift_test_options, \
1371-
config.swift_frontend_test_options))
1377+
('%r -target %s %s %s %s %s %s' % (config.swift_frontend, \
1378+
config.variant_triple, \
1379+
config.resource_dir_opt, mcp_opt, \
1380+
config.swift_system_overlay_opt, \
1381+
config.swift_test_options, \
1382+
config.swift_frontend_test_options))
13721383

13731384
config.target_codesign = 'echo'
13741385

@@ -1387,9 +1398,11 @@ elif run_os in ['windows-msvc']:
13871398
('%r -libpath:%s' % (config.link, os.path.join(test_resource_dir, \
13881399
config.target_sdk_name)))
13891400
config.target_sil_opt = \
1390-
('%r -target %s %s %s %s' % (config.sil_opt, config.variant_triple, \
1391-
config.resource_dir_opt, mcp_opt, \
1392-
config.sil_test_options))
1401+
('%r -target %s %s %s %s %s' % (config.sil_opt, \
1402+
config.variant_triple, \
1403+
config.resource_dir_opt, mcp_opt, \
1404+
config.swift_system_overlay_opt, \
1405+
config.sil_test_options))
13931406
subst_target_sil_opt_mock_sdk = config.target_sil_opt
13941407
subst_target_sil_opt_mock_sdk_after = ''
13951408
config.target_swift_symbolgraph_extract = \
@@ -1409,9 +1422,10 @@ elif run_os in ['windows-msvc']:
14091422
subst_target_swift_ide_test_mock_sdk_after = ''
14101423

14111424
config.target_swiftc_driver = \
1412-
('%r -target %s %s %s %s' % (config.swiftc, config.variant_triple, \
1413-
config.resource_dir_opt, mcp_opt, \
1414-
config.swift_driver_test_options))
1425+
('%r -target %s %s %s %s %s' % (config.swiftc, config.variant_triple,\
1426+
config.resource_dir_opt, mcp_opt, \
1427+
config.swift_system_overlay_opt, \
1428+
config.swift_driver_test_options))
14151429
config.target_swift_modulewrap = \
14161430
('%r -modulewrap -target %s' % (config.swiftc, config.variant_triple))
14171431
config.target_swift_emit_pcm = \
@@ -2416,7 +2430,10 @@ config.substitutions.append(('%target-swift-ide-test\(mock-sdk:([^)]+)\)',
24162430
escape_for_substitute_captures(subst_target_swift_ide_test_mock_sdk),
24172431
escape_for_substitute_captures(subst_target_swift_ide_test_mock_sdk_after),
24182432
escape_for_substitute_captures(swift_version)))))
2419-
config.substitutions.append(('%target-swift-ide-test', "%s -swift-version %s" % (config.target_swift_ide_test, swift_version)))
2433+
config.substitutions.append(('%target-swift-ide-test',
2434+
"%s -swift-version %s %s" % (config.target_swift_ide_test,
2435+
swift_version,
2436+
config.clang_system_overlay_opt)))
24202437

24212438
config.substitutions.append(('%target-swift-symbolgraph-extract', config.target_swift_symbolgraph_extract))
24222439
config.substitutions.append(('%target-swift-api-extract', config.target_swift_api_extract))

utils/build-windows-toolchain.bat

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ cmake ^
178178
cmake --build "%BuildRoot%\curl" || (exit /b)
179179
cmake --build "%BuildRoot%\curl" --target install || (exit /b)
180180

181-
:: Prepare system modules
182-
copy /y "%SourceRoot%\swift\stdlib\public\Platform\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" || (exit /b)
183-
copy /y "%SourceRoot%\swift\stdlib\public\Platform\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" || (exit /b)
184-
copy /y "%SourceRoot%\swift\stdlib\public\Platform\vcruntime.modulemap" "%VCToolsInstallDir%\include\module.modulemap" || (exit /b)
185-
copy /y "%SourceRoot%\swift\stdlib\public\Platform\vcruntime.apinotes" "%VCToolsInstallDir%\include\vcruntime.apinotes" || (exit /b)
186-
187181
:: Build Toolchain
188182
cmake ^
189183
-B "%BuildRoot%\1" ^

utils/build-windows.bat

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ path %PATH%;%install_directory%\bin
7878

7979
call :build_cmark %exitOnError%
8080

81-
call :prepare_platform_modules %exitOnError%
8281
call :build_swift %exitOnError%
8382

8483
call :build_lldb %exitOnError%
@@ -160,22 +159,6 @@ curl -L -O "https://www.sqlite.org/2021/%file_name%" %exitOnError%
160159
goto :eof
161160
endlocal
162161

163-
164-
:prepare_platform_modules
165-
:: Create files into the right places of the Windows SDK to the files in the
166-
:: swift repository, in order to consider the headers of the Windows SDK a
167-
:: module to compile Swift code against them.
168-
setlocal enableextensions enabledelayedexpansion
169-
170-
copy /y "%source_root%\swift\stdlib\public\Platform\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" %exitOnError%
171-
copy /y "%source_root%\swift\stdlib\public\Platform\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" %exitOnError%
172-
copy /y "%source_root%\swift\stdlib\public\Platform\vcruntime.modulemap" "%VCToolsInstallDir%\include\module.modulemap" %exitOnError%
173-
copy /y "%source_root%\swift\stdlib\public\Platform\vcruntime.apinotes" "%VCToolsInstallDir%\include\vcruntime.apinotes" %exitOnError%
174-
175-
goto :eof
176-
endlocal
177-
178-
179162
:build_llvm
180163
:: Configures, builds, and installs LLVM
181164
setlocal enableextensions enabledelayedexpansion

0 commit comments

Comments
 (0)