From 82914d32d21d3f0cd98f02cb67fd97b84ce2631d Mon Sep 17 00:00:00 2001 From: "Jonathan B. Coe" Date: Sat, 14 Mar 2026 15:47:03 +0000 Subject: [PATCH 1/2] Fast rebuilds of C/C++ code when needed. Configures `CMake` to use `ccache` for faster C/C++ compilation. Modifies `pyproject.toml` to enable `editable.rebuild` and specify `build-dir` for `scikit-build-core`, ensuring fast, incremental rebuilds when C/C++ sources or project metadata change. --- CMakeLists.txt | 11 +++++++++++ pyproject.toml | 2 ++ 2 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48a45e4b8..061979a6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,17 @@ endif() string(REGEX MATCH "^[0-9]+(\\.[0-9]+)*" CMAKE_NLE_VERSION "${NLE_VERSION}") project(nle VERSION ${CMAKE_NLE_VERSION}) +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + message(STATUS "ccache found, enabling for C and C++") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_FOUND}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_FOUND}") + else() + message(STATUS "ccache not found, proceeding without it") + endif() +endif() + if(CMAKE_BUILD_TYPE MATCHES Debug) message("Debug build.") # Unclear if this is even necessary. `dsymutil rlmain -o rlmain.dSYM` seems to diff --git a/pyproject.toml b/pyproject.toml index d1ff3031e..f6d9640f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,8 @@ cmake.build-type = "Release" cmake.args = ["-DHACKDIR=nle/nethackdir", "-DPYTHON_PACKAGE_NAME=nle"] minimum-version = "build-system.requires" metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +build-dir = "build/{wheel_tag}" +editable.rebuild = true generate = [ { path = "nle/version.py", template = '__version__ = "${version}"' }, ] From 842d289d3d2ad254a5e29e2ca0f7a37d99f96be0 Mon Sep 17 00:00:00 2001 From: "Jonathan B. Coe" Date: Tue, 17 Mar 2026 21:46:46 +0000 Subject: [PATCH 2/2] Add clarifying comment for enabling ccache --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 061979a6d..2036b9c7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,12 +12,13 @@ endif() string(REGEX MATCH "^[0-9]+(\\.[0-9]+)*" CMAKE_NLE_VERSION "${NLE_VERSION}") project(nle VERSION ${CMAKE_NLE_VERSION}) +# Only enable ccache if this is the main project, not a sub-dependency. if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - find_program(CCACHE_FOUND ccache) - if(CCACHE_FOUND) + find_program(CCACHE_EXECUTABLE ccache) + if(CCACHE_EXECUTABLE) message(STATUS "ccache found, enabling for C and C++") - set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_FOUND}") - set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_FOUND}") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}") else() message(STATUS "ccache not found, proceeding without it") endif()