mrexodia / zig-cross

Example of using as a CMake Toolchain for cross compiling.

Home Page:https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599

Repository from Github https://github.commrexodia/zig-crossRepository from Github https://github.commrexodia/zig-cross

zig-cross

Example of using zig as a CMake Toolchain for cross compiling.

Reference: https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599

Building

  • Install zig in your PATH (choco install zig on Windows)
  • cmake -B build-aarch64 -G Ninja --toolchain aarch64-linux-gnu.cmake
  • cmake --build build-arch64

You can create toolchains for other triples as well, just create a file named aarch64-windows-gnu.cmake with the following contents to build for Windows on ARM64:

include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

clangd

To get clangd to work you need to first enable generation of compile_commands.json:

cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Additionally you need to pass pass the following arguments to clangd:

"clangd.arguments": [
    "--log=verbose",
    "--query-driver=**/zig-cc.cmd,**/zig-cc,**/zig-c++.cmd,**/zig-c++",
]

Without these arguments clangd will not query the driver (zig c++) and the include paths will not be resolved correctly.

About

Example of using as a CMake Toolchain for cross compiling.

https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599

License:Boost Software License 1.0


Languages

Language:CMake 87.5%Language:C 3.9%Language:C++ 3.5%Language:Shell 2.6%Language:Batchfile 2.4%