From 8f4838866609677f545e6f18ce8bfaf32d66f957 Mon Sep 17 00:00:00 2001 From: Mark Schaller Date: Sat, 26 Sep 2026 02:30:42 -0400 Subject: [PATCH] Tell the agent to map the build type to flags, not to a compilation mode The skill never mentioned CMAKE_BUILD_TYPE or --compilation_mode, and its canonicalization text called -O*/-g* "never your concern" (reworded in the levels commit). Agents therefore map the concept, Release to `-c opt`, and lose the number: CMake's Release is -O3 -DNDEBUG, Bazel's opt is -O2; CMake's Debug is -g, Bazel's default fastbuild has neither. Measured in any2bazel-lab: all nine migrations of pono, with and without the skill, wrote `build --compilation_mode=opt` as the counterpart of Release, several saying so in a comment on the line above, and eight of the nine compile at -O2 against a reference at -O3; the ninth added `build --copt=-O3` and matched. lensfun's CMakeLists.txt defaults the build type to Debug when none is given; no lensfun migration set a compilation mode, so every one dropped -g from all 40 TUs. Adds a short "Build type" section to docs/REFERENCE-cmake.md, under a new "Writing the BUILD files" heading that "Create initial BUILD.bazel files" points to: the two mappings that differ, the reminder that a project can set its own default build type, where to read the reference's actual level (diff.json's levels, or the cache), and the two .bazelrc lines that pin it. It also says that opt adds -DNDEBUG and so turns off assertions the reference may keep (diff.json's ndebug shows it), and that `build --copt=-UNDEBUG` undoes only the toolchain's -DNDEBUG, not one a rule passes in its copts, which come later on the command line. In the lab's later runs with this change, pono kept -O3, lensfun kept -g, and CMake's sources, whose reference sets no build type, gained neither -O2 nor NDEBUG in three runs (two earlier runs had added both). Lab-Proposal: P18 Co-Authored-By: Claude Opus 5.5 --- SKILL.md | 5 ++++- docs/REFERENCE-cmake.md | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SKILL.md b/SKILL.md index 372974d..b2e3912 100644 --- a/SKILL.md +++ b/SKILL.md @@ -256,7 +256,7 @@ changes what "migrated" means, so surface it when first diff; the test-inclusive configure for [Diff tests](#diff-tests) is recorded apart, as `test_configure_command`. -### Create initial BUILD.bazel files +### Create initial BUILD.bazel files {#create-build-files} Read `model..json`. For each production target emit a `cc_library` / `cc_binary` with `srcs`, `hdrs`, `copts`, `defines`, `includes`, `deps`. Library @@ -270,6 +270,9 @@ rather than recalled). Put `common --check_direct_dependencies=error` in the generated `.bazelrc` so a declared version that MVS overrides fails the build instead of being a warning nobody reads. +The reference guide covers what is specific to translating its build system +(for CMake: the build type). + ### Main migration loop {#main-migration-loop} #### Extract the Bazel action graph {#extract-bazel-graph} diff --git a/docs/REFERENCE-cmake.md b/docs/REFERENCE-cmake.md index ce6227a..db36825 100644 --- a/docs/REFERENCE-cmake.md +++ b/docs/REFERENCE-cmake.md @@ -46,6 +46,23 @@ python3 "$SKILL_DIR/scripts/extract_cmake.py" model.cmake.js The project flags passed to `cmake` define the platform/options the Bazel aquery must mirror. +## Writing the BUILD files + +What is specific to CMake when +[creating the BUILD files](../SKILL.md#create-build-files). + +### Build type + +`--compilation_mode` is not a translation of `CMAKE_BUILD_TYPE`: Release is +`-O3 -DNDEBUG` where Bazel's `opt` is `-O2 -DNDEBUG`, and Debug is `-g` where +Bazel's default `fastbuild` has neither. A project may set its own default +build type in `CMakeLists.txt` even when none is passed. Read the reference's +level (`levels` in `diff.json`, or `CMAKE__FLAGS_` in the cache) +and pin it in `.bazelrc`, e.g. `build -c opt` plus `build --copt=-O3`. `opt` +also turns assertions off where the reference keeps them (`ndebug` in +`diff.json`); `build --copt=-UNDEBUG` undoes the toolchain's `-DNDEBUG`, not +one in a rule's `copts`. + ## CMake-specific comparison notes - **Target names** in `target_map` and `exclude_targets` keys are CMake target