From e31e5c3caf8efc9b4d811236286f0d05f3e7c92b Mon Sep 17 00:00:00 2001 From: John Hoy Date: Sun, 26 Jul 2026 21:20:24 -0400 Subject: [PATCH] EDGEML-14581 - Fix copy_headers to use build-time GLOB via cmake -P [Why] The previous aie_codegen_setup_build_include_layout() implementation collected headers at cmake configure time using file(GLOB CONFIGURE_DEPENDS) then copied or symlinked each one via configure_file COPYONLY or file(CREATE_LINK). The resolved file paths were baked into the generated build system (MSBuild .rule files under the Visual Studio generator) at configure time. In CI environments where the build directory is reused across runs, stale .rule files from a prior configure can contain paths that no longer exist or that point through defunct filesystem junctions, triggering MSB8066 errors and breaking incremental builds without requiring a full reconfigure. [How] Replace the configure-time header materialization with a build-time add_custom_target(copy_headers ALL) that invokes a new cmake -P script (cmake/CopyHeaders.cmake). The script GLOBs headers and copies them using file(COPY_FILE ... ONLY_IF_DIFFERENT) at build time, so the generated .rule file contains only stable variable-expanded paths that remain valid across build-directory reuse. The aie_codegen target gains an add_dependencies(... copy_headers) link so headers are always present before compilation begins. The AieCodegenHeaders.cmake module is retained for install-time use by AieCodegenInstall.cmake. Signed-off-by: John Hoy Co-authored-by: Claude --- src/cmake/AieCodegenIncludes.cmake | 34 ++++++++++++++---------------- src/cmake/CopyHeaders.cmake | 29 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 src/cmake/CopyHeaders.cmake diff --git a/src/cmake/AieCodegenIncludes.cmake b/src/cmake/AieCodegenIncludes.cmake index 2be2c9d4..e86e12e2 100644 --- a/src/cmake/AieCodegenIncludes.cmake +++ b/src/cmake/AieCodegenIncludes.cmake @@ -3,28 +3,25 @@ # SPDX-License-Identifier: MIT ############################################################################### -include(${CMAKE_CURRENT_LIST_DIR}/AieCodegenHeaders.cmake) - -function(_aie_codegen_materialize_header source dest) - file(CREATE_LINK "${source}" "${dest}" SYMBOLIC RESULT _link_result) - if(NOT _link_result EQUAL 0) - configure_file("${source}" "${dest}" COPYONLY) - endif() -endfunction() - function(aie_codegen_setup_build_include_layout) set(_inc_root "${CMAKE_CURRENT_BINARY_DIR}/include") file(MAKE_DIRECTORY "${_inc_root}/aie_codegen_inc") - aie_codegen_collect_headers(_headers) - foreach(_hdr IN LISTS _headers) - get_filename_component(_name "${_hdr}" NAME) - _aie_codegen_materialize_header("${_hdr}" "${_inc_root}/aie_codegen_inc/${_name}") - endforeach() - - _aie_codegen_materialize_header( - "${CMAKE_CURRENT_SOURCE_DIR}/aie_codegen.h" - "${_inc_root}/aie_codegen.h") + # Headers are copied at build time via a cmake -P script so that GLOB runs + # fresh on each build. Configure-time copies bake resolved paths into the + # generated build rules; stale rules cause MSB8066 failures in CI when a + # prior build directory is reused after a source-tree relocation. + add_custom_target(copy_headers ALL + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/aie_codegen.h" + "${_inc_root}/aie_codegen.h" + COMMAND ${CMAKE_COMMAND} + "-DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}" + "-DREGDB_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../aie-regdb/globalparams" + "-DDST_DIR=${_inc_root}/aie_codegen_inc" + -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyHeaders.cmake" + COMMENT "Syncing headers to build include directory" + ) endfunction() function(aie_codegen_apply_include_directories target) @@ -35,4 +32,5 @@ function(aie_codegen_apply_include_directories target) $ $ ) + add_dependencies(${target} copy_headers) endfunction() diff --git a/src/cmake/CopyHeaders.cmake b/src/cmake/CopyHeaders.cmake new file mode 100644 index 00000000..cc778863 --- /dev/null +++ b/src/cmake/CopyHeaders.cmake @@ -0,0 +1,29 @@ +############################################################################### +# Copyright (C) 2022-2026 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: MIT +############################################################################### +# Build-time script: invoked via cmake -P by the copy_headers custom target. +# Runs GLOB at build time so that paths are resolved fresh on each build rather +# than being baked into generated build rules at configure time. +# +# Expected variables (passed via -D on the cmake -P command line): +# SRC_DIR - aie-codegen/src source directory +# REGDB_DIR - aie-regdb/globalparams source directory +# DST_DIR - destination include/aie_codegen_inc directory + +foreach(_var SRC_DIR REGDB_DIR DST_DIR) + if(NOT DEFINED ${_var}) + message(FATAL_ERROR "CopyHeaders.cmake: required variable ${_var} is not defined") + endif() +endforeach() + +file(GLOB_RECURSE _hdrs + "${SRC_DIR}/*/*.h" + "${SRC_DIR}/*/*/*.h" + "${REGDB_DIR}/*.h" +) + +foreach(_hdr IN LISTS _hdrs) + get_filename_component(_name "${_hdr}" NAME) + file(COPY_FILE "${_hdr}" "${DST_DIR}/${_name}" ONLY_IF_DIFFERENT) +endforeach()