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-11504] for some reason, /usr/local/include takes priority over the SDK #4662

Open
weissi opened this issue Sep 22, 2019 · 10 comments
Open
Labels

Comments

@weissi
Copy link
Member

weissi commented Sep 22, 2019

Previous ID SR-11504
Radar rdar://problem/55601495
Original Reporter @weissi
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: b40fb2b5182a5282640ecfe2f7c53671

Issue Description:

Even if not asked to add any directories to the include path, when invoking (the) clang (importer), /usr/local/include seems to take priority over the SDK.

Repro:

git clone https://github.com/apple/swift-nio
sudo mkdir -p /usr/local/include
sudo bash -c 'echo "#error \"this should not happen\"" > /usr/local/include/string.h'
cd swift-nio
swift build

Note, to unbrick your computer, run sudo rm -f /usr/local/include/string.h.

Result:

[...]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/mach/mach_vm.h:6:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/mach/mach_vm.h:6:
#include <string.h>
         ^
/usr/local/include/string.h:1:2: error: "this should not happen"
#error "this should not happen"
 ^
<module-includes>:436:9: note: in file included from <module-includes>:436:
#import "libc.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libc.h:37:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libc.h:37:
#include <string.h>
         ^
/usr/local/include/string.h:1:2: error: "this should not happen"
#error "this should not happen"
 ^
<unknown>:0: error: could not build Objective-C module 'Darwin'
@weissi
Copy link
Member Author

weissi commented Sep 22, 2019

@swift-ci create

@weissi
Copy link
Member Author

weissi commented Sep 22, 2019

CC @belkadan/@ddunbar/@aciidb0mb3r

@weissi
Copy link
Member Author

weissi commented Sep 22, 2019

Xcode has no trouble building swift-nio even in the presence of the bogus string.h so I'd say this is a SwiftPM issue, tagging it as such for now even through it might be a bogus default in clang/swiftc.

@belkadan
Copy link

I think we looked into this before and it turns out to come from how the command-line tools work on macOS without being invoked through xcrun, or maybe without an explicit SDK (either from xcrun or from -sdk). Ankit, do you have the discussion for that?

@belkadan
Copy link

(As in, this is expected behavior on macOS and we aren't going to change it.)

@weissi
Copy link
Member Author

weissi commented Sep 23, 2019

@belkadan wait, xcrun swift build would workaround this?

@ankitspd
Copy link
Member

This is xcrun's behavior when an explicit SDK is not passed and `swift build` goes through xcrun on macOS. From xcrun's man page:

       CPATH
          This  environment variable is modified by xcrun to include /usr/local/include when an explicit SDK is not requested via environment vari-
          able nor command line argument and neither -nostdinc nor -nostdsysteminc are present.

@weissi It'll work if you run `xcrun -sdk macosx swift build`

This has known to cause one other similar issue so far. I don't know if it's a good idea for SwiftPM to try to detect and unset this env variable.

@weissi
Copy link
Member Author

weissi commented Sep 23, 2019

@aciidb0mb3r oh nice, thank you! Hmm, I think SwiftPM and Xcode should behave the same by default?

@ankitspd
Copy link
Member

I agree that they should but this is an unfortunate bug because of the implementation details of the underlying tools. There's no way to properly detect if CPATH was set by xcrun or not.

@weissi
Copy link
Member Author

weissi commented Sep 23, 2019

yup...

@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
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

4 participants