Is SwiftPM support link custom build static library inside targets,
I've try system target, system library, it's works
put header, and .c source file, it's works
but if I put header in include folder, and libXX.a custom static library file, and type [swift build]
it's always get this message
"\warning: target 'xx' in package 'xx' contains no valid source files"
in this c targets i've remove all .swift file
in module.modulemap i just define it this format, and put in include folder with shim.h header
module XX {
header "xx.h"
export *
}
and i know after Xcode 8.3 it should not add "link" syntax in modulemap file, if it's custom C language targets
I've google it for 5 days.. please help, thank you so much.
Is your project open sourced? If so I can take a look.
There are many little gotchas when mixing C and Swift so it is much easier to help if I can get more context of the layout and the Package.swift file etc.
btw, if I put foo.c, and bar.c, and type "swift build", everything is okay, module.modulemap generated successful, but no luck with libCFoo.a, libBar.a
it's error out with
"\warning: target 'Foo' in package 'Foo' contains no valid source files"
error: target 'Foo' referenced in product 'Foo' could not be found
It's only an empty file.
If there's no source files in the target directory, it can't compile.
It's written in here:
In case of complicated include layouts, a custom module.modulemap can be provided inside include.
I think having static link library in the module is a complicated case.
Hmm, I didn't know that part...
Anyway, if I removed the link part, it can't compile.
By the way, I forgot to mention to the critical problem.
This structure requires users to specify linker flag.
So packages depends on this also have to specify them.
In my case, the project was a executable. So it's not a big problem.
But if it is a public library, it's not user-friendry at all.
I recommend to search other way if your project is a library.
In Swift 5, you can do like this:
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Foo",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Foo",
targets: ["Foo"]),
],
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.
.target(
name: "Foo",
dependencies: ,