From c53570192f1c7b096701ec8c3bda104a1329a8d5 Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Fri, 3 Apr 2026 08:24:50 +0000 Subject: [PATCH] switch to Ninja+ccache, add clang/lld fast build profile - CMakePresets.json: add 'fast' preset (clang+lld+ccache) - .gitignore: generalize build/ to build*/, add CMakeUserPresets.json - CMakeUserPresets.json: untrack (conan-generated, now gitignored) - src/Core/Archives.h: remove redundant 'using basic_xml_iarchive::load_override' in xml_iarchive; caused ambiguous overload with clang (diamond inheritance) - src/Core/Object.cpp: remove invalid explicit instantiations of non-template virtual Object::serialize (GCC extension, clang rejects) - README.md, CLAUDE.md: document GCC and LLVM/clang build workflows Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 3 ++- CLAUDE.md | 14 +++++++++++++- CMakePresets.json | 18 +++++++++++++++++- CMakeUserPresets.json | 9 --------- README.md | 36 +++++++++++++++++++++++++++++++----- src/Core/Archives.h | 5 +++-- src/Core/Object.cpp | 8 -------- 7 files changed, 66 insertions(+), 27 deletions(-) delete mode 100644 CMakeUserPresets.json diff --git a/.gitignore b/.gitignore index f51005d..00488c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ CMakeFiles/ -build/ +build*/ .cache/ +CMakeUserPresets.json build_warnings*.log final_build.log cmake_configure.log diff --git a/CLAUDE.md b/CLAUDE.md index 576bfeb..7a59f7d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -12,7 +12,7 @@ export MAMBA_ROOT_PREFIX="/home/share/micromamba" eval "$(/home/share/micromamba/bin/micromamba shell hook --shell bash)" micromamba activate mutom -# Configure (from repo root, using Conan preset) +# Configure (from repo root, using Conan preset — uses Ninja + ccache) cmake --preset conan-release # Build everything @@ -40,6 +40,18 @@ conan install . --output-folder=build --build=missing cmake --preset conan-release ``` +### Build acceleration (already configured) +- **Ninja** generator — used automatically via the conan default profile (`~/.conan2/profiles/default`) +- **ccache** — enabled via `CMAKE_CXX_COMPILER_LAUNCHER=ccache`; cached rebuilds are nearly instant (~0.3s vs ~25s cold) +- **Clang 22 + lld** profile available (`~/.conan2/profiles/fast`) but blocked by template overload ambiguities in `src/Core/Archives.h` that need fixing for full compatibility + +To reconfigure with the fast profile once Archives.h is fixed: +```bash +conan install . --output-folder=build --build=missing --profile=fast +cmake -B build -G Ninja -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release +cmake --build build -j$(nproc) +``` + ## Architecture **uLib** is a C++ framework for Cosmic Muon Tomography (CMT), structured as layered shared libraries: diff --git a/CMakePresets.json b/CMakePresets.json index 99c234f..7ac98c2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -11,6 +11,22 @@ "CMAKE_BUILD_TYPE": "Debug", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" } + }, + { + "name": "fast", + "displayName": "Fast build: Ninja + clang + ccache", + "description": "Uses Ninja generator, clang/lld compiler, and ccache", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=lld", + "CMAKE_SHARED_LINKER_FLAGS": "-fuse-ld=lld", + "CMAKE_CXX_COMPILER_LAUNCHER": "ccache", + "CMAKE_C_COMPILER_LAUNCHER": "ccache" + } } ] -} \ No newline at end of file +} diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json deleted file mode 100644 index 945b382..0000000 --- a/CMakeUserPresets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 4, - "vendor": { - "conan": {} - }, - "include": [ - "build/CMakePresets.json" - ] -} \ No newline at end of file diff --git a/README.md b/README.md index b765451..35311d0 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,11 @@ conda activate mutom ### Configure and Build -1. **Configure Conan profile (if you haven't yet on your machine):** +#### Standard build (GCC + Ninja + ccache) + +The default conan profile uses **Ninja** as the generator and **ccache** for compiler caching, dramatically speeding up incremental rebuilds. + +1. **Configure Conan profile (first time only):** ```bash conan profile detect ``` @@ -51,17 +55,39 @@ conan profile detect conan install . --output-folder=build --build=missing ``` -3. **Configure the project with CMake:** +3. **Configure with CMake:** ```bash cmake --preset conan-release ``` -*(Alternatively: `cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release`)* -4. **Build the project:** +4. **Build:** ```bash -cmake --build build -j10 +cmake --build build -j$(nproc) ``` +#### LLVM/Clang build (clang + lld + ccache — fastest) + +A `fast` conan profile is provided that uses **clang**, **lld** (LLVM linker), and **ccache**. Install them into your environment first: + +```bash +micromamba install -n mutom -y clang clangxx lld -c conda-forge +``` + +Then build using the `fast` profile: + +```bash +conan install . --output-folder=build --build=missing --profile=fast +cmake -B build -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Release +cmake --build build -j$(nproc) +``` + +The `fast` profile is defined at `~/.conan2/profiles/fast` and sets: +- `CMAKE_C_COMPILER=clang` / `CMAKE_CXX_COMPILER=clang++` +- `CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld` +- `CMAKE_CXX_COMPILER_LAUNCHER=ccache` + ### Make python package ```bash diff --git a/src/Core/Archives.h b/src/Core/Archives.h index 1d40396..cc0496c 100644 --- a/src/Core/Archives.h +++ b/src/Core/Archives.h @@ -347,8 +347,6 @@ public: xml_iarchive(std::istream &is, unsigned int flags = 0) : xml_iarchive_impl(is, flags) {} - using basic_xml_iarchive::load_override; - // Anything not an attribute should be a name value pair as nvp or hrp typedef boost::archive::detail::common_iarchive detail_common_iarchive; @@ -366,6 +364,9 @@ public: // class_name_type can't be handled here as it depends upon the // char type used by the stream. So require the derived implementation. // derived in this case is xml_iarchive_impl or base .. + // Note: using base::load_override covers all basic_xml_iarchive overloads + // transitively, so a separate 'using basic_xml_iarchive::load_override' + // is redundant and creates ambiguity with clang. using base::load_override; void load_override(const char *str) { diff --git a/src/Core/Object.cpp b/src/Core/Object.cpp index 0cf37ce..01d8690 100644 --- a/src/Core/Object.cpp +++ b/src/Core/Object.cpp @@ -114,14 +114,6 @@ void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); } template void Object::save_override(ArchiveT &ar, const unsigned int version) {} -// Explicitly instantiate for all uLib archives -template void Object::serialize(Archive::xml_oarchive &, const unsigned int); -template void Object::serialize(Archive::xml_iarchive &, const unsigned int); -template void Object::serialize(Archive::text_oarchive &, const unsigned int); -template void Object::serialize(Archive::text_iarchive &, const unsigned int); -template void Object::serialize(Archive::hrt_oarchive &, const unsigned int); -template void Object::serialize(Archive::hrt_iarchive &, const unsigned int); -template void Object::serialize(Archive::log_archive &, const unsigned int); //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////