vapor-community / postgresql

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

Compile error with swift package #77

Closed mamcx closed 3 years ago

mamcx commented 6 years ago

I try to use this lib for first time with Swift 4:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "DbLib",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/groue/GRDB.swift.git", from: "2.10.0"),
        .package(url: "https://github.com/vapor/postgresql.git", from: "2.1.2"),
        //.package(url: "https://github.com/IBM-Swift/Swift-Kuery-PostgreSQL.git", from: "1.2.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "DbLib",
            dependencies: ["GRDB", "PostgreSQL"]),
    ]
)

➜ swift build warning: error while trying to use pkgConfig flags for swift-nio-zlib-support: couldNotFindConfigFile Compile libbcrypt blf.c Compile libbcrypt bcrypt.c Compile CNIOAtomics src/c-atomics.c Compile CNIOSHA1 c_nio_sha1.c Compile CNIOLinux shim.c Compile CNIODarwin shim.c Compile CNIOOpenSSL empty.c Compile Swift Module 'Debugging' (3 sources) Compile Swift Module 'NIOPriorityQueue' (2 sources) Compile Swift Module 'COperatingSystem' (1 sources) Compile Swift Module 'GRDB' (92 sources) Compile Swift Module 'NIOConcurrencyHelpers' (2 sources) Compile Swift Module 'NIO' (52 sources) Compile Swift Module 'NIOFoundationCompat' (1 sources) Compile Swift Module 'Bits' (12 sources) Compile Swift Module 'Async' (15 sources) Compile Swift Module 'NIOTLS' (3 sources) /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:50:51: error: missing argument label 'file:' in call let promise = worker.eventLoop.newPromise([Element.Expectation].self) ^ file: /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:53:48: error: ambiguous reference to member 'init' var results: [Element.Expectation?] = .init(repeating: nil, count: count) ^ ~~~~~~ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:53:48: note: overloads for 'init' exist with these partially matching parameter lists: (repeating: Element, count: Int), (repeating: Self.Element, count: Int) var results: [Element.Expectation?] = .init(repeating: nil, count: count) ^ error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/mamcx/Proyectos/Swift/DbLib/.build/debug.yaml main

vzsg commented 6 years ago

The build output shows that it's trying to compile NIO and Vapor 3's Core – which fails because you are using Swift 4.0 instead of the minimum required 4.1.

But the Package.swift you uploaded doesn't have any v3 stuff in it, which raises another question, have you run swift package update after changing the dependencies?

mamcx commented 6 years ago

Yeah, I don't do update. After that I get a dependance error, so I look at other vapor repos and try:

    .package(url: "https://github.com/vapor/core.git", from: "3.0.0"),
    .package(url: "https://github.com/vapor/postgresql.git", from: "1.0.0-rc"),

Now update work, but building:

warning: error while trying to use pkgConfig flags for swift-nio-zlib-support: couldNotFindConfigFile Compile Swift Module 'Async' (15 sources) Compile Swift Module 'NIOOpenSSL' (11 sources) /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:50:51: error: missing argument label 'file:' in call let promise = worker.eventLoop.newPromise([Element.Expectation].self) ^ file: /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:53:48: error: ambiguous reference to member 'init' var results: [Element.Expectation?] = .init(repeating: nil, count: count) ^ ~~~~~~ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/core.git-9210800844849382486/Sources/Async/Future+Flatten.swift:53:48: note: overloads for 'init' exist with these partially matching parameter lists: (repeating: Element, count: Int), (repeating: Self.Element, count: Int) var results: [Element.Expectation?] = .init(repeating: nil, count: count) ^

:1:9: note: in file included from :1: #import "/Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h" ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h:17:10: error: 'openssl/conf.h' file not found #include ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLHandler.swift:16:8: error: could not build Objective-C module 'CNIOOpenSSL' import CNIOOpenSSL ^ :1:9: note: in file included from :1: #import "/Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h" ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h:17:10: error: 'openssl/conf.h' file not found #include ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLHandler.swift:16:8: error: could not build Objective-C module 'CNIOOpenSSL' import CNIOOpenSSL ^ :1:9: note: in file included from :1: #import "/Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h" ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h:17:10: error: 'openssl/conf.h' file not found #include ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLHandler.swift:16:8: error: could not build Objective-C module 'CNIOOpenSSL' import CNIOOpenSSL ^ :1:9: note: in file included from :1: #import "/Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h" ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/CNIOOpenSSL/include/c_nio_openssl.h:17:10: error: 'openssl/conf.h' file not found #include ^ /Users/mamcx/Proyectos/Swift/DbLib/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLHandler.swift:16:8: error: could not build Objective-C module 'CNIOOpenSSL' import CNIOOpenSSL ^ error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/mamcx/Proyectos/Swift/DbLib/.build/debug.yaml main

So look like is a OpenSSL issue. But then how resolve that?

vzsg commented 6 years ago

There are actually two errors in there. One is caused by Swift 4.0 (you need to have Swift 4.1 installed if you want to work with Vapor 3), the other is indeed OpenSSL. Run brew install libressl pkg-config and run swift package update again.

mamcx commented 6 years ago

I can't use Swift 4.1 yet. Which is the compatible version for 4?

vzsg commented 6 years ago

Vapor 2.4.4 along with version 2.1.2 of this repo.

quantum-fusion commented 3 years ago

@vzsg I updated the LibreSSL packages, but there is still a compile error showing the wrong version being linked for dylib for LibreSSL.

ld: warning: ld: warning: dylib (/usr/local/Cellar/libressl/3.2.3/lib/libcrypto.dylib) was built for newer macOS version (11.0) than being linked (10.10)dylib (/usr/local/Cellar/libressl/3.2.3/lib/libssl.dylib) was built for newer macOS version (11.0) than being linked (10.10)

Screen Shot 2021-01-10 at 7 17 57 AM
quantum-fusion commented 3 years ago

@vzsg I tried this potential workaround for dylib, but no luck (https://stackoverflow.com/questions/58272830/python-crashing-on-macos-10-15-beta-19a582a-with-usr-lib-libcrypto-dylib)

0xTim commented 3 years ago

@quantum-fusion that's just a linking warning, the actual compiler error is in App and Run

quantum-fusion commented 3 years ago

@0xTim You can see that initially there are just warnings, for the dylib but then those turn to undefined symbols for dependencies during the linking step (Undefined symbols for architecture x86_64: "_OBJCCLASS$_CIContext", referenced from: objc-class-ref in Classifier.o "_OBJCCLASS$_CIImage", referenced from: objc-class-ref in routes.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) )

Screen Shot 2021-01-11 at 6 31 12 AM
quantum-fusion commented 3 years ago

@0xTim I have tried and tried and tried, but can't get these Undefined symbols resolved, for dylib.

0xTim commented 3 years ago

What versions on macOS, Xcode, Swift and LibreSSL are you using?

quantum-fusion commented 3 years ago

@0xTim We decided to downgrade the version of Swift and Xcode, to support Vapor4. I left a note to the developer of the Vapor project that was going to host a CoreML model with Vapor for a REST API, but he is non-responsive. I am not sure this is going anywhere. (https://github.com/rickwierenga/heartbeat-tutorials/issues/3). I asked if he could help upgrade to vapor4, but it doesn't look like he wants to.

swift --version Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28) Target: x86_64-apple-darwin20.4.0

0xTim commented 3 years ago

Closing this as this is due to trying to import CIImage into a Swift Package which isn't possible and nothing to do with Vapor. You need to generate an Xcode project and use that (though that's deprecated essentially so I'm not sure what the workaround is after that)