vapor-community / postgresql

Robust PostgreSQL interface for Swift
MIT License
131 stars 33 forks source link

Update build instructions for Postgres.app #34

Closed rsarwas closed 7 years ago

rsarwas commented 7 years ago

On macosx, it would be nice to use Postgres.app instead of the homebrew postgres (if possible). Please update the readme file to document this alternative

kenaniah commented 7 years ago

IMHO, this project's documentation should not include instructions to install Postgres.app, mainly because homebrew is the de facto package management tool for Mac. I have nothing against Postgres.app, and many developers find it to be a wonderful alternative for installing a PostgreSQL server. I am against this simply because it does not provide any meaningful value over the existing instructions.

regan-sarwas commented 7 years ago

I'm not requesting instruction on the installation of Postgres.app. However I'm using Postgres.app, and I'd rather not migrate to the Brew Postgres just to experiment with Vapor. This is where I got stuck and stopped. I was hoping there were others in my situation that had solved this, but maybe not.

pruthvikar commented 7 years ago

I use Postgres.app and there is no difference when using Vapor. Can you explain where you are hitting a roadblock?

rsarwas commented 7 years ago

@pruthvikar that is good news. Thanks for responding. my problem is error: 'libpq-fe.h' file not found. I suspect there will also be linking errors once this is resolved. It may be because I do not know how to specify the include and lib paths with the swift package manager.

I have postgres.app 2.0.3 (21) and swift 3.1 installed.

$ pg_config --includedir
/Applications/Postgres.app/Contents/Versions/9.6/include
$ pg_config --libdir
/Applications/Postgres.app/Contents/Versions/9.6/lib
$ swift --version
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Target: x86_64-apple-macosx10.9

Reproduce with:

cd /tmp
mkdir Project
cd Project
swift package init --type executable
cat <<EOT > Package.swift
import PackageDescription
let package = Package(
    name: "Project",
    dependencies: [
        .Package(url: "https://github.com/vapor/postgresql.git", majorVersion: 2)
    ]
)
EOT
swift build

Results:

Fetching https://github.com/vapor/postgresql.git
Fetching https://github.com/vapor-community/cpostgresql.git
Fetching https://github.com/vapor/node.git
Fetching https://github.com/vapor/core.git
Fetching https://github.com/vapor/bits.git
Fetching https://github.com/vapor/debugging.git
Cloning https://github.com/vapor/node.git
Resolving https://github.com/vapor/node.git at 2.0.3
Cloning https://github.com/vapor-community/cpostgresql.git
Resolving https://github.com/vapor-community/cpostgresql.git at 2.0.0
Cloning https://github.com/vapor/postgresql.git
Resolving https://github.com/vapor/postgresql.git at 2.0.1
Cloning https://github.com/vapor/core.git
Resolving https://github.com/vapor/core.git at 2.0.2
Cloning https://github.com/vapor/debugging.git
Resolving https://github.com/vapor/debugging.git at 1.0.0
Cloning https://github.com/vapor/bits.git
Resolving https://github.com/vapor/bits.git at 1.0.0
Compile Swift Module 'Debugging' (1 sources)
Compile Swift Module 'Bits' (19 sources)
Compile Swift Module 'libc' (1 sources)
Compile Swift Module 'Core' (23 sources)
Compile Swift Module 'PathIndexable' (2 sources)
Compile Swift Module 'Node' (38 sources)
Compile Swift Module 'PostgreSQL' (12 sources)
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
/private/tmp/Project/.build/checkouts/cpostgresql.git-2801679829006959247/shim.h:4:10: error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
         ^
/private/tmp/Project/.build/checkouts/postgresql.git-5650722971996441103/Sources/PostgreSQL/Connection.swift:1:8: error: could not build Objective-C module 'CPostgreSQL'
import CPostgreSQL
       ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /private/tmp/Project/.build/debug.yaml

libpq-fe.h exists.

$ ls `pg_config --includedir`/libpq-fe.h
/Applications/Postgres.app/Contents/Versions/9.6/include/libpq-fe.h
rsarwas commented 7 years ago

I'm not sure if this is the correct solution, but I was able to get it to compile by creating a pkgConfig file called: /usr/local/lib/pkgconfig/libpq.pc with this content:

prefix=/Applications/Postgres.app/Contents/Versions/latest
Cflags: -I${prefix}/include
Libs: -L${prefix}/lib -lpq

I am closing this issue since it really belongs in the Cpostgres instructions.

natebird commented 7 years ago

I created a pull request on cPostgres for this. Let me know if it looks ok and I'll merge it in.

Thanks for figuring this out.

vzsg commented 7 years ago

I disagree about where it belongs. No one should depend on cpostgresql directly, so I'd rather see it here in the README.

regan-sarwas commented 7 years ago

@natebird the pull request looks good to me. Thanks!

natebird commented 7 years ago

@vzsg I agree that no one should directly depend on the CPostgresql repo. We have a readme for setting up CPosgresql on different environments so I'll add it there but I'll also add a section in this readme about it as well. Does that sound good?

vzsg commented 7 years ago

@natebird Yeah, sounds good. 👍

phawk commented 6 years ago

The pkgconfig worked for me too, I think Postgres.app is a very common way of running postgres on mac, particularly coming form the ruby community. Would love to see this in the readme 👍

micheltlutz commented 6 years ago

Solve for me my postgresql installation with brew

Create File sudo vim /usr/local/lib/pkgconfig/libpq.pc

With content...

path=/usr/local/Cellar/postgresql@9.6/9.6.6/ Cflags: -I${path}/include Libs: -L${path}/lib -lpq

Path found with command

$ locate libpq-fe.h /Library/PostgreSQL/9.6/include/libpq-fe.h /usr/local/Cellar/postgresql@9.6/9.6.6/include/libpq-fe.h

After I Running vapor build --verbose and .. Building Project [Done]

gizmolab10 commented 6 years ago

i have the same problem:

/vapor/Packages/CPostgreSQL-1.0.0/module.modulemap:8:12: error: header '/usr/include/postgresql/libpq-fe.h' not found

and yet, "locate libpq-fe.h" returns:

/usr/include/postgresql/libpq-fe.h

i have a /usr/lib/pkgconfig/libpq.pc file, with contents:

Name: libpq Description: PostgreSQL libpq library Url: http://www.postgresql.org/ Version: 9.3.23 Requires: Requires.private: Cflags: -I/usr/include/postgresql Libs: -L/usr/lib -lpq Libs.private: -L/usr/lib/mit-krb5 -L/usr/lib/x86_64-linux-gnu/mit-krb5 -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lcrypt -lldap_r -lpthread

i'm stumped. can anyone help me out with this?