fix(codegen): drop grpcio-tools, stop committing generated code

The codegen only ever needed a protoc binary, but every entry point installed
grpcio-tools to get one. That drags in the grpcio C extension, which has no
Windows/ARM64 wheel and falls back to building from source there, so the ARM64
job died with "Failed building wheel for grpcio" -> "protoc not found".

tools/codegen_toolchain.py resolves the toolchain instead: protoc from $PROTOC,
PATH, a cache, grpc_tools when already installed, or a pinned checksum-verified
protoc release unpacked into .codegen-tools/; protobuf and pyyaml from the
calling interpreter or a cached virtualenv it re-execs into (distro Pythons
refuse `pip install` under PEP 668). All four build scripts and all three CI
jobs are now just `python tools/run_codegen.py`, with no pip lines around it.

tools/config_metadata_pb2.py was the one generated file checked into git. The
orca.* option extensions are now read out of the descriptor set, which already
carries config_metadata.proto via --include_imports, so nothing is generated
into the tree -- and the protobuf>=6.33.5,<7 CI pin goes away with it, since it
only existed to satisfy gencode's hard ValidateProtobufRuntimeVersion check.
Generated C++ verified byte-identical under upb and the pure-Python protobuf
runtime (what win/arm64 installs), and under both grpc_tools' and standalone
protoc.

Also fixed:
- build_release_macos.sh still passed -DPython3_EXECUTABLE=<codegen venv>,
  pointing the bundled *embed* interpreter at the codegen environment -- the
  same confusion fae4b124 fixed on the CMake side.
- Tab.cpp #includes TabLayout_generated.cpp but had no dependency on
  codegen_config, so an incremental build after a .proto edit could compile it
  while the file was being rewritten. libslic3r already had this guard.
- ConfigCodegen.cmake now probes with `codegen_toolchain.py --check` (which
  never downloads or installs), prefers a host interpreter over the embed one,
  and lets a fresh clone generate at configure time instead of erroring out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
ExPikaPaka
2026-07-28 12:53:05 +02:00
parent fae4b1241b
commit 2f67e46047
16 changed files with 446 additions and 188 deletions

View File

@@ -2,7 +2,8 @@
#
# Generates C++ source files from protobuf schema definitions.
# Generated files live in src/slic3r/GUI/generated/ and are gitignored.
# Run 'python tools/run_codegen.py' (requires grpcio-tools or protoc) to regenerate.
# Run 'python tools/run_codegen.py' to regenerate; it resolves protoc and the Python
# packages it needs itself (see tools/codegen_toolchain.py).
#
# Targets:
# codegen_config - Custom target to regenerate C++ from .proto files
@@ -21,24 +22,26 @@ set(_generated_marker "${CMAKE_SOURCE_DIR}/src/slic3r/GUI/generated/PrintConfigD
# The main CMakeLists forces Python3_EXECUTABLE to the *bundled embed* interpreter (used for
# the in-app Python plugin runtime). That interpreter has neither protoc nor the protobuf /
# pyyaml packages, and for cross-compiled targets it may not even be the host architecture — so
# it cannot run tools/run_codegen.py. In CI the generated sources are produced by a dedicated
# pre-build "Install codegen tools and generate config sources" step; developers run
# tools/run_codegen.py themselves. Only wire up (re)generation when the interpreter really has
# the toolchain, otherwise fall back to the already-generated files.
# it cannot run tools/run_codegen.py. Prefer a host interpreter, which tools/run_codegen.py can
# bootstrap the toolchain into.
#
# ORCA_CODEGEN_PYTHON lets a build explicitly point at an interpreter that has the tools
# (independent of the embed interpreter). Falls back to Python3_EXECUTABLE.
# ORCA_CODEGEN_PYTHON lets a build explicitly point at the interpreter to use.
if(NOT ORCA_CODEGEN_PYTHON)
set(ORCA_CODEGEN_PYTHON "${Python3_EXECUTABLE}")
find_program(_orca_host_python NAMES python3 python)
if(_orca_host_python)
set(ORCA_CODEGEN_PYTHON "${_orca_host_python}")
else()
set(ORCA_CODEGEN_PYTHON "${Python3_EXECUTABLE}")
endif()
endif()
# --check answers "can this interpreter regenerate right now?" (protobuf + pyyaml importable
# and a protoc already resolvable). It never downloads or installs, so wiring up the build-time
# regeneration below never turns a build into a network operation.
set(_codegen_usable FALSE)
if(ORCA_CODEGEN_PYTHON)
# Needs the protobuf python runtime (config_metadata_pb2) plus a protoc (standalone or
# grpc_tools.protoc). Probe the interpreter for both.
execute_process(
COMMAND ${ORCA_CODEGEN_PYTHON} -c
"import shutil, importlib.util, google.protobuf; import sys; sys.exit(0 if (shutil.which('protoc') or importlib.util.find_spec('grpc_tools')) else 1)"
COMMAND ${ORCA_CODEGEN_PYTHON} "${CMAKE_SOURCE_DIR}/tools/codegen_toolchain.py" --check
RESULT_VARIABLE _codegen_probe
OUTPUT_QUIET ERROR_QUIET
)
@@ -47,27 +50,28 @@ if(ORCA_CODEGEN_PYTHON)
endif()
endif()
# If generated files are missing (fresh clone) and we can run codegen, do it now at configure
# time so a plain cmake configure + build works without a separate pre-build step.
# If generated files are missing (fresh clone), run the codegen now at configure time so a plain
# cmake configure + build works without a separate pre-build step. Unlike the build-time
# regeneration above this is allowed to fetch the toolchain — there is nothing to build without it.
if(NOT EXISTS "${_generated_marker}")
if(_codegen_usable)
set(_codegen_result 1)
if(ORCA_CODEGEN_PYTHON)
message(STATUS "Config codegen: generated files missing — running codegen now...")
execute_process(
COMMAND ${ORCA_CODEGEN_PYTHON} "${CMAKE_SOURCE_DIR}/tools/run_codegen.py" --no-validate
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE _codegen_result
)
if(NOT _codegen_result EQUAL 0)
message(FATAL_ERROR "Config codegen failed. Install grpcio-tools: pip install grpcio-tools")
endif()
message(STATUS "Config codegen: generated files created successfully")
else()
message(FATAL_ERROR
"Config codegen: generated files are missing and no usable codegen toolchain was found.\n"
"Generate them first with an interpreter that has protoc + protobuf, e.g.:\n"
" pip install grpcio-tools pyyaml && python tools/run_codegen.py\n"
"or pass -DORCA_CODEGEN_PYTHON=<python-with-tools>.")
endif()
if(NOT _codegen_result EQUAL 0)
message(FATAL_ERROR
"Config codegen: generated files are missing and could not be generated.\n"
"Run it manually with a host Python:\n"
" python tools/run_codegen.py\n"
"or pass -DORCA_CODEGEN_PYTHON=<python>. Offline builds can point at an installed\n"
"protoc with PROTOC=<path>.")
endif()
message(STATUS "Config codegen: generated files created successfully")
endif()
set(CONFIG_PROTO_DIR "${CMAKE_SOURCE_DIR}/src/PrintConfigs")
@@ -101,7 +105,7 @@ set(CONFIG_PROTO_FILES
)
if(_codegen_usable)
# Single command: run_codegen.py handles protoc/grpcio-tools detection internally.
# Single command: run_codegen.py resolves protoc itself.
# Proto files → generated .cpp files. Runs automatically when any .proto changes.
add_custom_command(
OUTPUT ${CONFIG_GENERATED_SOURCES}