Swift 5.2 Issue with headers in same dir as `.c/m` files

Hi there!

I'm playing around with a recent snapshot (swift-DEVELOPMENT-SNAPSHOT-2020-01-28-a.xctoolchain to be exact) and am running into an issue with an Objective-C based project (but I can reproduce the issue with a C based project as well).

It looks like support for Resources broke the case where a header is in the same directory as a .m file, and you have to explicitly exclude the .h file in the manifest.

The error itself is:

error: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    <PROJECT_DIR_PREFIX>/Sources/abc.h

I was able to reproduce it in a simple use case by using the Fixtures/CFamilyTargets/CLibrarySources example in the Swift Package Manager repo and modifying it by moving abc.h into the Sources directory (and deleting the now empty include directory) and running swift build.

The code causing this error was added in this commit.

Is this an intentional decision or a bug? If it's a bug I'm happy to file a report, but wasn't sure if I'm missing something.

For us (Firebase) in particular, a large amount of our headers are non-public and not in an include directory, which would cause us to have to restructure our entire project or manually manage the list of headers. I wasn't able to get a regular expression to match all headers, so maybe that's possible as well.

Should headers be included somehow here or should they be safely ignored?

Thanks,
Ryan

3 Likes

I suspect this is just an oversight. I would have expected .h to be understood as source unless the manifest specified otherwise. CC: @Aciid

Related: The proposal has the following to say about Objective C, but can C targets even use resources?

For Objective-C, the build system will add a preprocessor define called SWIFTPM_MODULE_BUNDLE which can be used to access the bundle from any .m file.

2 Likes

@Ryan_Wilson

Seems you get the same issue as me:

If this is a feature or intend to change, please point it out and provide the solution for Objective-C package user. Because this make a huge pain for current 99% project.

Doesn't anyone write Objecitve-C code have the folder strcture like this ? Even Xcode's itself new created source code does not seperate the header and source files. I didn't find any open source package use this:

RepoRoot

  • include
    -- NSObjectSubClass.h
  • Sources
    -- NSObjectSubClass.m
1 Like

Do it all the time.

Hi, @Aciid :

I am trying add swiftpm support for tommath (GitHub - libtom/libtommath: LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C.)

My Package.swift

targets: [
        .target(
            name: "tommath",
            path: ".",
            exclude: ["demo", "doc", "etc", "logs", "mtest"],
            sources: ["."],
            publicHeadersPath: ".",
            cSettings: [
                .unsafeFlags(["-flto=thin"]),  // for Dead Code Elimination
                .headerSearchPath(".")
            ]),

The question is: publicHeadersPath can not be same as sources

error: target 'tommath' has invalid header layout: 
umbrella header found at './libtommath/tommath.h', 
but directories exist next to it: 
    ./libtommath/.build, 
    ./libtommath/.git, 
    ./libtommath/.swiftpm,
    ./libtommath/demo, 
    ./libtommath/doc, 
    ./libtommath/etc, 
    ./libtommath/logs, 
    ./libtommath/mtest;
consider removing them
Terms of Service

Privacy Policy

Cookie Policy