From 9fa397a299252b4621095b462afb0502d62c7da4 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sat, 22 Mar 2025 22:15:36 -0400 Subject: [PATCH 1/4] chore(gitignore): add compile_commands.json Signed-off-by: Seth Flynn --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b5523f685..c8f056eef 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ CMakeCache.txt /.vs cmake-build-*/ Debug +compile_commands.json # Build dirs build From 8a21b079159e12308928dab6d6d44d89c5bac0a3 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sat, 22 Mar 2025 22:15:52 -0400 Subject: [PATCH 2/4] build: export compile commands for debug builds Signed-off-by: Seth Flynn --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc2e77d4a..138049018 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOML_ENABLE_FLOAT16=0") # set CXXFLAGS for build targets set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}") +# Export compile commands for debug builds if we can (useful in LSPs like clangd) +# https://cmake.org/cmake/help/v3.31/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html +if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja" AND CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +endif() + option(DEBUG_ADDRESS_SANITIZER "Enable Address Sanitizer in Debug builds" OFF) # If this is a Debug build turn on address sanitiser From d6103c2a068a8ebc96e8dd349f3878d84da7e64f Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sat, 22 Mar 2025 22:19:16 -0400 Subject: [PATCH 3/4] build(nix): copy compile_commands.json when entering dev shell Signed-off-by: Seth Flynn --- flake.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flake.nix b/flake.nix index 54add656d..d15a5bf03 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,16 @@ ccache ninja ]; + + cmakeFlags = self.packages.${system}.prismlauncher-unwrapped.cmakeFlags ++ [ + "-GNinja" + "-Bbuild" + ]; + + shellHook = '' + cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug + ln -s {build/,}compile_commands.json + ''; }; } ); From e3f93295f0c8e4ea44762535e4e15bb4e0f0cf78 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sat, 22 Mar 2025 22:19:49 -0400 Subject: [PATCH 4/4] build(nix): add clangd to dev shell Signed-off-by: Seth Flynn --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index d15a5bf03..150240c8b 100644 --- a/flake.nix +++ b/flake.nix @@ -78,6 +78,7 @@ buildInputs = with pkgs; [ ccache ninja + llvmPackages_19.clang-tools ]; cmakeFlags = self.packages.${system}.prismlauncher-unwrapped.cmakeFlags ++ [