add compile_commands.json#24
Merged
Merged
Conversation
Extract compute_cxxflags() and compute_cflags() from emit_ninja_string() into standalone helper functions in the anonymous namespace. These helpers encapsulate all flag computation logic (PIC, sysroot, binutils, musl opt, include dirs, user flags) and will be reused by compile_commands.json generation in a follow-up commit. The ninja output is byte-identical to before the refactoring.
Automatically emit a Clang-compatible compile_commands.json to the target/ directory on every mcpp build. The JSON includes all compile units (project + dependencies) with exact compiler commands, matching the flags used by the ninja backend. - Add json_escape() helper for JSON string escaping - Add emit_compile_commands_json() using shared flag helpers - Wire into NinjaBackend::build() after build.ninja generation
Architecture redesign on top of PR mcpp-community#24's compile_commands.json feature: 1. `src/build/flags.cppm` (NEW) — shared compile/link flag computation. One definition consumed by both ninja backend and compile_commands emitter (and future backends). Eliminates the duplicated compute_cxxflags/compute_cflags functions. 2. `src/build/compile_commands.cppm` (NEW) — generates compile_commands.json using nlohmann::json (no manual string escaping). Uses `arguments` array format (clangd recommended). Writes to <projectRoot>/compile_commands.json for zero-config clangd. Incremental: skips write if content unchanged. 3. `src/libs/json.cppm` + `src/libs/json/json.hpp` (NEW) — nlohmann/json single-header library wrapped as C++23 module, copied from openxlings/xlings. MIT license. 4. `src/build/ninja_backend.cppm` — slimmed: imports flags.cppm, delegates compile_commands to its module, removes ~200 lines of duplicated flag computation. 5. `.agents/docs/2026-05-12-compile-commands-design.md` — design doc. 6. `.gitignore` — add compile_commands.json (generated). 7. `mcpp.toml` — add `include_dirs = ["src/libs/json"]` for json.hpp. All code formatted with .clang-format from PR mcpp-community#24.
4 tasks
read_xpkg_lua now tries multiple filename patterns when looking up a package's .lua descriptor in index repos: 1. <full-qualified-name>.lua (old: mcpplibs.cmdline.lua) 2. <short-name>.lua (new: cmdline.lua) 3. compat.<name>.lua (new: compat.gtest.lua) This completes namespace migration support: both install_path (0.0.7) and read_xpkg_lua (0.0.8) handle old and new index layouts. Locally verified: mcpp self-build + tinyhttps + llmapi + cmdline all pass against the migrated mcpp-index (namespace fields + short names + renamed files).
Sunrisepeak
added a commit
that referenced
this pull request
May 11, 2026
Squashed commits: - 13928b0 refactor(build): extract flag construction into shared helpers Extract compute_cxxflags() and compute_cflags() from emit_ninja_string() into standalone helper functions. These helpers encapsulate all flag computation logic and will be reused by compile_commands.json generation. - f9d4f95 feat(build): generate compile_commands.json during build Automatically emit a Clang-compatible compile_commands.json on every mcpp build. The JSON includes all compile units with exact compiler commands, matching the flags used by the ninja backend. - 5c1da99 feat: add .clang-format from mcpp-community/mcpp-style-ref - 9675ea9 refactor(build): extract flags + compile_commands into dedicated modules Architecture redesign: flags.cppm (shared flag computation), compile_commands.cppm (JSON generation via nlohmann/json), json.cppm + json.hpp (nlohmann/json single-header as C++23 module). ninja_backend.cppm slimmed by ~200 lines. - 0134a8b feat: namespace-aware read_xpkg_lua + bump to 0.0.8 read_xpkg_lua now tries multiple filename patterns for package .lua descriptors in index repos. - 2f482b7 ci: bump xlings 0.4.25 → 0.4.30 (sysroot fix for gcc 16.1.0) - eba834d ci: always install pinned xlings (cache may hold stale version)
Sunrisepeak
added a commit
that referenced
this pull request
May 11, 2026
Squashed commits: - 13928b0 refactor(build): extract flag construction into shared helpers Extract compute_cxxflags() and compute_cflags() from emit_ninja_string() into standalone helper functions. These helpers encapsulate all flag computation logic and will be reused by compile_commands.json generation. - f9d4f95 feat(build): generate compile_commands.json during build Automatically emit a Clang-compatible compile_commands.json on every mcpp build. The JSON includes all compile units with exact compiler commands, matching the flags used by the ninja backend. - 5c1da99 feat: add .clang-format from mcpp-community/mcpp-style-ref - 9675ea9 refactor(build): extract flags + compile_commands into dedicated modules Architecture redesign: flags.cppm (shared flag computation), compile_commands.cppm (JSON generation via nlohmann/json), json.cppm + json.hpp (nlohmann/json single-header as C++23 module). ninja_backend.cppm slimmed by ~200 lines. - 0134a8b feat: namespace-aware read_xpkg_lua + bump to 0.0.8 read_xpkg_lua now tries multiple filename patterns for package .lua descriptors in index repos. - 2f482b7 ci: bump xlings 0.4.25 → 0.4.30 (sysroot fix for gcc 16.1.0) - eba834d ci: always install pinned xlings (cache may hold stale version) Co-authored-by: yizhinailong <liufeng.code@outlook.com> Co-authored-by: sunrisepeak <speakshen@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.