Skip to content

[Minor] log ninja result#584

Merged
tqchen merged 2 commits into
apache:mainfrom
DarkSharpness:minor_log
May 13, 2026
Merged

[Minor] log ninja result#584
tqchen merged 2 commits into
apache:mainfrom
DarkSharpness:minor_log

Conversation

@DarkSharpness
Copy link
Copy Markdown
Contributor

should fix #565

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logging for the ninja build process in python/tvm_ffi/cpp/extension.py by checking the TVM_FFI_LOG_BUILD environment variable. Feedback was provided to improve the robustness of the decoding process by using platform-specific encodings (e.g., 'oem' on Windows) and adding error handling to prevent potential UnicodeDecodeError failures during logging.

Comment thread python/tvm_ffi/cpp/extension.py Outdated
Comment on lines +606 to +610
if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"):
logger.info("ninja build stdout:\n%s", status.stdout.decode("utf-8"))

if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stderr"):
logger.info("ninja build stderr:\n%s", status.stderr.decode("utf-8"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding utf-8 for decoding process output can lead to UnicodeDecodeError on Windows, where the output typically uses the OEM code page. This would cause the build process to fail even if the compilation was successful. It is recommended to use the same encoding logic as the error path and include errors="replace" for robustness. Additionally, caching the environment variable and checking if the output is non-empty before logging improves efficiency and log clarity.

Suggested change
if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"):
logger.info("ninja build stdout:\n%s", status.stdout.decode("utf-8"))
if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stderr"):
logger.info("ninja build stderr:\n%s", status.stderr.decode("utf-8"))
log_build = os.environ.get("TVM_FFI_LOG_BUILD")
encoding = "oem" if IS_WINDOWS else "utf-8"
if log_build in ("1", "stdout") and status.stdout:
logger.info("ninja build stdout:\n%s", status.stdout.decode(encoding, errors="replace"))
if log_build in ("1", "stderr") and status.stderr:
logger.info("ninja build stderr:\n%s", status.stderr.decode(encoding, errors="replace"))

Copy link
Copy Markdown
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit

Comment thread python/tvm_ffi/cpp/extension.py Outdated

raise RuntimeError("\n".join(msg))

if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given it is specific to CPP_EXTENSION, would be useful to do TVM_FFI_CPP_EXTENSION_LOG_BUILD

@tqchen
Copy link
Copy Markdown
Member

tqchen commented May 12, 2026

Thanks @DarkSharpness lgtm modulo minor nit on naming

@tqchen tqchen merged commit d4cfd86 into apache:main May 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add env var to print compiler output in JIT compilation

2 participants