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

SourceKit-LSP seems to ignore CXXSettings.unsafeFlags #609

Closed
mikolasstuchlik opened this issue Aug 9, 2022 · 12 comments
Closed

SourceKit-LSP seems to ignore CXXSettings.unsafeFlags #609

mikolasstuchlik opened this issue Aug 9, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@mikolasstuchlik
Copy link

I have set up a simple project using hand-built C++ library.

I have added custom C++ header search paths outside of the Package directory using CXXSettings.unsafeFlags as follows:

cxxSettings: [.unsafeFlags(["-I\(llvmIncludePath)"])],

but SourceKit-LSP ignores those include search paths. I have also tried to add those paths to the Swift Plugin for VSCode provided by SSWG, but this didn't work either.

@ahoppen asked me to try it out on the most recent DEVELOPMENT snapshot of the Swift Toolchain, but it didn't work either. On top of that, the clangd started to consume more and more cpu% and I was forced to kill it.

This issue was discussed on https://forums.swift.org/t/sourcekit-lsp-seems-to-ignore-cxxsettings-unsafeflags/59503

@ahoppen
Copy link
Member

ahoppen commented Aug 9, 2022

rdar://98370922

@ahoppen
Copy link
Member

ahoppen commented Aug 9, 2022

It appears that we aren’t passing compiler arguments that are provided in Package.swift to clangd.

@ahoppen ahoppen added the bug Something isn't working label Aug 22, 2022
@svanimpe
Copy link

svanimpe commented Oct 1, 2022

I came across this issue and I'm wondering if it's also the cause for my issue.

I'm trying to use a C library with Swift on Windows. Since the headers aren't installed in a global location, and pkg-config isn't available, I've added .unsafeFlags(["-IpathToIncludeDir"]) to the swiftSettings for my target in Package.swift.

The target now builds fine, but in the editor, I cannot click through to the definition of an imported C function, and the return types always show <<error type>>.

Screenshot

On macOS and Linux, this works fine, I'm assuming because it can find the headers through pkg-config instead?

Is this the same issue, or should I open a new one?

@compnerd
Copy link
Member

compnerd commented Oct 1, 2022

What version of swift are you using? Anything older the latest main snapshot would be too old for Windows at least. But, if it is the right version, then it should be the same issue.

@svanimpe
Copy link

svanimpe commented Oct 1, 2022

Ah sorry, I'm using the 5.7 release.

@ahoppen
Copy link
Member

ahoppen commented Jul 12, 2023

Hi @mikolasstuchlik, sorry for only getting back to this now. I just tried reproducing the issue and was unable to. Here’s what I tried.

  • mkdir /tmp/inc
  • echo "void testFunction() {}" > /tmp/inc/test.h
  • Open the attached project in VSCode
  • Open InstructionsExecuted.cpp
  • If I change testFunction to something different, I get a diagnostic but as it stands right now, I don’t, which means that we correctly find test.h in /tmp/inc using the custom search path in Package.swift.

Are you still seeing the issue? If yes, could you attach a project that reproduces the issue for you?

@mikolasstuchlik
Copy link
Author

Hello @ahoppen. Unfortunately, I have forgot why I've run into this issue. I will look through my archive and let you know if I find something.

@mikolasstuchlik
Copy link
Author

I have read the original thread on the Forums. The issue was manifesting when I've attempted to manually include header files of locally built library PCL.
I have been using Swift 5.6.1 at the time, which was ignoring said flags. However, I have been asked to DEVELOPMENT-SNAPSHOT-2022-08-06 which also failed.

I will need to build PCL again and I will let you know once I have results.

@ahoppen
Copy link
Member

ahoppen commented Jul 17, 2023

Sorry for the delay on my side. This would have been a lot easier if I had gotten back to you earlier. I really appreciate that you’re giving it another try.

@mikolasstuchlik
Copy link
Author

I would like to let you know, that I've been on vacation last week. I will look at the issue next week.

@mikolasstuchlik
Copy link
Author

mikolasstuchlik commented Aug 3, 2023

TL;DR I can confirm, that the issue no longer manifests on

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: x86_64-apple-macosx13.0

I have cloned pcl 1.13.1. I have tried to clone, configure and edit https://github.com/mikolasstuchlik/RunPCL which is the same project, where I've observed the issue.

The SourceKit-LSP in VSCide works as expected (albeit with considerable delay) and no longers spawns endless clangd tasks.

I consider this ticket solved.

@ahoppen
Copy link
Member

ahoppen commented Aug 3, 2023

Great. Thanks for verifying.

@ahoppen ahoppen closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants