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

Allow declaring modulemap file in Target #1274

Closed
wants to merge 2 commits into from

Conversation

natanrolnik
Copy link
Collaborator

In order to be able to include a Copy Headers build phase including the modulemap and other public headers, which will support .a libraries.

Resolves #1254

Thanks to @pepibumur for guiding me, over the step described in the issue above by @kwridan.

This PR still requires adding tests and in a later stage (or commit) we will add the suggested linting as well.

In order to be able to include a Copy Headers build phase including the modulemap and other public headers, which will support .a libraries.

Thanks to @pepibumur for guiding me!
Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

Nice work @natanrolnik - thanks for tackling this 👍

Left some initial thoughts

@@ -104,7 +109,8 @@ public struct Target: Codable, Equatable {
dependencies: [TargetDependency] = [],
settings: Settings? = nil,
coreDataModels: [CoreDataModel] = [],
environment: [String: String] = [:]) {
environment: [String: String] = [:],
modulemap: Path? = nil) {
Copy link
Collaborator

@kwridan kwridan Apr 27, 2020

Choose a reason for hiding this comment

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

minor:

What is everyones thoughts on moving it to somewhere in the middle (e.g. after entitlements)?

Thinking of how it appears in usage?

let target = Target(
    name: "MyTarget",
    dependencies: [
    // ..
    ],
    modulemap: "path/to/module.modulemap")
let target = Target(
    name: "MyTarget",
    modulemap: "path/to/module.modulemap",
    dependencies: [
    // ..
    ])

if let headers = target.headers {
try generateHeadersBuildPhase(headers: headers,
includePublicFiles: target.modulemap == nil,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm not mistaken the criteria here would be to omit the entire build phase if product == .staticLibrary,

we can introduce a helper in TuistCore/Target along side some of the others there to achieve something along those lines:

if let headers = target.headers, target.supportsHeadersPhase {
   try generateHeadersBuildPhase( ... )
}

pbxTarget: pbxTarget,
fileElements: fileElements,
pbxproj: pbxproj)
}

if let modulemap = target.modulemap {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the criteria for including the generateCopyHeadersBuildPhase is when !target.supportsHeadersPhase.

e.g. A normal .framework allows specifying a modulemap and does not require any special copy, Xcode automatically deals with that.

Comment on lines +212 to +216
if let definesModules = config.buildSettings["DEFINES_MODULE"] {
let message = "The target \(target.name) has DEFINES_MODULE build setting set to "
+ "\"\(definesModules)\" in \(config.name). "
+ "It will be set to \"YES\" because `modulemap` was set in the target to \"\(relativeModulemap)\"."
logger.log(level: .warning, Logger.Message(stringLiteral: message))
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency - we can add this as a lint warning within SettingsLinter for example

Comment on lines +226 to +227
config.buildSettings["DEFINES_MODULE"] = "YES"
config.buildSettings["MODULEMAP_FILE"] = relativeModulemap
Copy link
Collaborator

Choose a reason for hiding this comment

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

Target settings are usually updated in ConfigGenerator.generalTargetDerivedSettings - we can move that there for consistency :)

@@ -128,6 +128,10 @@ class ProjectFileElements {
files.insert(entitlements)
}

if let modulemap = target.modulemap {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 - awesome this means modulemaps will automatically appear in Xcode navigator - no longer need to manually add them to additionalFiles in the manifest! 🎉

@natanrolnik
Copy link
Collaborator Author

I would love to continue this PR. But unfortunately, at the moment, I don't have the capacity to do all the work needed.
An alternative is compiling the target into a framework, xcframework, or library.
Closing this PR for now.

@danieleformichelli danieleformichelli deleted the better-modulemap-support branch July 22, 2021 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When using a .a library, Tuist doesn't copy headers and modulemap files correctly
2 participants