Skip to content

Conversation

@amackworth
Copy link

Well, after a lot of wrangling with Xcode 6, it appears I have finally figured out how to generate ObjectiveGit as a module for use with Swift and Objective-C. 🎉 🎊

Note: 3rd party modules are a new feature in clang. Although beneficial but not necessary for Objective-C, they are required if a framework is to be imported into Swift.

To import the module into a new Xcode project, in addition to the changes made below, the following steps need to be taken each time:

  • Add the repo as a git submodule (e.g. at External/ObjectiveGit), checkout the Swift branch, and runscript/bootstrap.
  • DragObjectiveGitFramework.xcodeprojinto the project navigator.
  • Set the Swift compiler import path build setting to External/ObjectiveGit (or wherever ObjectiveGit is located).
  • Set the Allow Non-Modular Includes in Frameworks build setting to YES.
  • Add a new Copy Files build phase, set the destination to Frameworks, and add ObjectiveGit.framework to that. (Due to the new module structure, you no longer need to set it as a target dependency or link it to your project.)
  • Set the Header Search Paths build setting to the correct path for the libgit2 headers in your project. For example, if you added the submodule to your project as External/ObjectiveGit, you would set this build setting to External/ObjectiveGit/External/libgit2/include. If you see build errors saying that git2/filter.h cannot be found, then double-check that you set this setting correctly.
  • Import the module just like any other: import ObjectiveGit in Swift or @import ObjectiveGit; in Objective-C.

And you should be off and running!

Note: This is my first pull request to ObjectiveGit, so please suggest any dumb mistakes or changes to make it match the structure and style of the project. Thanks!

jspahrsummers and others added 6 commits August 1, 2014 14:43
Added success and error information to -[GTIndex clear:]
Removed libz from linked libraries to prevent a warning in Xcode 6 when compiling ObjectiveGit-ios (static libraries can't link to dynamic libraries).
@jspahrsummers jspahrsummers self-assigned this Aug 7, 2014
@jspahrsummers
Copy link
Contributor

Thanks for submitting this, and sorry for the delay in responding to it!

I think we can get a lot of these build settings for free by updating the External/Configuration submodule to the latest version of jspahrsummers/xcconfigs, since there were recently some changes to enable modules by default.

Would you mind trying that out? 🙇

@amackworth
Copy link
Author

It seems that the updated xcconfigs does provide most of the correct settings. However, it does not enable CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES, which is required for ObjectiveGit to compile. I'm not sure whether this should be changed in jspahrsummers/xcconfigs, or just be kept as a custom setting for this project.

Also, the last three commits (adding the module.modulemap file and including Foundation in ObjectiveGit.h) still appear to be necessary for the project to build.

Let me know if I should do anything further. Thanks for the help! ✨

@jspahrsummers
Copy link
Contributor

CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES should be ObjectiveGit-specific, because I think it's only an issue due to our imports of libgit2—which isn't a module, of course.

I'm not sure why the module map would be required, since I was able to turn other (admittedly less complex) frameworks into modules without doing that, but I have no idea what we'd have to do to omit it.

Have you been testing with the Mac or iOS target? The Mac build seems to fail after these changes, though the iOS one compiled successfully for me.

@amackworth
Copy link
Author

Hmm...that's really odd, since I've only been testing the Mac target. I also just tried a clean build, and that seemed to work successfully.

What kind of errors are you seeing?

@jspahrsummers
Copy link
Contributor

First, there's a bizarre error compiling Specta:

/Users/justin/GitHub/Mac/External/ObjectiveGit/ObjectiveGitTests/specta/src/Specta-Prefix.pch:3:11: fatal error: 'XCTest/XCTest.h' file not found
#  import <XCTest/XCTest.h>
          ^
1 error generated.

This seems more pertinent, though:

<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/cred_helpers.h' [-Werror,-Wincomplete-umbrella]
#import "/Users/justin/GitHub/Mac/External/ObjectiveGit/Classes/ObjectiveGit.h"
^
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/inttypes.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/odb_backend.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/stdint.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/commit.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/config.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/diff.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/index.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/mempack.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/odb_backend.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/refdb_backend.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/reflog.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/refs.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/sys/repository.h' [-Werror,-Wincomplete-umbrella]
<module-includes>:1:1: error: umbrella header for module 'ObjectiveGit' does not include header '/git2/trace.h' [-Werror,-Wincomplete-umbrella]
15 errors generated.
/Users/justin/GitHub/Mac/External/ObjectiveGit/ObjectiveGitTests/ObjectiveGitTests-Prefix.pch:8:10: fatal error: could not build module 'ObjectiveGit'
        #import <ObjectiveGit/ObjectiveGit.h>
         ~~~~~~~^
16 errors generated.

@amackworth
Copy link
Author

Yeah, Specta has been acting really weird, so I just ended up just temporarily turning it off.

The second set of errors seem to have something to do with the header import paths, but I'm not sure. Sometimes when I get similarly obscure errors, just cleaning and rebuilding the project seems to work for me. (This stuff is really undocumented. 😕 )

I'm heading off to the woods for a week, but I'll try out some more stuff when I get back. Thanks for all the help!

@jspahrsummers
Copy link
Contributor

Superseded by #386.

@amackworth
Copy link
Author

Alright, sounds good. 👌

Thanks for your all your help!

@jspahrsummers
Copy link
Contributor

Actually, I'm not sure this was superseded. I've upgraded ObjectiveGit for Xcode 6, and changed it to a framework on iOS, but it's still not a proper module (because it doesn't include libgit2 within its umbrella properly).

I'll reopen this.

@jspahrsummers jspahrsummers reopened this Oct 28, 2014
@amackworth
Copy link
Author

Cool. 👍

I'll try building it with all the new changes and see what sort of novel errors emerge from the depths of Xcode.

@joshaber
Copy link
Member

Superseded by #424.

@joshaber joshaber closed this Dec 12, 2014
@amackworth
Copy link
Author

Alright. Thanks for all your help, @jspahrsummers!

@jspahrsummers jspahrsummers removed their assignment May 22, 2015
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.

4 participants