Skip to content

Commit 6d93142

Browse files
authored
Merge pull request #2846 from egorzhdan/windows-2
Avoid passing -fPIC compiler argument on Windows
2 parents e100242 + 8fa7f03 commit 6d93142

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Sources/Workspace/Destination.swift

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public struct Destination: Encodable, Equatable {
9797
let binDir = customBinDir ?? binDir ?? Destination.hostBinDir(
9898
originalWorkingDirectory: originalWorkingDirectory)
9999

100-
#if os(macOS)
100+
let sdkPath: AbsolutePath?
101+
#if os(macOS)
101102
// Get the SDK.
102-
let sdkPath: AbsolutePath
103103
if let value = lookupExecutablePath(filename: ProcessEnv.vars["SDKROOT"]) {
104104
sdkPath = value
105105
} else {
@@ -111,35 +111,41 @@ public struct Destination: Encodable, Equatable {
111111
}
112112
sdkPath = AbsolutePath(sdkPathStr)
113113
}
114+
#else
115+
sdkPath = nil
116+
#endif
114117

115118
// Compute common arguments for clang and swift.
116119
var extraCCFlags: [String] = []
117120
var extraSwiftCFlags: [String] = []
121+
#if os(macOS)
118122
if let sdkPaths = Destination.sdkPlatformFrameworkPaths(environment: environment) {
119123
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
120124
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
121125
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
122126
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
123127
}
128+
#endif
129+
130+
#if !os(Windows)
131+
extraCCFlags += ["-fPIC"]
132+
#endif
133+
134+
var extraCPPFlags: [String] = []
135+
#if os(macOS)
136+
extraCPPFlags += ["-lc++"]
137+
#else
138+
extraCPPFlags += ["-lstdc++"]
139+
#endif
124140

125141
return Destination(
126142
target: nil,
127143
sdk: sdkPath,
128144
binDir: binDir,
129145
extraCCFlags: extraCCFlags,
130146
extraSwiftCFlags: extraSwiftCFlags,
131-
extraCPPFlags: ["-lc++"]
132-
)
133-
#else
134-
return Destination(
135-
target: nil,
136-
sdk: nil,
137-
binDir: binDir,
138-
extraCCFlags: ["-fPIC"],
139-
extraSwiftCFlags: [],
140-
extraCPPFlags: ["-lstdc++"]
147+
extraCPPFlags: extraCPPFlags
141148
)
142-
#endif
143149
}
144150

145151
/// Returns macosx sdk platform framework path.

0 commit comments

Comments
 (0)