Skip to content

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Sep 23, 2025

Silence all stdout from stubgen unless VERBOSE is passed to mlir_generate_type_stubs.

@makslevental makslevental force-pushed the users/makslevental/silence-stubgen branch from 5b89b16 to b247e59 Compare September 23, 2025 19:05
@makslevental makslevental marked this pull request as ready for review September 23, 2025 19:08
@llvmbot llvmbot added the mlir label Sep 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 23, 2025

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

Silence all stdout from stubgen unless VERBOSE is passed to mlir_generate_type_stubs.


Full diff: https://github.com/llvm/llvm-project/pull/160368.diff

2 Files Affected:

  • (modified) mlir/cmake/modules/AddMLIRPython.cmake (+8-2)
  • (modified) mlir/examples/standalone/python/CMakeLists.txt (+1)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index f25595116edca..208cbdd1dd535 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -113,11 +113,12 @@ endfunction()
 #   DEPENDS_TARGET_SRC_DEPS: List of cpp sources for extension library (for generating a DEPFILE).
 #   IMPORT_PATHS: List of paths to add to PYTHONPATH for stubgen.
 #   PATTERN_FILE: (Optional) Pattern file (see https://nanobind.readthedocs.io/en/latest/typing.html#pattern-files).
+#   VERBOSE: Emit logging/status messages during stub generation (default: OFF).
 # Outputs:
 #   NB_STUBGEN_CUSTOM_TARGET: The target corresponding to generation which other targets can depend on.
 function(mlir_generate_type_stubs)
   cmake_parse_arguments(ARG
-    ""
+    "VERBOSE"
     "MODULE_NAME;OUTPUT_DIR;PATTERN_FILE"
     "IMPORT_PATHS;DEPENDS_TARGETS;OUTPUTS;DEPENDS_TARGET_SRC_DEPS"
     ${ARGN})
@@ -152,6 +153,9 @@ function(mlir_generate_type_stubs)
       --include-private
       --output-dir
       "${ARG_OUTPUT_DIR}")
+  if(NOT ARG_VERBOSE)
+    list(APPEND _nb_stubgen_cmd "--quiet")
+  endif()
   if(ARG_PATTERN_FILE)
     list(APPEND _nb_stubgen_cmd "-p;${ARG_PATTERN_FILE}")
     list(APPEND ARG_DEPENDS_TARGETS "${ARG_PATTERN_FILE}")
@@ -166,7 +170,9 @@ function(mlir_generate_type_stubs)
     file(GENERATE OUTPUT "${_depfile}" CONTENT "${_depfiles}")
   endif()
 
-  message(DEBUG "Generating type-stubs outputs ${_generated_type_stubs}")
+  if(ARG_VERBOSE)
+    message(STATUS "Generating type-stubs outputs ${_generated_type_stubs}")
+  endif()
   add_custom_command(
     OUTPUT ${_generated_type_stubs}
     COMMAND ${_nb_stubgen_cmd}
diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt
index d48c5bcdde137..5404128e5fa27 100644
--- a/mlir/examples/standalone/python/CMakeLists.txt
+++ b/mlir/examples/standalone/python/CMakeLists.txt
@@ -92,6 +92,7 @@ if(NOT EXTERNAL_PROJECT_BUILD)
     OUTPUTS "${_core_type_stub_sources}"
     DEPENDS_TARGET_SRC_DEPS "${_core_extension_srcs}"
     IMPORT_PATHS "${StandalonePythonModules_ROOT_PREFIX}/_mlir_libs"
+    VERBOSE
   )
   set(_mlir_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")
 

@makslevental makslevental requested a review from kuhar September 24, 2025 00:30
@makslevental makslevental merged commit 79ad1bf into main Sep 24, 2025
12 checks passed
@makslevental makslevental deleted the users/makslevental/silence-stubgen branch September 24, 2025 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants