Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9024] dependency issues with SwiftPM generated Xcode projects that contain C modues #4754

Closed
weissi opened this issue Oct 17, 2018 · 7 comments
Labels

Comments

@weissi
Copy link
Member

weissi commented Oct 17, 2018

Previous ID SR-9024
Radar rdar://problem/45364394
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 4a4238ddf60ba176a1f622c3560fd804

Issue Description:

description

Let's assume we have the following setup:

1. TestApp - a regular Xcode project which contains say a macOS app
2. SomePackage - a SwiftPM project which is a library TestApp wants to use

A typical way to set that up would be:

1. create a regular Xcode project "TestApp"
2. next to "TestApp", clone/create a SwiftPM project and

cd SomePackage
swift package generate-xcodeproj

3. drag the SomePackage.xcodeproj into the TestApp xcode project so that the whole thing looks like this in Xcode

The whole thing works really well if the setup of SomePackage is

let package = Package(
    name: "SomePackage",
    products: [
        .library(
            name: "SomePackage",
            targets: ["SomePackage"]),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "SomePackage",
            dependencies: ["SomeModuleInSomePackage"]),
        .target(
            name: "SomeModuleInSomePackage",
            dependencies: []),
    ]
)

Which makes the dependency tree

TestApp -> SomePackage -> SomeModuleInSomePackage

assuming all the modules are Swift modules. However adding a C module (called SomeModuleInSomePackage) into SomePackage making the graph

TestApp -> SomePackage -> SomeModuleInSomePackage -> CSomeModuleInSomePackage

or as Package.swift

let package = Package(
    name: "SomePackage",
    products: [
        .library(
            name: "SomePackage",
            targets: ["SomePackage"]),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "SomePackage",
            dependencies: ["SomeModuleInSomePackage"]),
        .target(
            name: "SomeModuleInSomePackage",
            dependencies: ["CSomeModuleInSomePackage"]),
        .target(
            name: "CSomeModuleInSomePackage",
            dependencies: []),
    ]
)

always raises the following compilation error in Xcode:

error: missing required module 'CSomeModuleInSomePackage'

repro

1. Download the attached repro.tar.gz
2. tar xf repro.tar.gz
3. cd repro/SomePackage/
4. swift package generate-xcodeproj
5. cd ../TestApp
6. xed .
7. make sure the "TestApp" scheme is selected in Xcode
8. build the Xcode project (Cmd+B)

expected

builds the whole thing

actual

Missing required module 'CSomeModuleInSomePackage'

environment

$ swift -version
Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0
$ sw_vers -buildVersion
18A391
$ xcodebuild -version
Xcode 10.0
Build version 10A255
@weissi
Copy link
Member Author

weissi commented Oct 17, 2018

@aciidb0mb3r/@neonichu this is probably related to SR-7531 but it still doesn't work... Clang modules seem to be enabled but it doesn't work:

$ grep CLANG_ENABLE_MODULES SomePackage.xcodeproj/project.pbxproj 
            CLANG_ENABLE_MODULES = "YES";
            CLANG_ENABLE_MODULES = "YES";

I did try to generate the xcodeproj with /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-10-03-a.xctoolchain/usr/bin/swift package generate-xcodeproj which is

Apple Swift version 4.2-dev (LLVM aeaaca98ed, Clang 1ddef2249a, Swift 20bb815b62)
Target: x86_64-apple-darwin18.0.0

but didn't work still.

@weissi
Copy link
Member Author

weissi commented Oct 18, 2018

@swift-ci create

@ankitspd
Copy link
Member

This will only work if the C module has an umbrella header. In your repro, rename SomePackage/Sources/CSomeModuleInSomePackage/include/c_some_module_in_some_package.h to SomePackage/Sources/CSomeModuleInSomePackage/include/CSomeModuleInSomePackage.h

@weissi
Copy link
Member Author

weissi commented Oct 18, 2018

Wow, that's awesome, thank you so much! Fixed NIO in apple/swift-nio#636 .
Can we re-open this as a diagnostics issue for SwiftPM, it should at least warn about that, right?

@ankitspd
Copy link
Member

I am not sure if we can detect the intent with just SwiftPM. It is perfectly valid to not have an umbrella header. What kind of diagnostic do you have in mind?

@weissi
Copy link
Member Author

weissi commented Oct 19, 2018

@aciidb0mb3r when would I want a C module in a SwiftPM project that doesn't have an umbrella header? And if that's what I want, why doesn't the generated Xcode project then work?

@tkrajacic
Copy link

@aciidb0mb3r When I give an umbrella header to the C library, but do NOT remove a potential modulemap for this module, the same error is still there. This makes sense when looking at the code path I guess, but can this be considered a bug?

} else if includeGroup.subitems.contains(where: { $0.path == clangTarget.c99name + ".h" }) {
// If an umbrella header exists, enable Xcode's builtin module's feature rather than generating
// a custom module map. This increases the compatibility of generated Xcode projects.
let headerPhase = xcodeTarget.addHeadersBuildPhase()
for case let header as Xcode.FileReference in includeGroup.subitems {
let buildFile = headerPhase.addBuildFile(fileRef: header)
buildFile.settings.ATTRIBUTES = ["Public"]
}
targetSettings.common.CLANG_ENABLE_MODULES = "YES"
targetSettings.common.DEFINES_MODULE = "YES"

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants