I've tried to just include the header and c files but they seem to be ignored
C function pointers are imported into Swift as closures with the C function pointer calling convention, denoted by the @convention(c) attribute. For example, a function pointer that has the type int (*)(void) in C is imported into Swift as @convention(c) () -> Int32 .
Swift packages are reusable components of Swift, Objective-C, Objective-C++, C, or C++ code that developers can use in their projects. They bundle source files, binaries, and resources in a way that's easy to use in your app's project. Each Swift package requires a Package.
To distribute code in binary form as a Swift package, create an XCFramework bundle, or artifact, that contains the binaries. Then, make the bundle available locally or on a server: When you host the binaries on a server, create a ZIP archive with the XCFramework in its root directory and make it available publicly.
The Swift Package Manager is a tool for managing the distribution of Swift code. It's integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. The Package Manager is included in Swift 3.0 and above.
it is possible but the usual way to do it is to define a seperate package called 'Csomething' where you simply prefix the C library name with a capital C and host it on Github. The C package only need consist of an empty Package.swift
file and a module.modulemap
. In the module.modulemap
you refer to where the C headers are:
module CPackage [system] { header "/usr/local/include/myheader.h" link "libraryname" export * }
Thus in your original package, you simply put a dependency in for the CPackage e.g.:
.Package(url: "https://github.com/aleph7/CHDF5.git", majorVersion: 1)
and then you can import CPackage
https://github.com/aleph7/CHDF5 is a good example of a simple C Package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With