I am looking for reading the build settings of the target in BuildToolPlugin. However I see no relevant APIs offered by Target or SourceModuleTarget that can be used to read these values. I tried using ProcessInfo.processInfo.environment as well but seems like build settings aren’t provided to BuildToolPlugin as environment variables. Is there any other way to access target’s build settings?
No, currently build tool plugins really only support generating source files that feed into the Target build. In that use case, there’s nothing really in the build settings that would be useful, unless I'm missing something.
What build settings were you hoping to use in your plugins? I’ve been wondering if plug-ins themselves could use their own build settings when attached to a target. I’m wondering if that would help your use case.
Thanks for responding @dschaefer2. I have few use-cases I am working on.
First one is distributing iOS application extensions binary dependencies with SPM. Currently SPM only allows distributing library dependencies as binary targets. But for distributing application extensions, there is no SPM support. I was looking into how I can codesign and copy extensions to application and I am able achieve that with Xcode project script phase (which could be used with dependency managers like CocoaPods). But with SPM there seems to be no way to achieve this.
Second one is generating Codable helpers for protocols. Consider this scenario:
// In module A
protocol Base {
}
// In module B
struct Impl1: Base {
}
#if TARGET_B_CONDITION
struct ConditionalImpl1: Base {
}
#endif
// In main target
func decodeBase(from decoder: Decoder) throws -> Base {
// only try to decode ConditionalImpl1 if TARGET_B_CONDITION is enabled in target B's build settings
}
The above scenario is not possible because of this limitation. Few users of my plugin have requested this feature implementation: [Feature Request] No HelperCoder generated when check compilation condition · Issue #82 · SwiftyLab/MetaCodable · GitHub
@dschaefer2 I am able to access build settings from environment variables from my buildCommand executable. However I have few queries regarding resolving the issues I am facing:
- The build tool plugin currently only provides a single working directory. As per the doc, non source files are copied by the build system into the built product bundle. Is there any way tools can create temporary files? i.e. creating and entitlements file to pass to
codesign? (The current workaround is to delete files after being used which might be bad in case the temp files generated require heavy processing) codesignran from build tool command doesn’t seem to have access to keychain to perform signing. Is there any way such access can be provided to the build command?