orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MongoKitten and Swift Playground

kzahedi opened this issue Β· comments

Hi,

I'm trying to use MongoKitten in a Swift Playground for Data Science purposes. Unfortunately, I cannot get it to work, because it will not find the CNIOOpenSSL module.

Does anyone know a solution to this problem?

Best,
Keyan

Hello πŸ‘‹ This could happen because your version of macOS doesn't have the openSSL or libreSSL headers installed by default. If that's not the case it might be that your Xcodeproject was created without pkg-config installed, it will likely not find the C library (libssl) without it.

Just so I can help better; what steps did you use to create the playground?

Thank you very much for your fast reply. Here are my steps:

  1. I used Carthage to download and install MongoKitten
  2. Called GenerateXcodeproj.rb in ~/Carthage/Checkouts/MongoKitten to create the project file
  3. Created a new workspace
  4. Added a playground file to my new workspace (code below)
  5. Added MongoKitten.xcodeproj to my workspace
  6. Compiled MongoKitten-Package for "My Mac"

My Swift Playground is:

import Cocoa
import MongoKitten

var str = "Hello, playground"

And I receive the following error message

error: missing required module 'CNIOOpenSSL'

I have attached a screenshot below.

The failed compile message for MongoKitten contains 999+ compile errors. I have screenshotted a few of them in the second screenshot below. I had installed sourcery via homebrew.

Thanks,
Keyan

screenshot 2019-02-15 at 17 47 06

screenshot 2019-02-15 at 17 28 24

The 120 characters error is not an error in our project or tooling. I'm suspecting your xcworkspace is running some script over the code for linting with a configuration we do not support. How did you link the playground against MongoKitten?

I am new to swift and playground. Basically, I followed the instructions I found in a WWDC talk. I opened a new workspace and included the MongoKitten.xcodeproj using the "Add file to " option. This works fine with other 3rd party libraries, such as Yams (yaml parser).

I don't recall installing swiftlint via brew, but somehow, it was installed. Uninstalling it removed all the compile errors for MongoKitten, but the include problem remains. Trying the run the three lines of code shown above still results in:

error: missing required module 'CNIOOpenSSL'

Recompiling CNIOOpenSSL did not resolve the issue.

I didn't try the above, but I'm not sure how to get it working otherwise. If you clone MongoKitten itself using git or by copying the zip from the releases tab here on github. You can run swift build. Does this work?

Does it work if you create the xcodeproject then with swift package generate-xcodeproj?

try using https://github.com/JohnSundell/TestDrive

Thanks for the tip. Unfortunately, it does not work for MongoKitten:

testdrive https://github.com/OpenKitten/MongoKitten.git
πŸ“¦ Cloning https://github.com/OpenKitten/MongoKitten.git...
🚒 Resolving latest version...
πŸ“‹ Checking out 5.1.1...
πŸ’₯ Xcode project missing at 'https://github.com/OpenKitten/MongoKitten.git'

Hmm... πŸ™ None of those tools all support SPM it seems. You can try to create a small package (without Playground) for now.

mkdir NotAPlayground
cd NotAPlayground
swift package init --type=exeuctable
open Package.swift

Update the Package.swift

swift package generate-xcodeproj
open NotAPlayground.xcodeproj

That works fine but causes other problems. One that is related to MongoKitten is the question of how to wait for the find expression to complete before moving on in the code.

SwiftNIO provides the wait() API on all promises. Don't use it within an eventloop. So you'll want to use Database.synchronousConnect(...) and then wait() for all operations.

Thanks. That worked. Now I need to find out, how the second library that I rely on works in an executable setting :)

It would still be great to see MongoKitten work in a playground setting. I am trying to move from Python to Swift for my data science stuff and ML stuff.

@kzahedi if you're interested, we're working on MongoKitten mobile which supports Cocoapods as well as MongoDB's embedded database and NIOTransportServices for macOS and iOS.

I'm closing this since it's solved, but feel free to ask me other things here or in slack πŸ‘