Skip to content

Commit cc89797

Browse files
jakepetroulesaciidgh
authored andcommitted
Use the correct sysroot spellings on Darwin and Linux
On Apple platforms, Clang accepts -isysroot to indicate the sysroot, while on Linux, it is --sysroot. Similarly, on Apple platforms the environment variable SDKROOT indicates the sysroot, while on Linux it is SYSROOT. rdar://47367002
1 parent ce18acc commit cc89797

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Sources/Workspace/Destination.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public struct Destination {
4646
/// The file extension for dynamic libraries (eg. `.so` or `.dylib`)
4747
public let dynamicLibraryExtension: String
4848

49+
/// The compiler flag for specifying the sysroot (eg. `--sysroot` or `-isysroot`).
50+
public let sysrootFlag: String
51+
4952
/// Additional flags to be passed to the C compiler.
5053
public let extraCCFlags: [String]
5154

@@ -94,7 +97,7 @@ public struct Destination {
9497
#if os(macOS)
9598
// Get the SDK.
9699
let sdkPath: AbsolutePath
97-
if let value = lookupExecutablePath(filename: getenv("SYSROOT")) {
100+
if let value = lookupExecutablePath(filename: getenv("SDKROOT")) {
98101
sdkPath = value
99102
} else {
100103
// No value in env, so search for it.
@@ -115,6 +118,7 @@ public struct Destination {
115118
sdk: sdkPath,
116119
binDir: binDir,
117120
dynamicLibraryExtension: "dylib",
121+
sysrootFlag: "-isysroot",
118122
extraCCFlags: commonArgs,
119123
extraSwiftCFlags: commonArgs,
120124
extraCPPFlags: ["-lc++"]
@@ -125,6 +129,7 @@ public struct Destination {
125129
sdk: .root,
126130
binDir: binDir,
127131
dynamicLibraryExtension: "so",
132+
sysrootFlag: "--sysroot",
128133
extraCCFlags: ["-fPIC"],
129134
extraSwiftCFlags: [],
130135
extraCPPFlags: ["-lstdc++"]
@@ -187,6 +192,7 @@ extension Destination: JSONMappable {
187192
sdk: AbsolutePath(json.get("sdk")),
188193
binDir: AbsolutePath(json.get("toolchain-bin-dir")),
189194
dynamicLibraryExtension: json.get("dynamic-library-extension"),
195+
sysrootFlag: json.get("sysroot-flag"),
190196
extraCCFlags: json.get("extra-cc-flags"),
191197
extraSwiftCFlags: json.get("extra-swiftc-flags"),
192198
extraCPPFlags: json.get("extra-cpp-flags")

Sources/Workspace/UserToolchain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public final class UserToolchain: Toolchain {
233233
] + destination.extraSwiftCFlags
234234

235235
self.extraCCFlags = [
236-
"--sysroot", destination.sdk.asString
236+
destination.sysrootFlag, destination.sdk.asString
237237
] + destination.extraCCFlags
238238

239239
// Compute the path of directory containing the PackageDescription libraries.

Utilities/bootstrap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,10 @@ def main():
12311231
"SWIFTPM_BOOTSTRAP=1",
12321232
]
12331233
if args.sysroot:
1234-
env_cmd.append("SYSROOT=" + args.sysroot)
1234+
if platform.system() == 'Darwin':
1235+
env_cmd.append("SDKROOT=" + args.sysroot)
1236+
else:
1237+
env_cmd.append("SYSROOT=" + args.sysroot)
12351238
cmd = env_cmd + [bootstrapped_product] + build_flags
12361239

12371240
# Always build tests in stage2.

0 commit comments

Comments
 (0)