Add wrappers for 'zig c++' to work around clangd
This commit is contained in:
19
README.md
19
README.md
@@ -16,3 +16,22 @@ You can create toolchains for other triples like this. Here is an example to bui
|
|||||||
set(ZIG_TARGET "aarch64-windows-gnu")
|
set(ZIG_TARGET "aarch64-windows-gnu")
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## clangd
|
||||||
|
|
||||||
|
To get [clangd](https://clangd.llvm.org/) to work you need to first enable generation of `compile_commands.json`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
```
|
||||||
|
|
||||||
|
Additionally you need to pass pass the following arguments to `clangd`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"clangd.arguments": [
|
||||||
|
"--log=verbose",
|
||||||
|
"--query-driver=*/clang-cl.exe,*/zig-cc.*,*/zig-c++.*,*/em++.bat,*/emcc.bat,*/em++,*/emcc",
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Without these arguments `clangd` will not query the driver (`zig c++`) and the include paths will not be resolved correctly.
|
||||||
|
|||||||
0
cmake/zig-ar.sh → cmake/zig-ar
Executable file → Normal file
0
cmake/zig-ar.sh → cmake/zig-ar
Executable file → Normal file
2
cmake/zig-c++
Normal file
2
cmake/zig-c++
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
zig c++ "$@"
|
||||||
2
cmake/zig-c++.cmd
Normal file
2
cmake/zig-c++.cmd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
@echo off
|
||||||
|
zig c++ %*
|
||||||
2
cmake/zig-cc
Normal file
2
cmake/zig-cc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
zig cc "$@"
|
||||||
2
cmake/zig-cc.cmd
Normal file
2
cmake/zig-cc.cmd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
@echo off
|
||||||
|
zig cc %*
|
||||||
0
cmake/zig-ranlib.sh → cmake/zig-ranlib
Executable file → Normal file
0
cmake/zig-ranlib.sh → cmake/zig-ranlib
Executable file → Normal file
0
cmake/zig-rc.sh → cmake/zig-rc
Executable file → Normal file
0
cmake/zig-rc.sh → cmake/zig-rc
Executable file → Normal file
@@ -1,2 +1,2 @@
|
|||||||
set(ZIG_TARGET "riscv64-freestanding-none")
|
set(ZIG_TARGET "riscv64-freestanding-none")
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
|
||||||
|
|||||||
@@ -33,15 +33,16 @@ endif()
|
|||||||
set(CMAKE_SYSTEM_VERSION 1)
|
set(CMAKE_SYSTEM_VERSION 1)
|
||||||
set(CMAKE_SYSTEM_PROCESSOR ${ZIG_ARCH})
|
set(CMAKE_SYSTEM_PROCESSOR ${ZIG_ARCH})
|
||||||
|
|
||||||
set(CMAKE_C_COMPILER "zig" cc -target ${ZIG_TARGET})
|
if(CMAKE_HOST_WIN32)
|
||||||
set(CMAKE_CXX_COMPILER "zig" c++ -target ${ZIG_TARGET})
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
set(SCRIPT_SUFFIX ".cmd")
|
set(SCRIPT_SUFFIX ".cmd")
|
||||||
else()
|
else()
|
||||||
set(SCRIPT_SUFFIX ".sh")
|
set(SCRIPT_SUFFIX "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Work around a bug in clangd where 'c++' is reordered on the command line
|
||||||
|
set(CMAKE_C_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-cc${SCRIPT_SUFFIX}" -target ${ZIG_TARGET})
|
||||||
|
set(CMAKE_CXX_COMPILER "${CMAKE_CURRENT_LIST_DIR}/zig-c++${SCRIPT_SUFFIX}" -target ${ZIG_TARGET})
|
||||||
|
|
||||||
# This is working (thanks to Simon for finding this trick)
|
# This is working (thanks to Simon for finding this trick)
|
||||||
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
|
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar${SCRIPT_SUFFIX}")
|
||||||
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${SCRIPT_SUFFIX}")
|
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib${SCRIPT_SUFFIX}")
|
||||||
|
|||||||
Reference in New Issue
Block a user