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-3129] SwiftPM Header Search Bug #5180

Closed
swift-ci opened this issue Nov 3, 2016 · 8 comments
Closed

[SR-3129] SwiftPM Header Search Bug #5180

swift-ci opened this issue Nov 3, 2016 · 8 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 3, 2016

Previous ID SR-3129
Radar rdar://problem/28030420
Original Reporter jeffburg@jeffburg.com (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

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

md5: 6772e3b0fef3a68f9afbc7e1333bc9f0

Issue Description:

When compiling Perfect-CURL or other lightweight wrappers around system dependencies, a compiler crash occurs when:

1) Xcode Command Line Tools installed (xcode-select --install)
2) Pkg-Config installed via home-brew

If both of those things are installed then it fails to compile. If only 1 of the 2 is installed then it works.

              • Steps to reproduce: ---------------

1) Install Sierra fresh
2) Install Xcode but do not install command line tools
3) Install HomeBrew
4) brew install pkg-config
5) git clone https://github.com/PerfectlySoft/Perfect-CURL.git
6) cd PerfectCurl, swift build

This should compile fine

7) swift build --clean=dist to clear everything
8) xcode-select --install to install CLT
9) swift build

Now the compiler will crash

10) brew uninstall pkg-config
11) swift build

Now it will compile again.

                    • Requested Command Output ------------
                      In ticket SR-1567 @aciidb0mb3r asked me to show some command output before and after CLT were installed.

Before Command Line Tools Installed

Jeffreys-Mac:~ jeffreybergier$ brew list
pkg-config
Jeffreys-Mac:~ jeffreybergier$ ls -al /usr
total 0
drwxr-xr-x@   10 root  wheel    340 Jun  7 00:32 .
drwxr-xr-x@   30 root  wheel   1088 Jul  7 12:37 ..
drwxr-xr-x     3 root  wheel    102 Jun  3 14:37 adic
drwxr-xr-x  1059 root  wheel  36006 Nov  3 14:27 bin
drwxr-xr-x   279 root  wheel   9486 Jul  7 12:40 lib
drwxr-xr-x   199 root  wheel   6766 Nov  3 14:27 libexec
drwxr-xr-x    13 root  wheel    442 Nov  3 14:28 local
drwxr-xr-x   246 root  wheel   8364 Jul  7 12:40 sbin
drwxr-xr-x    46 root  wheel   1564 Jul  6 13:18 share
drwxr-xr-x     4 root  wheel    136 Jun  7 00:33 standalone
Jeffreys-Mac:~ jeffreybergier$ pkg-config --cflags libcurl

Jeffreys-Mac:~ jeffreybergier$ pkg-config --cflags libxml2
Package libxml2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml2' found
Jeffreys-Mac:~ jeffreybergier$ 

After Command Line Tools Installed

Jeffreys-Mac:Perfect-CURL jeffreybergier$ brew list
pkg-config
Jeffreys-Mac:Perfect-CURL jeffreybergier$ ls -al /usr
total 0
drwxr-xr-x@   11 root  wheel    374 Nov  3 14:34 .
drwxr-xr-x@   30 root  wheel   1088 Jul  7 12:37 ..
drwxr-xr-x     3 root  wheel    102 Jun  3 14:37 adic
drwxr-xr-x  1059 root  wheel  36006 Nov  3 14:27 bin
drwxr-xr-x   261 root  wheel   8874 Nov  3 14:33 include
drwxr-xr-x   300 root  wheel  10200 Nov  3 14:34 lib
drwxr-xr-x   199 root  wheel   6766 Nov  3 14:27 libexec
drwxr-xr-x    13 root  wheel    442 Nov  3 14:28 local
drwxr-xr-x   246 root  wheel   8364 Jul  7 12:40 sbin
drwxr-xr-x    47 root  wheel   1598 Nov  3 14:34 share
drwxr-xr-x     4 root  wheel    136 Jun  7 00:33 standalone
Jeffreys-Mac:Perfect-CURL jeffreybergier$ pkg-config --cflags libcurl

Jeffreys-Mac:Perfect-CURL jeffreybergier$ pkg-config --cflags libxml2
Package libxml2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml2' found
@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 3, 2016

Comment by Jeffrey Bergier (JIRA)

The compiler crash output is attached above.

@swift-ci
Copy link
Contributor Author

Comment by Eric Knibbe (JIRA)

The issue here is that SwiftPM's pkg-config reader suggests header search paths that are already part of the compiler's default search path list, causing them to be searched in the wrong order and so exposing a compiler bug. The pkg-config tool itself avoids this by suppressing output of system search paths, and SwiftPM should be doing the same.

For example, pkg-config --cflags --libs libxml-2.0 returns -I/usr/include/libxml2 -lxml2 because /usr/include/libxml2 is not in the default search path list, while pkg-config --cflags --libs sqlite3 returns just -lsqlite3 because /usr/include is already in the list (as shown by clang++ -E -x c++ - -v < /dev/null).

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 6, 2016

Comment by Gregor Milos (Grzegorz Miłoś) (JIRA)

The failure also shows up when working with purely C packages. The issue isn't a compiler crash, but a compilation error due to module redefinition.

Minimum example is published here:
https://github.com/gmilos/TestZ

When

swift build

is invoked you get errors as follows[1].

IMPORTANT: the prerequisite is to have #810 merged (otherwise the zlib.pc isn't even used).

[1]

Cloning git@github.com:gmilos/CLibZ.git
HEAD is now at 77ed2dd Readme update.
Resolved version: 0.0.5
Compile TestZ main.c
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'AppleTextureEncoder'
module AppleTextureEncoder [system] [extern_c] {
       ^
/usr/include/module.modulemap:1:8: note: previously defined here
module AppleTextureEncoder [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:7:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/usr/include/module.modulemap:7:8: note: previously defined here
module Compression [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:13:8: error: redefinition of module 'Darwin'
module Darwin [system] [extern_c] {
       ^
/usr/include/module.modulemap:13:8: note: previously defined here
module Darwin [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1621:8: error: redefinition of module 'asl'
module asl [system] [extern_c] {
       ^
/usr/include/module.modulemap:1621:8: note: previously defined here
module asl [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1626:8: error: redefinition of module 'dnssd'
module dnssd [system] [extern_c] {
       ^
/usr/include/module.modulemap:1626:8: note: previously defined here
module dnssd [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1631:8: error: redefinition of module 'launch'
module launch {
       ^
/usr/include/module.modulemap:1631:8: note: previously defined here
module launch {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1636:8: error: redefinition of module 'os'
module os [system] [extern_c] {
       ^
/usr/include/module.modulemap:1636:8: note: previously defined here
module os [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1657:8: error: redefinition of module 'os_object'
module os_object [system] [extern_c] {
       ^
/usr/include/module.modulemap:1657:8: note: previously defined here
module os_object [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1662:8: error: redefinition of module 'libkern'
module libkern [system] [extern_c] {
       ^
/usr/include/module.modulemap:1662:8: note: previously defined here
module libkern [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1690:8: error: redefinition of module 'ldap'
module ldap [system] [extern_c] {
       ^
/usr/include/module.modulemap:1690:8: note: previously defined here
module ldap [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/module.modulemap:1723:8: error: redefinition of module 'krb5'
module krb5 [system] [extern_c] {
       ^
/usr/include/module.modulemap:1723:8: note: previously defined here
module krb5 [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/dispatch/module.modulemap:1:8: error: redefinition of module 'Dispatch'
module Dispatch [system] [extern_c] {
       ^
/usr/include/dispatch/module.modulemap:1:8: note: previously defined here
module Dispatch [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/dispatch/module.modulemap:7:8: error: redefinition of module 'DispatchIntrospection'
module DispatchIntrospection [system] [extern_c] {
       ^
/usr/include/dispatch/module.modulemap:7:8: note: previously defined here
module DispatchIntrospection [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach-o/module.map:1:8: error: redefinition of module 'MachO'
module MachO [system] [extern_c] {
       ^
/usr/include/mach-o/module.map:1:8: note: previously defined here
module MachO [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/objc/module.map:1:8: error: redefinition of module 'ObjectiveC'
module ObjectiveC [system] [extern_c] {
       ^
/usr/include/objc/module.map:1:8: note: previously defined here
module ObjectiveC [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/simd/module.modulemap:1:8: error: redefinition of module 'simd'
module simd [system] {
       ^
/usr/include/simd/module.modulemap:1:8: note: previously defined here
module simd [system] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/xpc/module.modulemap:1:8: error: redefinition of module 'XPC'
module XPC [system] [extern_c] {
       ^
/usr/include/xpc/module.modulemap:1:8: note: previously defined here
module XPC [system] [extern_c] {
       ^
17 errors generated.
<unknown>:0: error: build had 1 command failures
�[31merror:�[0m exit(1): /Library/Developer/Toolchains/swift-3.0.1-RELEASE.xctoolchain/usr/bin/swift-build-tool -f /private/tmp/tmp2/TestZ/.build/debug.yaml
Program ended with exit code: 1

@ankitspd
Copy link
Member

ankitspd commented Dec 6, 2016

#838

@ankitspd
Copy link
Member

ankitspd commented Dec 6, 2016

Looks like this happens only when you have CLT installed

@swift-ci
Copy link
Contributor Author

swift-ci commented Mar 7, 2017

Comment by Partho Biswas (JIRA)

I am still having this issue. I am using latest swift and Xcode version till date. How can i solve that ?

@ankitspd
Copy link
Member

ankitspd commented Mar 7, 2017

@swift-ci
Copy link
Contributor Author

swift-ci commented Mar 7, 2017

Comment by Eric Knibbe (JIRA)

ParthoBiswas007 (JIRA User) You need to download and install the newest Swift 3.1 toolchain and activate it in Xcode. Note that this doesn't activate it on the command line - to do that, you need to set the TOOLCHAINS environment variable, e.g. `export TOOLCHAINS=org.swift.3120170131a`. https://github.com/apple/swift-package-manager#managing-swift-environments

@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

2 participants