Update, a much simpler setup that works!
Structure:
<project>
|
- Sources
|
- Swift
| |
| - <swift files>
|
- graphqlparser
|
- module.modulemap
- graphqlparser.h
Module map:
module CGraphQLParser [system] {
umbrella header "graphqlparser.h"
link "graphqlparser"
export *
}
graphqlparser.h (umbrella header)
#import<c/GraphQLAstForEachConcreteType.h>
#import<c/GraphQLAst.h>
#import<c/GraphQLAstNode.h>
#import<c/GraphQLAstToJSON.h>
#import<c/GraphQLAstVisitor.h>
#import<c/GraphQLParser.h>
Package.swift:
// swift-tools-version:4.2
import PackageDescription
let package = Package(
name: "GraphQLParserSwift",
products: [
.library(
name: "GraphQLParserSwift",
targets: ["GraphQLParserSwift"])
],
targets: [
.target(
name: "GraphQLParserSwift",
dependencies: ["CGraphQLParser"],
path: "Sources/Swift"),
.systemLibrary(
name: "CGraphQLParser",
path: "Sources/graphqlparser",
// pkgConfig: "libgraphqlparser", this needs to be added to homebrew, open a PR.
providers: [
.brew(["libgraphqlparser"]),
.apt(["libgraphqlparser"]),
]
),
.testTarget(
name: "GraphQLParserSwiftTests",
dependencies: ["GraphQLParserSwift", "CGraphQLParser"],
path: "Tests")
],
swiftLanguageVersions: [.v4_2]
)
However, I still need to build xcode-proj with
-Xswiftc -I/usr/local/include/graphqlparser/ -Xlinker -L/usr/local/lib
E.g.
$ swift package -Xswiftc -I/usr/local/include/graphqlparser/ -Xlinker -L/usr/local/lib generate-xcodeproj
If I do the following
$ swift package generate-xcodeproj
and build in Xcode I get
ld: warning: Could not find auto-linked library 'graphqlparser'
Undefined symbols for architecture x86_64:
"_graphql_ast_to_json", referenced from:
GraphQLParserSwift.parse(query: Swift.String) throws -> GraphQLParserSwift.Document in QueryParser.o
"_graphql_error_free", referenced from:
GraphQLParserSwift.parse(query: Swift.String) throws -> GraphQLParserSwift.Document in QueryParser.o
"_graphql_node_free", referenced from:
$defer #1 () -> () in GraphQLParserSwift.parse(query: Swift.String) throws -> GraphQLParserSwift.Document in QueryParser.o
"_graphql_parse_string", referenced from:
closure #1 (Swift.UnsafeMutablePointer<Swift.UnsafePointer<Swift.Int8>?>) -> Swift.OpaquePointer? in GraphQLParserSwift.parse(query: Swift.String) throws -> GraphQLParserSwift.Document in QueryParser.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
However, swift build seems to build without hickup (though I haven't tested if the produced binary actually works in practice.)
Is there any way I can get the semantics of these flags automatically derived from the Package, header, or module map instead? Would love to be able to just do swift package generate-xcodeproj.