Skip to content

Commit a81411a

Browse files
authored
Merge pull request swiftlang#78415 from bnbarham/cherry-windows-fixes
[6.1] Cherry-pick various windows build fixes
2 parents 202de3a + c9c71ae commit a81411a

File tree

10 files changed

+131
-41
lines changed

10 files changed

+131
-41
lines changed

CMakeLists.txt

-6
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,6 @@ if (NOT BOOTSTRAPPING_MODE)
950950
message(FATAL_ERROR "turning off bootstrapping is not supported anymore")
951951
endif()
952952

953-
# As a temporary workaround, disable SwiftCompilerSources on
954-
# Windows/ARM64 because the compiler segfaults
955-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
956-
set(BOOTSTRAPPING_MODE "OFF")
957-
endif()
958-
959953
set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
960954
set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
961955
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")

lib/Frontend/ModuleInterfaceBuilder.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
279279
// optimization pipeline.
280280
SerializationOptions SerializationOpts;
281281
std::string OutPathStr = OutputPath.str();
282+
SerializationOpts.StaticLibrary = FEOpts.Static;
282283
SerializationOpts.OutputPath = OutPathStr.c_str();
283284
SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName;
284285
SerializationOpts.AutolinkForceLoad =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name dynamic
3+
4+
import Swift
5+
6+
public func f() {}
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -static -module-name static
3+
4+
import Swift
5+
6+
public func f() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs/SR77756 -c %s -o /dev/null -D STATIC
3+
// RUN: llvm-bcanalyzer -dump %t/mcp/static-*.swiftmodule | %FileCheck %s -check-prefix CHECK-STATIC
4+
// RUN: %target-swift-frontend -module-cache-path %t/mcp -I %S/Inputs/SR77756 -c %s -o /dev/null
5+
// RUN: llvm-bcanalyzer -dump %t/mcp/dynamic-*.swiftmodule | %FileCheck %s -check-prefix CHECK-DYNAMIC
6+
7+
#if STATIC
8+
import `static`
9+
#else
10+
import `dynamic`
11+
#endif
12+
13+
// CHECK-STATIC: IS_STATIC
14+
// CHECK-DYNAMIC-NOT: IS_STATIC

tools/swift-inspect/CMakeLists.txt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
3+
project(swift-inspect
4+
LANGUAGES CXX Swift)
5+
6+
# Set C++ standard
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
11+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
12+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
13+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
14+
15+
find_package(ArgumentParser CONFIG REQUIRED)
16+
17+
add_library(SymbolicationShims INTERFACE)
18+
target_include_directories(SymbolicationShims INTERFACE
19+
Sources/SymbolicationShims)
20+
21+
if(WIN32)
22+
add_library(SwiftInspectClientInterface INTERFACE)
23+
target_include_directories(SwiftInspectClientInterface INTERFACE
24+
Sources/SwiftInspectClientInterface)
25+
26+
add_library(SwiftInspectClient SHARED
27+
Sources/SwiftInspectClient/SwiftInspectClient.cpp)
28+
target_link_libraries(SwiftInspectClient PRIVATE
29+
SwiftInspectClientInterface)
30+
endif()
31+
32+
add_executable(swift-inspect
33+
Sources/swift-inspect/Operations/DumpArray.swift
34+
Sources/swift-inspect/Operations/DumpCacheNodes.swift
35+
Sources/swift-inspect/Operations/DumpConcurrency.swift
36+
Sources/swift-inspect/Operations/DumpConformanceCache.swift
37+
Sources/swift-inspect/Operations/DumpGenericMetadata.swift
38+
Sources/swift-inspect/Operations/DumpRawMetadata.swift
39+
Sources/swift-inspect/Backtrace.swift
40+
Sources/swift-inspect/DarwinRemoteProcess.swift
41+
Sources/swift-inspect/main.swift
42+
Sources/swift-inspect/Process.swift
43+
Sources/swift-inspect/RemoteMirror+Extensions.swift
44+
Sources/swift-inspect/RemoteProcess.swift
45+
Sources/swift-inspect/String+Extensions.swift
46+
Sources/swift-inspect/Symbolication+Extensions.swift
47+
Sources/swift-inspect/WindowsRemoteProcess.swift
48+
Sources/swift-inspect/WinSDK+Extentions.swift)
49+
target_compile_options(swift-inspect PRIVATE
50+
-parse-as-library)
51+
target_link_libraries(swift-inspect PRIVATE
52+
ArgumentParser
53+
swiftRemoteMirror)
54+
if(WIN32)
55+
target_link_libraries(swift-inspect PRIVATE
56+
SwiftInspectClientInterface)
57+
endif()
58+
59+
install(TARGETS swift-inspect
60+
DESTINATION bin)
61+
if(WIN32)
62+
install(TARGETS SwiftInspectClient
63+
RUNTIME DESTINATION bin)
64+
endif()

tools/swift-inspect/Package.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ let package = Package(
2121
.target(name: "SwiftInspectClientInterface", condition: .when(platforms: [.windows])),
2222
],
2323
swiftSettings: [.unsafeFlags(["-parse-as-library"])]),
24-
.target(
25-
name: "SwiftInspectClient",
26-
// Workaround https://github.com/llvm/llvm-project/issues/40056
27-
cxxSettings: [.unsafeFlags(["-Xclang", "-fno-split-cold-code"])]),
24+
.target(name: "SwiftInspectClient"),
2825
.systemLibrary(
2926
name: "SwiftInspectClientInterface"),
3027
.testTarget(

tools/swift-inspect/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ swift-inspect uses the reflection APIs to introspect the live process. It relie
88

99
swift-inspect can be built using [swift-package-manager](https://github.com/swiftlang/swift-package-manager).
1010

11-
##### Windows
11+
#### Windows
1212

1313
In order to build on Windows, some additional parameters must be passed to the build tool to locate the necessary libraries.
1414

1515
~~~
1616
swift build -Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror -Xlinker %SDKROOT%\usr\lib\swift\windows\x86_64\swiftRemoteMirror.lib
1717
~~~
1818

19+
#### CMake
20+
21+
In order to build on Windows with CMake, some additional parameters must be passed to the build tool to locate the necessary Swift modules.
22+
23+
~~~
24+
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror"
25+
~~~
26+
1927
### Using
2028

2129
The following inspection operations are available currently.

tools/swift-inspect/Sources/SwiftInspectClient/SwiftInspectClient.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#if defined(_WIN32)
1414

15+
#if SWIFT_PACKAGE
1516
#pragma comment(lib, "swiftCore.lib")
17+
#endif
1618

1719
#include "../SwiftInspectClientInterface/SwiftInspectClientInterface.h"
1820
#include <assert.h>

utils/build.ps1

+27-30
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ if ($null -eq $BuildArchName) { $BuildArchName = $env:PROCESSOR_ARCHITECTURE }
166166
if ($PinnedBuild -eq "") {
167167
switch ($BuildArchName) {
168168
"AMD64" {
169-
$PinnedBuild = "https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe"
170-
$PinnedSHA256 = "3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286"
171-
$PinnedVersion = "5.10.1"
169+
$PinnedBuild = "https://download.swift.org/swift-6.0.3-release/windows10/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-windows10.exe"
170+
$PinnedSHA256 = "AB205D83A38047882DB80E6A88C7D33B651F3BAC96D4515D7CBA5335F37999D3"
171+
$PinnedVersion = "6.0.3"
172172
}
173173
"ARM64" {
174-
$PinnedBuild = "https://download.swift.org/development/windows10-arm64/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a-windows10-arm64.exe"
175-
$PinnedSHA256 = "037BDBF9D1A1A99D7156584948870A8A958FD27CC4FF5711691CC0A76F2E88F5"
176-
$PinnedVersion = "0.0.0"
174+
$PinnedBuild = "https://download.swift.org/swift-6.0.3-release/windows10-arm64/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-windows10-arm64.exe"
175+
$PinnedSHA256 = "81474651E59A9955C9E6A389EF53ABD61631FFC62C63A2A02977271019E7C722"
176+
$PinnedVersion = "6.0.3"
177177
}
178178
default { throw "Unsupported processor architecture" }
179179
}
@@ -454,6 +454,7 @@ enum HostComponent {
454454
LMDB
455455
SymbolKit
456456
DocC
457+
SwiftInspect
457458
}
458459

459460
function Get-HostProjectBinaryCache([HostComponent]$Project) {
@@ -1182,7 +1183,7 @@ function Build-CMakeProject {
11821183
}
11831184

11841185
if ($UseBuiltCompilers.Contains("Swift")) {
1185-
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
1186+
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;$(Get-PinnedToolchainRuntime);${env:Path}"
11861187
} elseif ($UsePinnedCompilers.Contains("Swift")) {
11871188
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
11881189
}
@@ -1943,7 +1944,7 @@ function Build-FoundationMacros() {
19431944

19441945
$SwiftSDK = $null
19451946
if ($Build) {
1946-
$SwiftSDK = $BuildArch.SDKInstallRoot
1947+
$SwiftSDK = $(Get-PinnedToolchainSDK)
19471948
}
19481949

19491950
$InstallDir = $null
@@ -2579,7 +2580,7 @@ function Build-TestingMacros() {
25792580

25802581
$SwiftSDK = $null
25812582
if ($Build) {
2582-
$SwiftSDK = $BuildArch.SDKInstallRoot
2583+
$SwiftSDK = $(Get-PinnedToolchainSDK)
25832584
}
25842585

25852586
$Targets = if ($Build) {
@@ -2636,18 +2637,19 @@ function Install-HostToolchain() {
26362637
}
26372638

26382639
function Build-Inspect() {
2639-
$OutDir = Join-Path -Path $HostArch.BinaryCache -ChildPath swift-inspect
2640-
$SDKInstallRoot = (Get-HostSwiftSDK) `
2640+
$SDKRoot = Get-HostSwiftSDK
26412641

2642-
Isolate-EnvVars {
2643-
$env:SWIFTCI_USE_LOCAL_DEPS=1
2644-
Build-SPMProject `
2645-
-Action Build `
2646-
-Src $SourceCache\swift\tools\swift-inspect `
2647-
-Bin $OutDir `
2648-
-Arch $HostArch `
2649-
-Xcc "-I$SDKInstallRoot\usr\include\swift\SwiftRemoteMirror" -Xlinker "$SDKInstallRoot\usr\lib\swift\windows\$($HostArch.LLVMName)\swiftRemoteMirror.lib"
2650-
}
2642+
Build-CMakeProject `
2643+
-Src $SourceCache\swift\tools\swift-inspect `
2644+
-Bin (Get-HostProjectBinaryCache SwiftInspect) `
2645+
-InstallTo "$($HostArch.ToolchainInstallRoot)\usr" `
2646+
-Arch $HostArch `
2647+
-UseBuiltCompilers C,CXX,Swift `
2648+
-SwiftSDK $SDKRoot `
2649+
-Defines @{
2650+
CMAKE_Swift_FLAGS = @("-Xcc", "-I$SDKRoot\usr\include\swift\SwiftRemoteMirror");
2651+
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2652+
}
26512653
}
26522654

26532655
function Build-DocC() {
@@ -2686,18 +2688,15 @@ function Test-PackageManager() {
26862688
function Build-Installer($Arch) {
26872689
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
26882690
# when cross-compiling https://github.com/apple/swift/issues/71655
2689-
$INCLUDE_SWIFT_INSPECT = if ($IsCrossCompiling) { "false" } else { "true" }
26902691
$INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling) { "false" } else { "true" }
26912692
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc" -and $Arch -eq $ArchX64) { "true" } else { "false" }
26922693

26932694
$Properties = @{
26942695
BundleFlavor = "offline";
26952696
DEVTOOLS_ROOT = "$($Arch.ToolchainInstallRoot)\";
26962697
TOOLCHAIN_ROOT = "$($Arch.ToolchainInstallRoot)\";
2697-
INCLUDE_SWIFT_INSPECT = $INCLUDE_SWIFT_INSPECT;
2698-
SWIFT_INSPECT_BUILD = "$($Arch.BinaryCache)\swift-inspect\release";
2699-
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
27002698
ENABLE_MIMALLOC = $ENABLE_MIMALLOC;
2699+
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
27012700
SWIFT_DOCC_BUILD = "$($Arch.BinaryCache)\swift-docc\release";
27022701
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
27032702
}
@@ -2712,7 +2711,7 @@ function Build-Installer($Arch) {
27122711
}
27132712

27142713
foreach ($SDK in $WindowsSDKArchs) {
2715-
$Properties["INCLUDE_$($SDK.VSName.ToUpperInvariant())_SDK"] = "true"
2714+
$Properties["INCLUDE_WINDOWS_$($SDK.VSName.ToUpperInvariant())_SDK"] = "true"
27162715
$Properties["PLATFORM_ROOT_$($SDK.VSName.ToUpperInvariant())"] = "$($SDK.PlatformInstallRoot)\"
27172716
$Properties["SDK_ROOT_$($SDK.VSName.ToUpperInvariant())"] = "$($SDK.SDKInstallRoot)\"
27182717
}
@@ -2723,11 +2722,9 @@ function Build-Installer($Arch) {
27232722
function Stage-BuildArtifacts($Arch) {
27242723
Copy-File "$($Arch.BinaryCache)\installer\Release\$($Arch.VSName)\*.cab" "$Stage\"
27252724
Copy-File "$($Arch.BinaryCache)\installer\Release\$($Arch.VSName)\*.msi" "$Stage\"
2726-
Copy-File "$($Arch.BinaryCache)\installer\Release\$($Arch.VSName)\rtl.cab" "$Stage\"
2727-
Copy-File "$($Arch.BinaryCache)\installer\Release\$($Arch.VSName)\rtl.msi" "$Stage\"
27282725
foreach ($SDK in $WindowsSDKArchs) {
2729-
Copy-File "$($Arch.BinaryCache)\installer\Release\$($SDK.VSName)\sdk.$($SDK.VSName).cab" "$Stage\"
2730-
Copy-File "$($Arch.BinaryCache)\installer\Release\$($SDK.VSName)\sdk.$($SDK.VSName).msi" "$Stage\"
2726+
Copy-File "$($Arch.BinaryCache)\installer\Release\$($SDK.VSName)\sdk.windows.$($SDK.VSName).cab" "$Stage\"
2727+
Copy-File "$($Arch.BinaryCache)\installer\Release\$($SDK.VSName)\sdk.windows.$($SDK.VSName).msi" "$Stage\"
27312728
Copy-File "$($Arch.BinaryCache)\installer\Release\$($SDK.VSName)\rtl.$($SDK.VSName).msm" "$Stage\"
27322729
}
27332730
Copy-File "$($Arch.BinaryCache)\installer\Release\$($Arch.VSName)\installer.exe" "$Stage\"
@@ -2845,6 +2842,7 @@ if (-not $SkipBuild) {
28452842
Invoke-BuildStep Build-Format $HostArch
28462843
Invoke-BuildStep Build-IndexStoreDB $HostArch
28472844
Invoke-BuildStep Build-SourceKitLSP $HostArch
2845+
Invoke-BuildStep Build-Inspect $HostArch
28482846
}
28492847

28502848
Install-HostToolchain
@@ -2854,7 +2852,6 @@ if (-not $SkipBuild -and $Allocator -eq "mimalloc") {
28542852
}
28552853

28562854
if (-not $SkipBuild -and -not $IsCrossCompiling) {
2857-
Invoke-BuildStep Build-Inspect $HostArch
28582855
Invoke-BuildStep Build-DocC $HostArch
28592856
}
28602857

0 commit comments

Comments
 (0)