@@ -918,10 +918,21 @@ def _write_cmake_version_file(self, dst_root: str) -> None:
918918 # 1.5.0+cpu)` is rejected by CMake as an invalid argument, so a consumer could
919919 # not name the version this file reports. Strip to the dotted numbers CMake
920920 # can compare, which is what a consumer asks for in practice.
921- cmake_version = re .match (r"\d+(?:\.\d+)*" , Version .string ())
922- contents = contents .replace (
923- "@EXECUTORCH_VERSION@" , cmake_version .group (0 ) if cmake_version else "0"
924- )
921+ # Two variables with different jobs. CMake compares PACKAGE_VERSION, so it has to be the
922+ # numeric release and nothing else. EXECUTORCH_BUILD_VERSION is documented as the full
923+ # version, which is what a consumer pinning an exact build compares against, so filling it
924+ # from the numeric part would make that comparison pass against a different wheel.
925+ build_version = Version .string ()
926+ cmake_version = re .match (r"\d+(?:\.\d+)*" , build_version )
927+ if not cmake_version :
928+ # A version file claiming 0 would satisfy every version request, which is worse than
929+ # not building at all.
930+ raise RuntimeError (
931+ f"cannot derive a numeric CMake version from { build_version !r} ; the version file "
932+ "would claim 0 and satisfy every version request"
933+ )
934+ contents = contents .replace ("@EXECUTORCH_VERSION@" , cmake_version .group (0 ))
935+ contents = contents .replace ("@EXECUTORCH_BUILD_VERSION@" , build_version )
925936 self .mkpath (os .path .dirname (destination ))
926937 with open (destination , "w" ) as handle :
927938 handle .write (contents )
0 commit comments