Chore(core-debug): debugged utils to hide std::cout output from production builds - #524
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Hi. I'm sorry for letting you implement all of this and then changing my mind about some things. That's just how it goes sometimes. :(
Please see this conversation with ChatGPT - it shows how to:
- Manage spdlog via CMake, which is much safer than macros,
- Enforce the no console printing rule more effectively via clang-tidy
Please will you also update it to ensure that console logging is always off in Release mode unless the user explicitly passed a flag to enable it.
Additionally, why did you update the Dawn submodule?
This is good work, though. Thank you!
|
Hi @Ryan-Millard , no worries at all. Regarding Dawn, it likely got updated accidentally when I ran Let me ask you again, you want these right?
|
Maybe reset
Yes.
Yes. I think you should throw an error when the use the enable logging flag and explain in the error that it is discouraged for release versions. Thereafter, create another flag that is explicitly for release logging and add it to the error message I mentioned. That will keep things clean and communicate everything well.
Yes. |
|
Yes please revert changes to Dawn. That can really break all the webgpu stuff |
|
@Krasner, maybe we can implement this in your upcoming PR. |
No let's keep this as a separate PR. |
That's not what I meant.😅😅 I should've explained it better. I meant that we should use spdlog in your PR once this is merged. |
Haha in that case yes! |
|
@Prachi-Gupta2808 in CMakeLists.txt you need something like this: add_compile_definitions(SPDLOG_USE_STD_FORMAT)
add_compile_definitions(
$<$<CONFIG:Debug>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_OFF>
)in each file with logging you will need: this way when the CMAKE_BUILD_TYPE=Release none of the debug prints will be compiled. |
@Krasner, I think this would be better since we could build with settings that are not add_compile_definitions(SPDLOG_USE_STD_FORMAT)
add_compile_definitions(
$<$<CONFIG:Release>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_OFF>
$<$<NOT:$<CONFIG:Release>>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG>
)I flipped it around to turn off in release and be on when not in release mode. |
I'll let @Prachi-Gupta2808 implement this (and revert the dawn submodule change :) ) |
|
@Ryan-Millard do we have any command like "validatepr" which can check formatting or lint checks before we raise a PR. if not can we implement this? |
Run |
There's also |
|
Hey @Prachi-Gupta2808! Could you review this PR when you get a chance? It adds a configurable compile-time log level for the core (the thing behind the spdlog work you did - this should supersede/unblock that, so it's worth checking it fits what you had in mind). What it does
How to test my changes # C++: Release build with logs — the new headline combo
just clean cpp
just build-c-cpp Release TRACE
just console-cpp test.jpg # should show trace/debug lines
# Confirm stripping still works
just build-c-cpp Release OFF
just console-cpp test.jpg # no spdlog output at all
# Python (note: uv hides the cmake output; use -v if you want to see the level confirmation)
just build-py Release INFO
just console-py test.jpg
# JS/wasm — Debug should now work in the browser again
just build-packages-js Debug
just react-js start # upload an image, no more SyntaxErrorArgs are positional (just quirk - Also a small quality-of-life thing you might like: Thanks! |
ripgrep exits 1 when no matches are found and 0 on matches, so the check failed on a clean tree and passed when violations existed. Handle the three exit codes explicitly (0 = violations -> fail with an error annotation, 1 = clean -> pass, 2+ = rg error -> propagate) instead of relying on the raw exit status under bash -e.
The explicit sdist manifest introduced when trimming the Dawn tarball never covered third_party/spdlog, so wheels built from the sdist (the path CI and plain `uv build` take, unlike `uv sync` which builds from the working tree) failed at configure: core's add_subdirectory pointed at a directory absent from the archive. Generalize the third_party excludes to recursive gitwildmatch patterns (**/.git, **/build/, **/test(s)/, ...), replacing the per-path Dawn entries. This also sweeps the nested submodule gitlinks under dawn/third_party that the old excludes never caught. The vk-gl-cts rationale from PR Ryan-Millard#562 still applies; it is now covered by the **/test/ pattern. Add wheel.license-files so the wheel's dist-info carries license texts for the statically linked third-party code (spdlog, Dawn and its vendored dependencies) alongside our own. Verified by building the wheel from the sdist (uv build) and inspecting the archive for spdlog, absence of .git entries, and collected licenses.
Replace the Node-based clang-format wrapper (scripts/format-cpp.js) with
Python entry points in a new img2num_dev_scripts workspace member:
- scripts/py/{lint_cpp,format_cpp}.py exposed as `uv run lint-cpp` /
`uv run format_cpp`, with clang-tidy/clang-format 22.1.8 pinned as
package dependencies instead of a root lint group
- lint_cpp resolves TUs against one or more compile databases (-p,
repeatable), verifies the clang-tidy config up front, skips files
absent from every database with a warning, and serializes --fix runs
to avoid concurrent header rewrites
- img2num_root.py locates the repo root by marker files so scripts work
from any CWD
Config fixes shaken out by the new entry points:
- .clang-tidy: restore identifier-length ignore patterns; split
FunctionCase (snake_case free functions) from MethodCase (camelCase
methods)
- .clang-format: Standard c++20 -> c++17 to match the core's actual
language level
Remaining C++ diffs are mechanical reformatting from re-running
clang-format 22 (braced-init closing brace placement, include ordering,
macro line-length wrapping); no functional changes.
- Rename eslint/eslint:fix to lint:js/lint:js:fix - Add lint, lint:fix, lint:cpp, lint:cpp:fix meta-scripts using pnpm parallel regex dispatch (scoped to root via --filter=.) - Restore format:check as parallel dispatch of cpp/js check scripts; format_cpp now takes --fix for writes, default is check-only - Update CI to use lint:js (lint:cpp pending initial C++ format commit) - Remove no-raw-debug-output workflow (superseded by clang-tidy via lint:cpp)
14b0bd8 to
906a509
Compare
The Python bindings were configured by scikit-build-core in a throwaway
temp directory, so bindings/py/src/img2num_pybind.cpp never had a usable
compile_commands.json and was silently skipped by lint-cpp.
- Set tool.scikit-build.build-dir = "build-py/{wheel_tag}" so the CMake
tree (and its exported compile database) survives the build. The
{wheel_tag} placeholder keeps cibuildwheel's per-Python builds from
clobbering each other's caches.
- Teach lint_cpp to auto-discover all databases (build-c-cpp/, legacy
build/, build-py/*/) and lint each TU against the first database that
contains it. Explicit -p flags still override discovery.
- Warn (instead of failing) on TUs absent from every database, e.g.
bindings/js/src/wasm_wrapper.c, whose Emscripten flags clang-tidy
can't consume.
- Add build-py/ to .gitignore.
img2num_pybind.cpp is now linted for the first time (passes clean).
Note: the database may retain a stale include path from uv's isolated
build env; harmless, since compilers skip nonexistent -I directories and
pybind11 headers resolve from .venv instead. Rebuilding with
`just build py` refreshes the database if resolution ever breaks.
bindings/js/src/wasm_wrapper.c was skipped because emcc injects its sysroot include paths inside the compiler driver, so they never appear in compile_commands.json and clang-tidy fails on the first standard-library include when replaying the recorded command. - Locate the Emscripten sysroot via $EMSDK, falling back to `em-config CACHE`, and pass it per-TU as --extra-arg=-isystem for files owned by build-wasm/. Native databases are unaffected. - Add build-wasm/ to auto-discovery, ordered last so TUs built for both native and wasm targets keep their native database mapping. - Degrade gracefully when no sysroot is found: build-wasm/ is excluded with a warning during discovery, but an explicit `-p build-wasm` is a hard error rather than a silent no-op. - Cache the sysroot lookup so em-config runs at most once across worker threads.
The build-docs job runs on a submodule-less checkout and consumes prebuilt wasm artifacts from the cmake-build job. But building the docs triggers packages/js's full `build`, whose prebuild hook runs `just build js` -> emcmake, which dies on the missing third_party/spdlog submodule. (The job's explicit `build:browser` step never hit this: pnpm pre-hooks match exact script names, so only the aggregate `build` has a prebuild.) Guard the prebuild behind IMG2NUM__CI_YML__PACKAGES_JS__SKIP_PREBUILD and set it on the Build Docusaurus step, so the Vite builds run against the downloaded build-wasm/ artifacts instead of regenerating them. Local `pnpm build` is unchanged (var unset -> full build runs).
This reverts commit 6e3dc31.
The prebuild script invoked `just`, which isn't installed in CI and would rebuild WASM with default flags, clobbering the workflow's explicit CMake configuration. The dependency is already orchestrated by `just build packages-js` locally and by the workflow's Configure/Build steps in CI, so the hook was redundant in both contexts (and a no-op under pnpm's default lifecycle settings). In its place, vite.config.js now fails fast at config time when build-wasm/<glue> is missing, replacing the cryptic "@wasm" alias resolution error with an actionable message. The closeBundle check in copyWasmPlugin remains for its narrower case: glue present without its sibling .wasm (mixed SINGLE_FILE states). Also: - hoist glueDir/outDir/WASM_BUILD_HINT as single sources of truth (fixes the stale "pnpm build:wasm" remediation hint) - gate wasmUrlPlugin and cjsWebgpuGuard at the plugins array instead of returning no-op plugin objects - document that LITERAL/MANGLED/mangledRe are intentionally not derived from one another
|
These failing builds are tolerable.
|
…sting" This reverts commit c85c987.
Changes & Reason
Changes
std::coutdebug output in the GPU source files with the project's debug logging macros.std::cout/std::cerrdebug statements.internal/debug.hincludes.std::coutandstd::cerrusage in C++ files (excludingthird_party/andexample-apps/).Reason
This change ensures that debug logging goes through a centralized logging system instead of raw console output. It also prevents accidental debug prints from being committed in the future by enforcing the rule through CI.
Related Issues
Fixes: #240
Testing & Verification
std::cout/std::cerrstatements.Additional Resources
N/A