Swift language support

I’ve been away from this for a few days on family business. I spent several hours, today, trying to figure out how to do something with your Xcode project from GitHub or how to incorporate it into my Xcode projects that I write…I’m lost!

The problems:

  1. your Xcode project compiles but doesn’t do anything – I tried, but I can’t determine where to put my code
  2. my Xcode project has AppDelegate and ViewController files, as normal – I tried, but I can’t figure out how to correctly copy your files into my project so I can use them

I guess this is above my pay grade…

Haven’t given up on a Swift API… but until that arrives I have been experimenting with FDB by using Chris Lattner’s Python interoperability thru Swift playground (mentioned that in an earlier post).

Been fiddling with timing… In a Swift Playground timing can be significantly improved by moving source code to the Playground’s Sources Folder – because it gets precompiled and doesn’t go thru the REPL in the main window.

I got some pretty good results… but first, the following is from the FDB Benchmarking writeup:

So, 46,000 writes/second on a single core…

Here’s the best timing I got on Swift/Python - 65,580 writes/second:

For some reason I can’t get C bridging working. CFoundationdb doesn’t build with error
error: 'fdb_c_options.g.h' file not found
(in shim.h)
It just can’t find header files. However, if I set full (and hence platform-specific) paths to headers (e.g. /usr/local/include/foundationdb/fdb_c.h), package builds, but with warning
ld: warning: Auto-Linking library not found for -llibfdb_c
and if I try to use like anything from fdb library, I get error

Undefined symbols for architecture x86_64:
  "_fdb_get_max_api_version", referenced from:
      _main in main.swift.o

which is highly confusing. It seems like it just can’t see the dylib (I think I tried every possible form of link value in modulemap, none of them seem to work).

Can anyone help? I would really like to use fdb in my project, but the stupidity of situation is frustrating me beyond measure :frowning:

OK so I managed to get it working. You either pass Xlinker flag to swift build / swift run command like this:

swift build -Xlinker -L/usr/local/lib/

(which is ugly) or you should use pkg-config in CFoundationdb Package.swift:

let package = Package(
    name: "CFoundationdb",
    pkgConfig: "libfdb",
    products: [
          .library(
              name: "CFoundationdb",
              targets: ["CFoundationdb"]
          )
    ],
    targets: [
        .target(name: "CFoundationdb")
    ]
)

Since I haven’t found one, I created macOS pkgconfig myself: https://gist.github.com/kirilltitov/a3829d6f9d73f5c84b52a8f7b7dbe870, it should be copied to /usr/local/lib/pkgconfig directory. After that everything works like a charm.

(but really pkgconfig should be vendored with fdb installation)

-l implicitly prefixes its argument with “lib”, so this should probably just be -lfdb_c

This actually came up in conversation on Tuesday. I agree it would be a good idea.

I’d also be happy to look at a PR that adds one to the installers/packages. :slight_smile:

I’ve never done such things before… I mean, it’s very new subject area for me (pkgconfigs etc). So I think I should focus on the wrapper. By the way here it is: https://github.com/kirilltitov/FDBSwift :slight_smile:

All, bumping this thread for awareness.

Last month official Swift bindings for FoundationDB were announced, and they are available on GitHub: https://github.com/foundationdb/fdb-swift-bindings.

2 Likes