@@ -220,3 +220,53 @@ function(bench_add_source_dep target name version)
220220 target_sources (${target} PRIVATE ${impls} )
221221 endif ()
222222endfunction ()
223+
224+ # ── The half that must run BEFORE project() ─────────────────────────────────
225+ #
226+ # `bench_hermetic_payload()` above keys off CMAKE_CXX_COMPILER_ID, which does
227+ # not exist until project() has probed the compiler — and that probe is exactly
228+ # what fails without these flags:
229+ #
230+ # [2/2] .../xim-x-gcc/16.1.0/bin/g++ ... -o cmTC_c87ee
231+ # /usr/bin/ld: cannot find crt1.o: No such file or directory
232+ # /usr/bin/ld: cannot find crti.o: No such file or directory
233+ #
234+ # CMake reports that as "The C++ compiler is not able to compile a simple test
235+ # program", naming neither the sysroot nor the payload. It passed on developer
236+ # boxes because a host crt1.o was findable there and did not on CI.
237+ #
238+ # So this one keys off the compiler PATH, which the caller already has from
239+ # -DCMAKE_CXX_COMPILER. Same flags, same reasoning as the GNU branch above;
240+ # a compiler outside the registry is left alone, exactly as there.
241+ function (bench_hermetic_payload_preproject )
242+ if (NOT CMAKE_CXX_COMPILER OR WIN32 )
243+ return ()
244+ endif ()
245+ get_filename_component (_real "${CMAKE_CXX_COMPILER } " REALPATH )
246+ string (FIND "${_real} " "xpkgs" _pos)
247+ if (_pos EQUAL -1)
248+ return ()
249+ endif ()
250+ # clang carries its own include chain (see the Clang branch above) and does
251+ # not need -B/--sysroot to link a test program; only the gcc payload does.
252+ if (NOT _real MATCHES "g\\ +\\ +$" AND NOT _real MATCHES "gcc$" )
253+ return ()
254+ endif ()
255+ bench_registry_xpkgs (_xpkgs )
256+ bench_newest_package ("${_xpkgs} " "xim-x-binutils" _binutils )
257+ set (_sysroot "${_xpkgs} /../subos/default" )
258+ set (_add "" )
259+ if (_binutils)
260+ string (APPEND _add " -B${_binutils} /bin" )
261+ endif ()
262+ if (IS_DIRECTORY "${_sysroot} " )
263+ string (APPEND _add " --sysroot=${_sysroot} " )
264+ endif ()
265+ if (_add STREQUAL "" )
266+ return ()
267+ endif ()
268+ foreach (_v CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_EXE_LINKER_FLAGS )
269+ set (${_v} "${${_v} }${_add} " PARENT_SCOPE )
270+ endforeach ()
271+ message (STATUS "bench: hermetic payload applied before project()${_add} " )
272+ endfunction ()
0 commit comments