如何在swift模块中 Package cassandrac++驱动程序

cdmah0mi  于 2021-06-10  发布在  Cassandra
关注(0)|答案(0)|浏览(278)

我正在尝试编写一个针对cassandrac驱动程序的服务器端swift应用程序(据我所知,没有swift本机支持)
我可以在mac上本地安装cassandra c
如下:


# Datastax C++ driver dependencies

   brew install libuv cmake
   brew install openssl
   brew link --force openssl

   # Install git if you dont have it
   brew install git

   # Retrieve the cpp 
   git clone https://github.com/datastax/cpp-driver.git --depth=1
   mkdir cpp-driver/build
   cd cpp-driver/build

   # Build with qualified path to OpenSSL location
   cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
   make
   make install

已验证

ls /usr/local/include/cassandra.h
-rw-r--r--  1 staff   323K Feb  2 14:26 /usr/local/include/cassandra.h

以及:

pkg-config --list-all
...
cassandra             cassandra - A C/C++ client driver for Apache Cassandra and DataStax Products
...

我创建了一个swift包,使用了太多的教程。
主要是:
https://github.com/apple/swift-package-manager/blob/master/documentation/usage.md#requiring-系统库
以及https://medium.com/shopify-mobile/wrapping-a-c-library-in-swift-part-1-6dd240070cef
但似乎每个线程的指令都是错误的?
https://forums.swift.org/t/system-library-targets-package-has-unsupported-layout-modulemap/16614/6
目前我的结构如下:

/Developer/cassandra-swift: tree
.
├── Package.swift
├── README.md
├── Sources
│   ├── cassandra
│   │   ├── cassandraumb.h
│   │   └── module.modulemap
│   └── cassandra-swift
│       └── cassandra_swift.swift
├── Tests
│   ├── LinuxMain.swift
│   └── cassandra-swiftTests
│       ├── XCTestManifests.swift
│       └── cassandra_swiftTests.swift

内容包括:

cassandra-swift: cat Package.swift
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "cassandra-swift",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
          name: "CCassandra",
          targets: ["CCassandra"])
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.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.
        .systemLibrary(
                    name: "CCassandra",
                    path: "Sources/cassandra",
                    pkgConfig: "cassandra"
//                    providers: [
//                        .brew(["libgraphqlparser"]),
//                        .apt(["libgraphqlparser"]),
//                        ]
                    ),
//        .testTarget(
//            name: "cassandra-swiftTests",
//            dependencies: ["cassandra-swift"]),
    ]
)

//git clone https://github.com/datastax/cpp-driver.git --depth=1
//cd cpp-driver/
//ls
//mkdir build
//cd build/
//   cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
//make
//make install
//less /usr/local/include/cassandra.h
//cat /usr/local/lib/pkgconfig/cassandra.pc

//-- Install configuration: ""
//-- Installing: /usr/local/include/cassandra.h
//-- Installing: /usr/local/include/dse.h
//-- Installing: /usr/local/lib/libcassandra.2.15.0.dylib
//-- Installing: /usr/local/lib/libcassandra.2.dylib
//-- Up-to-date: /usr/local/lib/libcassandra.dylib
//-- Installing: /usr/local/lib/pkgconfig/cassandra.pc
cassandra-swift: cat Sources/cassandra/module.modulemap
module CCassandra [system] {
    umbrella header  "cassandraump.h"
    header "/usr/local/include/cassandra.h"
    link "cassandra"
    export *
}
cat Sources/cassandra/cassandraumb.h

# import <c/cassandra.h>

我有一个2测试项目。第一个测试项目是使用 SPM 集成支持和添加git repo引用
另一个项目是引用spm包的spm生成的项目
两者都不能正常工作。
我已经玩了好几个小时了。
我希望它能在xcodefordev中本地工作,并且是可移植的(假设通过 spm )在快速码头集装箱中运行。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题