Improve clangd support #8867

Open
Tmpod wants to merge 1 commit from Tmpod/task/improve-clangd-support into master
Tmpod commented 2024-08-06 17:12:10 +00:00 (Migrated from github.com)

clangd is a very useful tool, serving as a Language Server for C/C++,
helping non-IDE editors tremendously.
With these tweaks, it works flawlessly on my setup.

Add a .clangd config file to exclude the -mno-direct-extern-access
flag which works fine on gcc but not on clang.
Also tell CMake to export a thing called "compile commands", which is
essentially a JSON file detailing all the commands used in compilation,
so that clangd can correctly process headers and allow you to jump
between definitions, uses and whatnot.
Finally, adds .cache/clangd to the gitignore file.

clangd is a very useful tool, serving as a Language Server for C/C++, helping non-IDE editors tremendously. With these tweaks, it works flawlessly on my setup. Add a .clangd config file to exclude the `-mno-direct-extern-access` flag which works fine on gcc but not on clang. Also tell CMake to export a thing called "compile commands", which is essentially a JSON file detailing all the commands used in compilation, so that clangd can correctly process headers and allow you to jump between definitions, uses and whatnot. Finally, adds `.cache/clangd` to the gitignore file.
biodranik (Migrated from github.com) reviewed 2024-08-06 20:52:56 +00:00
biodranik (Migrated from github.com) left a comment

What is your editor? Did you test it with VSCode?

What is your editor? Did you test it with VSCode?
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
biodranik (Migrated from github.com) commented 2024-08-06 20:50:51 +00:00

It would be great to know where does this flag come from :) Is it your system-specific issue?

It would be great to know where does this flag come from :) Is it your system-specific issue?
Tmpod (Migrated from github.com) reviewed 2024-08-06 21:21:58 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
Tmpod (Migrated from github.com) commented 2024-08-06 21:21:58 +00:00

This flag appears in the CMake-generated build.ninja files. Can you confirm if it appears in yours?
Indeed, I'm not sure where it comes from...

This flag appears in the CMake-generated `build.ninja` files. Can you confirm if it appears in yours? Indeed, I'm not sure where it comes from...
biodranik (Migrated from github.com) reviewed 2024-08-06 21:28:12 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
biodranik (Migrated from github.com) commented 2024-08-06 21:28:12 +00:00

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?
Tmpod (Migrated from github.com) reviewed 2024-08-06 21:39:46 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
Tmpod (Migrated from github.com) commented 2024-08-06 21:39:46 +00:00

According to gcc's man page:

-mdirect-extern-access
-mno-direct-extern-access
    Do  not  use  or  use  GOT  to  access external symbols.  The default is -mno-direct-extern-access: GOT is used for external symbols with default visibility, but not used for other
    external symbols.

    With -mdirect-extern-access, GOT is not used and all external symbols are PC-relatively addressed.  It is only suitable for environments where no dynamic link  is  performed,  like
    firmwares, OS kernels, executables linked with -static or -static-pie.  -mdirect-extern-access is not compatible with -fPIC or -fpic.

It's rather weird because I'm clearly using GCC to compile OM, yet CMake adds that flag, which is already the default.

Seems like the issue stems from clang having a different name for this: -fdirect-access-external-data.

According to gcc's man page: ``` -mdirect-extern-access -mno-direct-extern-access Do not use or use GOT to access external symbols. The default is -mno-direct-extern-access: GOT is used for external symbols with default visibility, but not used for other external symbols. With -mdirect-extern-access, GOT is not used and all external symbols are PC-relatively addressed. It is only suitable for environments where no dynamic link is performed, like firmwares, OS kernels, executables linked with -static or -static-pie. -mdirect-extern-access is not compatible with -fPIC or -fpic. ``` It's rather weird because I'm clearly using GCC to compile OM, yet CMake adds that flag, which is already the default. Seems like the issue stems from clang having a different name for this: [`-fdirect-access-external-data`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fdirect-access-external-data).
Tmpod (Migrated from github.com) reviewed 2024-08-06 22:33:31 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
Tmpod (Migrated from github.com) commented 2024-08-06 22:33:31 +00:00

It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode?

Looks like it's a Qt6 thing:

   Called from: [3]     /usr/lib/cmake/Qt6/Qt6Targets.cmake
                [2]     /usr/lib/cmake/Qt6/Qt6Config.cmake
                [1]     /home/tmpod/Programming/GSoC/2024/organicmaps/CMakeLists.txt
/usr/lib/cmake/Qt6/Qt6Targets.cmake(70):  set_target_properties(Qt6::Platform PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17 INTERFACE_COMPILE_OPTIONS \$<\$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>;\$<\$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data> INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/lib/qt6/mkspecs/linux-g++;${_IMPORT_PREFIX}/include/qt6 INTERFACE_LINK_LIBRARIES Threads::Threads _qt_package_version 6.7.2 )
> It looks like some dependency sets it. Can you try to trace cmake with debug/verbose/trace mode? Looks like it's a Qt6 thing: ``` Called from: [3] /usr/lib/cmake/Qt6/Qt6Targets.cmake [2] /usr/lib/cmake/Qt6/Qt6Config.cmake [1] /home/tmpod/Programming/GSoC/2024/organicmaps/CMakeLists.txt /usr/lib/cmake/Qt6/Qt6Targets.cmake(70): set_target_properties(Qt6::Platform PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17 INTERFACE_COMPILE_OPTIONS \$<\$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>;\$<\$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data> INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/lib/qt6/mkspecs/linux-g++;${_IMPORT_PREFIX}/include/qt6 INTERFACE_LINK_LIBRARIES Threads::Threads _qt_package_version 6.7.2 ) ```
Tmpod (Migrated from github.com) reviewed 2024-08-13 10:53:38 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
Tmpod (Migrated from github.com) commented 2024-08-13 10:53:38 +00:00

@biodranik What is your Qt6 version?

@biodranik What is your Qt6 version?
biodranik (Migrated from github.com) reviewed 2024-08-13 14:05:24 +00:00
@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"
biodranik (Migrated from github.com) commented 2024-08-13 14:05:24 +00:00

6.6 on Mac

6.6 on Mac
rtsisyk approved these changes 2024-12-23 18:41:08 +00:00
rtsisyk left a comment
Owner

LGTM

LGTM
This repo is archived. You cannot comment on pull requests.
No reviewers
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No milestone
No project
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: organicmaps/organicmaps-tmp#8867
No description provided.