libgit2 / objective-git

Objective-C bindings to libgit2
MIT License
1.16k stars 280 forks source link

Build does not include libssh2 with Xcode 7.1 / iOS 9.1 #531

Closed dleehr closed 8 years ago

dleehr commented 8 years ago

I was trying to build a fresh copy of objective-git and found that the iOS build process can no longer find libssh2.

Steps to reproduce:

$ git clone git@github.com:libgit2/objective-git.git
$ cd objective-git/
$ script/bootstrap 
$ open ObjectiveGitFramework.xcodeproj

In Xcode 7.1, pick ObjectiveGit-iOS for iPhone 6 Simulator and build. Upon completion:

$ grep -i ssh2 External/libgit2-ios/*/*.log

External/libgit2-ios/iphoneos9.1-arm64.sdk/build-libgit2.log:-- checking for module 'libssh2'
External/libgit2-ios/iphoneos9.1-arm64.sdk/build-libgit2.log:--   package 'libssh2' not found
External/libgit2-ios/iphoneos9.1-arm64.sdk/build-libgit2.log:-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.

Not sure what caused this to happen, could be Xcode 7 or iOS 9 related. I had a build under iOS 8 SDK that worked fine.

dleehr commented 8 years ago

I found a working build for iOS 9.0 on Sept 16, but I don't know what version exactly I had checked out when I built it:

-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/usr/lib/libz.dylib (found version "1.2.5") 
-- checking for module 'libssh2'
--   found libssh2, version 1.4.3
-- Looking for libssh2_userauth_publickey_frommemory in ssh2
-- Looking for libssh2_userauth_publickey_frommemory in ssh2 - not found
dleehr commented 8 years ago

After some digging, this is certainly related to my homebrew copy of libssh2. When update_libgit2_ios runs, cmake does not use the locally-built iOS copy of libssh2 - it finds the version I have in /usr/local/opt

I uninstalled libssh2 and re-installed it with homebrew, now update_libgit2_ios succeeds, but it reports version 1.6.0 and 1.4.3 is the version used by the submodule.

So I suppose the issue here is to update the update_libgit2_ios build script, but I don't know what to change.

phatblat commented 8 years ago

I'll look into this. I'm guessing the new tvOS platform is breaking an assumption in those fragile build scripts

dleehr commented 8 years ago

I feel like it's got something to do with this:

https://github.com/libgit2/libgit2/blob/c27b4afcdd80f5a45d7120044bf3d78272181abb/CMakeLists.txt#L279

The PKG_CHECK_MODULES CMake function is for finding pkg-config packages, but the library in External/libssh2-ios/lib doesn't have a pkgconfig dir or .pc file. The SDK and arch-specific ones in External/libssh2-ios/bin/iphoneos8.1-arm64.sdk/lib/does.

If there's an easy way to include that path before running CMake, that could help. I just don't know enough about pkg-config or CMake to know how this should fit together.

phatblat commented 8 years ago

Ah, I think you're onto something. I'm also seeing libssh2 version 1.6.0 pulled in from homebrew's install.

The update_libgit2_ios script does have LIBSSH2_INCLUDE_DIRS pointed at the libssh2-ios dir, but perhaps it needs to be pointed to the arch-specific subdir that contains the pkgconfig info.

dleehr commented 8 years ago

I just realized that the script/bootstrap script installs libssh2 onto my mac homebrew, which probably masks this problem most of the time. Some other info:

  1. The LIBSSH2_INCLUDE_DIRS variable isn't used until after libssh2 is found by CMake. If CMake fails to find libssh2, it builds libgit2 without ssh and reports that the user supplied LIBSSH2_INCLUDE_DIRS variable was not used. So, changing the LIBSSH2_INCLUDE_DIRS path will not fix this problem - it's only observed after LIBSSH2 is found in the first place
  2. CMake finds libssh2 for the mac installed by homebrew, that's enough to enable it for the rest of the build process, where it does link with the iOS static library. So this probably ends up working in most cases (because you need a mac to build for ios, and the bootstrap script installs libssh2). Messy though.
  3. I've tried to set PKG_CONFIG_PATH to the directory with the iOS pkgconfig files, but CMake doesn't seem to find them.
phatblat commented 8 years ago

This has been driving me nuts. Everything I try seems to make no difference. However, I just ran across PKG_CONFIG_USE_CMAKE_PREFIX_PATH which is making PKG_CHECK_MODULES actually pay attention to CMAKE_PREFIX_PATH

-- checking for module 'libssh2'
--   found libssh2, version 1.4.3_DEV
-- Looking for libssh2_userauth_publickey_frommemory in ssh2
-- Looking for libssh2_userauth_publickey_frommemory in ssh2 - not found

Fix incoming, then we can deal with the fact that iOS is using a 2 year old version of libssh2.

dleehr commented 8 years ago

If its any consolation, this was driving me nuts too. I tried a bunch of stuff and kept running into the same walls. Hoped the fix would be obvious to someone who'd worked with that build script before. Thanks for digging in!

phatblat commented 8 years ago

@dleehr Thanks for your research as well!

Would you mind testing out the changes I made in #533? I tested both with libssh2 uninstalled and installed through homebrew and according to the logs it picked up the correct (old) version.