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-6514] Using libSwiftPM in Xcode Project is blocked by error: missing required module 'clibc'. #4850

Closed
norio-nomura opened this issue Dec 1, 2017 · 27 comments
Labels

Comments

@norio-nomura
Copy link
Contributor

Previous ID SR-6514
Radar rdar://problem/67516759
Original Reporter @norio-nomura
Type Bug

Attachment: Download

Environment

swift 4.0.2-RELEASE

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

md5: 9cba4834f2c2ee99f4952a52b7775c26

Issue Description:

Example: jpsim/SourceKitten#454
Build log: https://circleci.com/gh/jpsim/SourceKitten/757

@ddunbar
Copy link
Member

ddunbar commented Dec 1, 2017

@aciidb0mb3r is this because we need the special command line arguments to point to the module maps?

I have also hit this problem trying to use a SwiftPM package from a playground, and it is pretty annoying. Fixing it may not be easy though.

@ankitspd
Copy link
Member

ankitspd commented Dec 1, 2017

I think this is failing because you're depending on SwiftPM product. Try depending on "Utility".

@ankitspd
Copy link
Member

ankitspd commented Dec 1, 2017

Oh, are you adding dependency to the generated Xcode project?

@norio-nomura
Copy link
Contributor Author

@aciidb0mb3r Yes, I'm trying. Using system module may be biggest barrier on using generated Xcode project as dependency.

@ankitspd
Copy link
Member

ankitspd commented Dec 1, 2017

We need to generate copy header phases in the generated Xcode project to fix this issue.

@norio-nomura
Copy link
Contributor Author

I implement generating copy header phase on #1406
But, generated Xcode project with that PR is blocked by different error:

nclude of non-modular header inside framework module 'clibc': '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/fts.h'

That is caused by that {{clibc}} is system module.

@ankitspd
Copy link
Member

ankitspd commented Dec 1, 2017

Try setting enable modules off

@norio-nomura
Copy link
Contributor Author

Error: include of non-modular header inside… with CLANG_ENABLE_MODULES = NO.
Error: No such module 'clibc' with DEFINES_MODULE = NO.

@norio-nomura
Copy link
Contributor Author

The only workaround I found was:

  1. Delete clibc target
  2. Set $(SRCROOT)/Sources/clibc/include/clibc.h to SWIFT_OBJC_BRIDGING_HEADER of libc target
  3. Remove @_exported import clibc in libc.swift

@norio-nomura
Copy link
Contributor Author

FYI, generated {{SwiftPM.xcodeproj}} will be able to be built in xcworkspace by following changes:
jpsim/SourceKitten@4bf212e
With that changes, modules in {{libSwiftPM}} can be used from playgrounds in the workspace.

@ankitspd
Copy link
Member

Here is a workaround. In clibc target:
• Set Defines Module to YES
• Add a Headers Phase and add clibc.h to public headers.
• Add the following script phase:

Script:
echo "framework module clibc [system] {
umbrella header "clibc.h"
export *
}" > $BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME/Modules/module.modulemap

Input Files:
$(BUILT_PRODUCTS_DIR)/$(FULL_PRODUCT_NAME)

@krzyzanowskim
Copy link
Contributor

@aciidb0mb3r The workaround seems not perfect

./swift-source/swiftpm/Sources/clibc/include/clibc.h:1:10: Include of non-modular header inside framework module 'clibc': '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/fts.h'

@ankitspd
Copy link
Member

I recently published a documentation on using libSwiftPM. You shouldn't have these issues anymore when directly depending on SwiftPM: https://github.com/apple/swift-package-manager/blob/master/Documentation/libSwiftPM.md

Xcode project generation: https://github.com/apple/swift-package-manager/blob/master/Examples/package-info/Makefile#L23

@krzyzanowskim
Copy link
Contributor

@aciidb0mb3r should `Utilities/bootstrap build-runtimes` works with Swift 4.2.1 ?
I get `unknown build action: 'build-runtimes'`

@krzyzanowskim
Copy link
Contributor

It doesn't seem to work to me, tried master with Swift 4.2.1. I wish it work with Xcode out of the box one day 😉

@ankitspd
Copy link
Member

Did you use the makefile to generate the project?

@krzyzanowskim
Copy link
Contributor

the Makefile is in the Example. I don't use that example. I'm trying to build Xcode usable SwiftPM. Tried with `swift-DEVELOPMENT-SNAPSHOT-2018-11-01-a` and still failed.

I do:
$ Utilities/bootstrap build-runtimes
$ swift package generate-xcodeproj

and it has the same problem with clibc as any previous version

@krzyzanowskim
Copy link
Contributor

specifically, this snapshot doesn't seem to build at all with Xcode

More I fight with that I come to the conclusion that I should just copy files over instead of trying to make it build 😉

@ankitspd
Copy link
Member

As I said in the previous comment, you need to generate the Xcode project using:

$ swift package generate-xcodeproj --xcconfig-overrides config.xcconfig

See: https://github.com/apple/swift-package-manager/blob/master/Examples/package-info/Makefile#L23

@krzyzanowskim
Copy link
Contributor

Hm... I don't understand why is the `config.xcconfig` somewhere in the Examples if it's required for SwiftPM.xcodeproj?

@ankitspd
Copy link
Member

Oh, you want to build SwiftPM itself as opposed to using it as dependency? Then you just need: `Utilities/bootstrap --generate-xcodeproj`.

See more info here: https://github.com/apple/swift-package-manager/blob/master/Documentation/Development.md#developing-using-xcode

@krzyzanowskim
Copy link
Contributor

@aciidb0mb3r it did the job.

@krzyzanowskim
Copy link
Contributor

oh no, it didn't. I don't know what I'm doing wrong. I just use SwiftPM as a subproject and link to it.

@ankitspd
Copy link
Member

Yeah, adding as a subproject doesn't work out of the box since clibc contains a custom modulemap. Adding header search path to `swiftpm/Sources/clibc/include` in the top-level project should fix that.

@krzyzanowskim
Copy link
Contributor

I didn't find it easy to set up. I summarize my thoughts on forum https://forums.swift.org/t/how-to-use-libswiftpm-dylib/18529 in case it needs more discussion

@CodaFi
Copy link
Member

CodaFi commented Aug 21, 2020

This is still hitting people that consume libSwiftPM

@swift-ci create

@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
@MaxDesiatov
Copy link
Member

Since libSwiftPM doesn't have a versioned stable API other than in PackageDescription and PackagePlugin modules, its use outside of toolchain components developed in lockstep (like SourceKit-LSP) is not supported.

@MaxDesiatov MaxDesiatov closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
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

7 participants