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

[Xcodeproj] Avoid generating module.modulemap if umbrella header exists, on creating Clang Module targets #1406

Conversation

norio-nomura
Copy link
Contributor

This was rewritten #955 for master.


This PR increases the portability of generated Xcode project by reducing the use of module.modulemap which absolute path contains.

  • If clang module has umbrella header:
    • Add headers to HeadersBuildPhase
    • Set CLANG_ENABLE_MODULES = YES
    • Set DEFINES_MODULE = YES
    • Don’t generate module.modulemap
  • Set CLANG_ENABLE_MODULES = YES to test target so that we can import clang module.

In the course of testing to create a package written only in Objective-C, I came up with this change.
e.g: https://github.com/norio-nomura/GTMNSString_HTML

…ating the clangModule target

If clang module has umbrella header:
- Add headers to `HeadersBuildPhase`
- Set CLANG_ENABLE_MODULES = YES
- Set DEFINES_MODULE = YES
- Don’t generate `module.modulemap`
`Xcode.BuildFile.Settings` and` Xcode.BuildSettingsTable.BuildSettings` conform to that.
@aciidgh
Copy link
Contributor

aciidgh commented Dec 1, 2017

This looks fine to me but I am not completely sure if there would be any unexpected fallout from this.

@ddunbar @abertelrud Can you guys review this patch?

isGenerated = true
let umbrellaHeaderName = clangTarget.c99name + ".h"
if includeGroup.subitems.contains(where: { $0.path == umbrellaHeaderName }) {
// if umbrellaHeader exists, we can use module.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say something like:

// If an umbrella header exists, enable Xcode's builtin module's feature rather than generating
// a custom module map. This increases the compatibility of generated Xcode projects.

Copy link
Contributor

Choose a reason for hiding this comment

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

That said...

Why can't we always generate a module.modulemap file, and then set the MODULEMAP_FILE build setting to point at it. That should let Xcode's builtin logic work, but can work universally without needing the else branch here.

@ddunbar
Copy link
Contributor

ddunbar commented Dec 2, 2017

This change seems reasonable to me, but I would prefer if we could always generate a file for MODULEMAP_FILE (I may have gotten the name wrong for this setting) so this works for all frameworks, not just ones with an umbrella header.

@ddunbar
Copy link
Contributor

ddunbar commented Dec 2, 2017

My main concern here is I don't want to land a change which improves compatibility, but only for some targets, and in a way which wouldn't be discoverable to a user.

if includeGroup.subitems.contains(where: { $0.path == umbrellaHeaderName }) {
// If an umbrella header exists, enable Xcode's builtin module's feature rather than generating
// a custom module map. This increases the compatibility of generated Xcode projects.
targetSettings.common.CLANG_ENABLE_MODULES = "YES"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this different from DEFINES_MODULE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Xcode's Quick Help said:

CLANG_ENABLE_MODULES
--
Boolean
Enables the use of modules for system APIs. System headers are imported as semantic modules instead of raw headers. This can result in faster builds and project indexing.

I am setting this by mimicking the framework target settings generated by Xcode.
I do not know if it is essential to set this to YES, but I have never had any troubles with doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know if it is essential to set this to YES,

I confirmed that this setting is required by testing on https://github.com/jpsim/Yams

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah cool. Can you also implement the MODULEMAP_FILE setting that @ddunbar suggested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try.

@norio-nomura
Copy link
Contributor Author

Updated to:

  • Set modulemap to MODULEMAP_FILE if exists or generated
  • Stop using -fmodule-map-file in OTHER_SWIFT_FLAGS
  • Set CLANG_ENABLE_MODULES=YES and DEFINES_MODULE=YES if user provided modulemap does not exist

}
targetSettings.common.CLANG_ENABLE_MODULES = "YES"
targetSettings.common.DEFINES_MODULE = "YES"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not set DEFINES_MODULE=YES if user defined modulemap exists, since I don't know about the issue mentioned in following comment:

            // Disable defines target for clang target because our clang targets are not proper framework targets.
            // Also see: <rdar://problem/29825757> 
            targetSettings.common.DEFINES_MODULE = "NO"

@rehatkathuria
Copy link

Thank you so much for taking the initiative to open up this pull request, @norio-nomura!

Curious to know your thoughts on the request as it sits, @ddunbar.

@ddunbar
Copy link
Contributor

ddunbar commented Jan 4, 2018

Sorry for the very long delay, I am testing and experimenting with this today...

@olbrichj
Copy link

olbrichj commented Feb 5, 2018

Any updates on this?

@aciidgh
Copy link
Contributor

aciidgh commented Jun 12, 2018

Sorry that this PR has been sitting for so long on me. I created a new PR based on @norio-nomura work. Thank you for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants