Skip to content

Commit 6b45ad4

Browse files
committed
[PackageLoading] Allow using Foundation in PackageDescription
This will add the arguments that are required to import Foundation in PackageDescription library when bootstrapping on the CI. It should be now possible to use Codable for generating JSON in the runtime libraries. <rdar://problem/45975602> Allow importing Foundation in the PackageDescription library
1 parent 87d81d7 commit 6b45ad4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
317317
#endif
318318
cmd += [resources.swiftCompiler.asString]
319319
cmd += ["--driver-mode=swift"]
320+
cmd += bootstrapArgs()
320321
cmd += verbosity.ccArgs
321322
cmd += ["-L", runtimePath, "-lPackageDescription"]
322323
cmd += interpreterFlags
@@ -347,6 +348,36 @@ public final class ManifestLoader: ManifestLoaderProtocol {
347348
return json
348349
}
349350

351+
/// Returns the extra manifest args required during SwiftPM's own bootstrap.
352+
private func bootstrapArgs() -> [String] {
353+
#if !os(Linux)
354+
return []
355+
#else
356+
// The Linux bots require extra arguments in order to locate the corelibs.
357+
// We can potentially drop this by installing some stable linux toolchain
358+
// after Swift gets ABI and module stability.
359+
//
360+
// Compute if SwiftPM is bootstrapping.
361+
let env = ProcessInfo.processInfo.environment
362+
guard env.keys.contains("SWIFTPM_BOOTSTRAP") else { return [] }
363+
guard let buildPathStr = env["SWIFTPM_BUILD_DIR"], let buildPath = try? AbsolutePath(validating: buildPathStr) else {
364+
return []
365+
}
366+
367+
// Construct the required search paths relative to the build directory.
368+
let libdir = buildPath.appending(RelativePath(".bootstrap/lib/swift/linux"))
369+
let incdir = libdir.appending(component: "x86_64")
370+
let dispatchIncdir = incdir.appending(component: "dispatch")
371+
372+
return [
373+
"-I" + incdir.asString,
374+
"-I" + dispatchIncdir.asString,
375+
"-L" + libdir.asString,
376+
"-Xcc", "-F" + incdir.asString,
377+
]
378+
#endif
379+
}
380+
350381
/// Returns path to the sdk, if possible.
351382
private func sdkRoot() -> AbsolutePath? {
352383
if let sdkRoot = _sdkRoot {

0 commit comments

Comments
 (0)