Bouke / HAP

Swift implementation of the Homekit Accessory Protocol
https://boukehaarsma.nl/HAP/
MIT License
366 stars 50 forks source link

Can't build on macOS Sierra with Xcode 8 Beta 6 #1

Closed jarrodldavis closed 8 years ago

jarrodldavis commented 8 years ago

I've been trying to build this repo for several days now and even with your updates to support Xcode 8 Beta 6, I'm still getting a lot of build errors.

The first thing I get is a problem with OpenSSL:

Linking ./.build/debug/http-demo
ld: library not found for -lssl
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Then I get hundreds (literally hundreds!) of "redefinition" errors like this:

/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'AppleTextureEncoder'
module AppleTextureEncoder [system] [extern_c] {
       ^
/usr/include/module.modulemap:1:8: note: previously defined here
module AppleTextureEncoder [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:7:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/usr/include/module.modulemap:7:8: note: previously defined here
module Compression [system] [extern_c] {
       ^

Are you building this on macOS Sierra? That's the only reason I can think of that could be drastically different between our environments that could be causing this issue.

jarrodldavis commented 8 years ago

Okay so I've tried on a fresh El Capitan install with Xcode 8 Beta 6 and the necessary Homebrew dependencies (libsodium and openssl) and I'm getting the same errors.

Bouke commented 8 years ago

Swift Package Manager probably cannot find openssl installed by brew. You probably need to force-link openssl with brew:

$ pkg-config --cflags openssl

$ brew link openssl          
Warning: openssl is keg-only and must be linked with --force
Note that doing so can interfere with building software.
$ brew link --force openssl
Linking /usr/local/Cellar/openssl/1.0.2h_1... 1601 symlinks created
$ pkg-config --cflags openssl
-I/usr/local/Cellar/openssl/1.0.2h_1/include

Also verify that libsodium is known to pkg-config:

$ brew install libsodium 
==> Downloading https://homebrew.bintray.com/bottles/libsodium-1.0.10.el_capitan
Already downloaded: /Users/bouke/Library/Caches/Homebrew/libsodium-1.0.10.el_capitan.bottle.tar.gz
==> Pouring libsodium-1.0.10.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libsodium/1.0.10: 67 files, 1.1M
$ pkg-config --cflags libsodium 
-I/usr/local/Cellar/libsodium/1.0.10/include

I intend to include the xcodeproj as well, which comes with already defined search paths for the libraries.

Note that there's an issue with encryption (CryptoSwift) that results in pairings not being able to establish (say ~75% of the time). So if pairing does not succeeds on the first try, try a few times more.

Note 2 this project is in its infancy and is in flux. Feel free to lend a hand.

jarrodldavis commented 8 years ago

Attempting to force link OpenSSL results in this:

Jarrods-MacBook-Pro:HAP jarrodldavis$ brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

And I've tried swift build -Xcc -I/usr/local/opt/openssl/include -Xcc -L/usr/local/opt/openssl/lib to no avail.

Bouke commented 8 years ago

As of https://github.com/Homebrew/brew/pull/597 it's no longer possible to force link openssl. The compiler flags look allright, but are not picked up here as well. We should probably report this issue upstream. Apart from downgrading homebrew or symlinking openssl yourself, I don't know of any workaround for the moment.

jarrodldavis commented 8 years ago

Well I replaced your OpenSSL package with the one provided by IBM, fixed some operator errors in Sources/CryptoSwift/Operators.swift, and used swift build -Xcc -I/usr/local/opt/openssl/include.

It gets all the way to hap-server and then this happens:

Compile Swift Module 'hap_server' (1 sources)
Linking ./.build/debug/hap-server
ld: library not found for -lcrypto for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/jarrodldavis/dev/misc/HAP/.build/debug.yaml
Bouke commented 8 years ago

The issue with using their module is that they don't import crypto.h, so the crypto module isn't available. What I found as a workaround is symlinking the libraries to something on pkg-config's path:

ln -s /usr/local/opt/openssl/lib/pkgconfig/*.pc /usr/local/lib/pkgconfig
jarrodldavis commented 8 years ago

Okay, that works!