Skip to content

Better support for creating C libraries with Swift #8228

Open
@dabrahams

Description

@dabrahams

Description

Copied from this forum post:

I've run into two problems:

  • the Swift code in the C library needs access to the declarations in the C library's headers, and I don't see a way to do that with SPM other than by .unsafeFlags.

  • I don't seem to be able to import the C library into a Swift test. If I do that (uncomment the test target here), I get scads of errors that look like this:

.../TemporaryDirectory.J6j0QN/LotsawaC.pch:3:21: error: source file is not valid UTF-8
   1 | # 1 "<built-in>"

   2 | # 1 "/var/folders/wg/wvvfbgl96f727hzqdtpfrrl80000gn/T/TemporaryDirectory.J6j0QN/LotsawaC.pch"

      1 | # 1 "<built-in>"

   2 | # 1 "/var/folders/wg/wvvfbgl96f727hzqdtpfrrl80000gn/T/TemporaryDirectory.J6j0QN/LotsawaC.pch"

   3 | ����  <more nonsense>

In other words, the .pch file starts with valid text, but then it appears to be binary. Which might be just fine, but then SPM is cosuming it incorrectly.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

As noted above, uncomment these lines in the referenced project and then test it.

Swift Package Manager version/commit hash

6.0.0-dev

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Darwin davea-mbp16.corp.adobe.com 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec 6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000 arm64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions