clice-project / clice

MIT License
24 stars 1 forks source link

Fix build with clang-18 toolchain. #1

Closed Guo-Shiyu closed 1 week ago

Guo-Shiyu commented 1 week ago

Fix Build with Clang-18 toolchain

So sorry to start such a direct PR without any issue or email communication before. I'm interested in this project to build a new LSP for C++. Tried to build it in my machine, I got some CE and has fixed it in this PR.

  1. My develop environment: WSL Ubuntu 22.04.5 LTS

    shiyu@DESKTOP-FNGPFEO ~/g/clice (main)> clang++ --version                                                                                                   10-14 [16:07:36]
    Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    shiyu@DESKTOP-FNGPFEO ~/g/clice (main)> clang-format --version                                                                                              10-14 [16:07:40]
    Ubuntu clang-format version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
  2. What I did (as the changes):

    • Fix a build error caused by missing include headers
      [{
      "resource": "/home/shiyu/github/clice/include/Server/Logger.h",
      "owner": "_generated_diagnostic_collection_name_#7",
      "code": "template_instantiate_undefined",
      "severity": 8,
      "message": "Implicit instantiation of undefined template 'std::basic_ostringstream<char>'",
      "source": "clang",
      "startLineNumber": 23,
      "startColumn": 28,
      "endLineNumber": 23,
      "endColumn": 38,
      "relatedInformation": [
      {
          "startLineNumber": 104,
          "startColumn": 11,
          "endLineNumber": 104,
          "endColumn": 30,
          "message": "Template is declared here",
          "resource": "/usr/include/c++/11/iosfwd"
      }
      ]
      },{
      "resource": "/home/shiyu/github/clice/include/Server/Logger.h",
      "owner": "_generated_diagnostic_collection_name_#7",
      "code": "no_member",
      "severity": 8,
      "message": "No member named 'put_time' in namespace 'std' (fix available)",
      "source": "clang",
      "startLineNumber": 24,
      "startColumn": 28,
      "endLineNumber": 24,
      "endColumn": 36
      }]

/home/shiyu/github/clice/.clang-format:35:1: error: unknown key 'BreakAfterReturnType' BreakAfterReturnType: Automatic ^~~~~~~~ I[00:16:45.539] getStyle() failed for file /home/shiyu/github/clice/include/Server/Logger.h: Error reading /home/shiyu/github/clice/.clang-format: Invalid argument. Fallback is LLVM style.



+ Fix other scirpts in `scripts` dir and format `.py` file  with black.

## MISC
This is a simple trail to contribute to clice project, if master branch is not ready to merge it u can close this directly.   

I also noticed something may could be improved (IMO), such as use `xmake` instead of `cmake` to manage depdencies because this project may needs to be tested under various version of compiler in the future (in my guess). And [libhv](https://github.com/ithewei/libhv?tab=readme-ov-file#tcp) maybe more suitable than `libuv` to build a LSP server, based on my experience (I have deploied some production app with libhv). 

If u need some help about it (or other things), I will be happy to do something for clice.
16bit-ykiko commented 1 week ago

Thank you for your suggestions.

  1. I am using the latest version of llvm for development because I might need to modify clang's source code and merge it into the mainline. The lower versions haven't been tested yet. Even after the entire program is completed, I believe supporting lower versions of llvm won't provide much value. The higher the version, the more powerful it is, with more features supported.

  2. I currently don't plan to use package managers like xmake, since llvm's build only requires cmake and python. Therefore, I hope the users of clice will only need these two dependencies if they decide to build from source.

  3. The reason I'm using libuv is that I'm more familiar with it, and I'm not very familiar with libhv. Could you elaborate on how it might be more suitable? Even with libuv, clice only uses a small portion of its features, so I want to keep the dependencies as lightweight as possible.

  4. The project isn't ready to accept contributions yet as it is still in an early development phase. My roadmap roughly looks like this:

    • Understand the existing issues in clangd, read through clangd and clang source code, and test prototypes to attempt solving problems.
    • Write the basic setup for clice, encapsulate clang's internal compiler calls, provide indexing, and build the server infrastructure.
    • Based on the apis provided in the second phase, implement higher-level lsp features.

I've spent a significant amount of time over the past few months studying clang's source code and testing prototypes. Now I'm in the second phase. To contribute at this stage, one needs to have a deep understanding of clang's internals. I wouldn't recommend contributing at this stage as it's very challenging. Contributing in the third phase will be relatively easier, where you'd only need to work with the apis I've encapsulated. I expect it will take me another 1-2 months to complete phase 2.

I've noticed that many people seem interested in building a new c++ lsp. I will open some issues to discuss and track progress. You're welcome to share your thoughts! :)