Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow-up / Making Scipio environment-configurable #154

Merged
merged 10 commits into from
Nov 18, 2024
3 changes: 2 additions & 1 deletion Sources/ScipioKit/Producer/FrameworkProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ struct FrameworkProducer {
let compiler = PIFCompiler(
descriptionPackage: descriptionPackage,
buildOptions: buildOptions,
buildOptionsMatrix: buildOptionsMatrix
buildOptionsMatrix: buildOptionsMatrix,
toolchainEnvironment: toolchainEnvironment
)
try await compiler.createXCFramework(buildProduct: product,
outputDirectory: outputDir,
Expand Down
43 changes: 38 additions & 5 deletions Sources/ScipioKit/Producer/PIF/ToolchainGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ struct ToolchainGenerator {
// Compute common arguments for clang and swift.
var extraCCFlags: [String] = []
var extraSwiftCFlags: [String] = []
let sdkPaths = try SwiftSDK.sdkPlatformFrameworkPaths(environment: [:])
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
let macosSDKPlatformPaths = try await nonCachingSDKPlatformFrameworkPaths()
extraCCFlags += ["-F", macosSDKPlatformPaths.fwk.pathString]
extraSwiftCFlags += ["-F", macosSDKPlatformPaths.fwk.pathString]
extraSwiftCFlags += ["-I", macosSDKPlatformPaths.lib.pathString]
extraSwiftCFlags += ["-L", macosSDKPlatformPaths.lib.pathString]

let buildFlags = BuildFlags(cCompilerFlags: extraCCFlags, swiftCompilerFlags: extraSwiftCFlags)
#if compiler(>=6.0)
Expand Down Expand Up @@ -87,3 +87,36 @@ struct ToolchainGenerator {
#endif
}
}

fileprivate extension ToolchainGenerator {

/// A non-caching environment-aware implementation of `SwiftSDK.sdkPlatformFrameworkPaths`
/// Returns `macosx` sdk platform framework path.
func nonCachingSDKPlatformFrameworkPaths() async throws -> (fwk: AbsolutePath, lib: AbsolutePath) {
Copy link
Contributor Author

@dmhts dmhts Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the PR description, this is just a copy of the existing function without the path-caching part.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you note this context in the comment?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid abbreviations frameworkPath, libPath

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to add a verb to the name. This method executes external commands, so it's not better to name it like a getter.

How about renaming like resolveSDKPlatformFrameworkPaths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid abbreviations frameworkPath, libPath

Sorry, I just copied Apple's implementation one-to-one. Of course, it makes sense. Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming like resolveSDKPlatformFrameworkPaths?

Yes, I also like it. Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you note this context in the comment?

/// A non-caching environment-aware implementation of SwiftSDK.sdkPlatformFrameworkPaths

I believe it's already in the comment above, or did you mean something else?

let platformPath = try await executor.execute(
"/usr/bin/xcrun",
"--sdk",
"macosx",
"--show-sdk-platform-path"
)
.unwrapOutput()
.spm_chomp()

guard !platformPath.isEmpty else {
throw StringError("could not determine SDK platform path")
}

// For XCTest framework.
let fwk = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "Library", "Frameworks"
)

// For XCTest Swift library.
let lib = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "usr", "lib"
)

return (fwk, lib)
}

}
3 changes: 2 additions & 1 deletion Sources/ScipioKit/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public struct Runner {
buildOptionsMatrix: buildOptionsMatrix,
cacheMode: options.cacheMode,
overwrite: options.overwrite,
outputDir: outputDir
outputDir: outputDir,
toolchainEnvironment: options.toolchainEnvironment
)
do {
try await producer.produce()
Expand Down