Skip to content

Commit 2af08ff

Browse files
[SYCL] set __SYCL_COMPILER_VERSION from CMake variable or git commit timestamp (#19845)
This PR changes the way CMake sets `__SYCL_COMPILER_VERSION` from using the date of compilation to: - using `-DSYCL_COMPILER_VERSION=...` if set - otherwise, running git to get the timestamp of the latest commit, and using that - falling back to the old behavior if the first two fail See #19692 for the rationale behind this. TL;DR: Make `__SYCL_COMPILER_VERSION` reproducible. Closes #19692.
1 parent 9b938b1 commit 2af08ff

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sycl/CMakeLists.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,33 @@ set(SYCL_EXT_ONEAPI_BACKEND_HIP ${LLVM_HAS_AMDGPU_TARGET})
190190
# Configure SYCL version macro
191191
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
192192
set(sycl_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/source)
193-
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
193+
194+
if(NOT DEFINED SYCL_COMPILER_VERSION)
195+
find_package(Git QUIET)
196+
if(GIT_FOUND)
197+
# Get the date of the latest commit
198+
execute_process(
199+
COMMAND ${GIT_EXECUTABLE} log -1 --format=%cd --date=format:%Y%m%d
200+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
201+
RESULT_VARIABLE GIT_RESULT
202+
OUTPUT_VARIABLE GIT_DATE
203+
OUTPUT_STRIP_TRAILING_WHITESPACE
204+
)
205+
206+
if(GIT_RESULT EQUAL 0 AND GIT_DATE)
207+
set(SYCL_COMPILER_VERSION "${GIT_DATE}")
208+
endif()
209+
endif()
210+
211+
if(NOT DEFINED SYCL_COMPILER_VERSION)
212+
message(WARNING "No value for SYCL_COMPILER_VERSION passed and couldn't determine timestamp of last commit, falling back to current timestamp.")
213+
string(TIMESTAMP SYCL_COMPILER_VERSION "%Y%m%d")
214+
endif()
215+
endif()
216+
217+
set(__SYCL_COMPILER_VERSION "${SYCL_COMPILER_VERSION}")
218+
message(STATUS "SYCL Compiler Version: ${__SYCL_COMPILER_VERSION}")
219+
194220
configure_file("source/version.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/version.hpp")
195221
configure_file("source/feature_test.hpp.in" "${SYCL_INCLUDE_BUILD_DIR}/sycl/feature_test.hpp")
196222

0 commit comments

Comments
 (0)