Skip to content

Commit e266719

Browse files
authored
Amend #9231: Add minimal version info header to help compiler cache (#9238)
* Amend #9231: Add minimal version info header to help compiler cache Refactor the autogenerated version.h into two separately configured headers, one that doesn't use timestamp (version-slim.h) and one that does (version.h). The XRT exported header files depend on ABI check that uses the XRT version only. These headers can include version-slim.h and not be affected by a changing timestamp everytime CMake is reconfigured. This in turn simplifies the logic for building with ccache. The two separate headers are generated under the build tree in a directory with same relatively location as where the corresponding headers will be installed. Thank you @shramov for #9231, which seeded this PR. Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com> * Fix review comment Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com> * Fix driver build error Make sure version-slim.h is installed in proper location for DKMS. Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com> --------- Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
1 parent b639c52 commit e266719

File tree

14 files changed

+67
-127
lines changed

14 files changed

+67
-127
lines changed

src/CMake/ccache.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ if (XRT_CCACHE)
88
if(CCACHE_PROGRAM)
99
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
1010
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
11-
12-
# Disable abi compile time checks which renders ccache close to useless
13-
message ("***** CCACHE: DISABLING ABI VERSION CHECK ******")
14-
add_compile_options("-DDISABLE_ABI_CHECK")
1511
else()
1612
message ("***** ccache program not found, ignoring -ccache")
1713
endif()

src/CMake/config/version-slim.h.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
#ifndef XRT_VERSION_SLIM_H_
4+
#define XRT_VERSION_SLIM_H_
5+
6+
// This header contains minimal version info needed for xrt/detail/abi.h header
7+
8+
#define XRT_VERSION(major, minor) ((major << 16) + (minor))
9+
#define XRT_VERSION_CODE XRT_VERSION(@XRT_VERSION_MAJOR@, @XRT_VERSION_MINOR@)
10+
#define XRT_MAJOR(code) ((code >> 16))
11+
#define XRT_MINOR(code) (code - ((code >> 16) << 16))
12+
13+
#endif

src/CMake/config/version.h.in

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
/**
2-
* SPDX-License-Identifier: Apache-2.0
3-
* Copyright (C) 2019-2021 Xilinx, Inc. All rights reserved.
4-
* Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
5-
*/
6-
7-
#ifndef _XRT_VERSION_H_
8-
#define _XRT_VERSION_H_
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2019-2021 Xilinx, Inc. All rights reserved.
3+
// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
4+
#ifndef XRT_VERSION_H_
5+
#define XRT_VERSION_H_
96

107
static const char xrt_build_version[] = "@XRT_VERSION_STRING@";
118

@@ -22,15 +19,12 @@ static const char xrt_build_version_date[] = "@XRT_DATE@";
2219
static const char xrt_modified_files[] = "@XRT_MODIFIED_FILES@";
2320

2421
#define XRT_DRIVER_VERSION "@XRT_VERSION_STRING@,@XRT_HASH@"
25-
26-
#define XRT_VERSION(major, minor) ((major << 16) + (minor))
27-
#define XRT_VERSION_CODE XRT_VERSION(@XRT_VERSION_MAJOR@, @XRT_VERSION_MINOR@)
28-
#define XRT_MAJOR(code) ((code >> 16))
29-
#define XRT_MINOR(code) (code - ((code >> 16) << 16))
3022
#define XRT_PATCH @XRT_VERSION_PATCH@
3123
#define XRT_HEAD_COMMITS @XRT_HEAD_COMMITS@
3224
#define XRT_BRANCH_COMMITS @XRT_BRANCH_COMMITS@
3325

26+
#include "xrt/detail/version-slim.h"
27+
3428
#ifdef __cplusplus
3529
#include <iostream>
3630
#include <string>

src/CMake/settings.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ else()
5050
set(XRT_WARN_OPTS -Wall)
5151
endif()
5252

53-
if (DISABLE_ABI_CHECK)
54-
add_compile_options("-DDISABLE_ABI_CHECK")
55-
endif()
56-
5753
if (NOT CMAKE_BUILD_TYPE)
5854
set (CMAKE_BUILD_TYPE RelWithDebInfo)
5955
endif (NOT CMAKE_BUILD_TYPE)

src/CMake/version.cmake

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (C) 2019-2021 Xilinx, Inc. All rights reserved.
3-
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
3+
# Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
44

55
# AMD promotion build works from copied sources with no git
66
# repository. The build cannot query git for git metadata. The
@@ -83,9 +83,14 @@ execute_process(
8383

8484
string(TIMESTAMP XRT_DATE "%Y-%m-%d %H:%M:%S")
8585

86+
configure_file(
87+
${XRT_SOURCE_DIR}/CMake/config/version-slim.h.in
88+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version-slim.h
89+
)
90+
8691
configure_file(
8792
${XRT_SOURCE_DIR}/CMake/config/version.h.in
88-
${PROJECT_BINARY_DIR}/gen/version.h
93+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version.h
8994
)
9095

9196
configure_file(
@@ -94,7 +99,9 @@ configure_file(
9499
)
95100

96101
# xrt component install
97-
install(FILES ${PROJECT_BINARY_DIR}/gen/version.h
102+
install(FILES
103+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version.h
104+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version-slim.h
98105
DESTINATION ${XRT_INSTALL_INCLUDE_DIR}/xrt/detail
99106
COMPONENT ${XRT_BASE_DEV_COMPONENT})
100107

@@ -108,7 +115,13 @@ endif()
108115
if (XRT_ALVEO AND (NOT XRT_EDGE) AND (NOT WIN32))
109116
# Copied over from dkms.cmake. TODO: cleanup
110117
set (XRT_DKMS_INSTALL_DIR "/usr/src/xrt-${XRT_VERSION_STRING}")
111-
install(FILES ${PROJECT_BINARY_DIR}/gen/version.h
118+
install(FILES
119+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version.h
120+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version-slim.h
112121
DESTINATION ${XRT_DKMS_INSTALL_DIR}/driver/include
113122
COMPONENT ${XRT_DEV_COMPONENT})
123+
install(FILES
124+
${PROJECT_BINARY_DIR}/gen/xrt/detail/version-slim.h
125+
DESTINATION ${XRT_DKMS_INSTALL_DIR}/driver/include/xrt/detail
126+
COMPONENT ${XRT_DEV_COMPONENT})
114127
endif()

src/runtime_src/core/common/api/xrt_version.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
2+
// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
33

44
// This file implements XRT version APIs as declared in
55
// core/include/experimental/xrt_version.h
66
#define XRT_API_SOURCE // exporting xrt_version.h
77
#define XRT_CORE_COMMON_SOURCE // in same dll as core_common
88
#include "core/include/xrt/experimental/xrt_version.h"
9-
#include "version.h"
9+
#include "xrt/detail/version.h"
1010

1111
#ifdef major
1212
# undef major

src/runtime_src/core/common/message.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
1-
/**
2-
* Copyright (C) 2016-2022 Xilinx, Inc
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may
5-
* not use this file except in compliance with the License. A copy of the
6-
* License is located at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations
14-
* under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2016-2022 Xilinx, Inc. All rights reserved.
3+
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
174
#define XRT_CORE_COMMON_SOURCE
185
#include "message.h"
196
#include "time.h"
20-
#include "gen/version.h"
217
#include "config_reader.h"
228
#include "utils.h"
239

10+
#include "xrt/detail/version.h"
11+
2412
#include <map>
2513
#include <fstream>
2614
#include <iostream>

src/runtime_src/core/common/sysinfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
33
#define XRT_CORE_COMMON_SOURCE
4-
// Local - Include files
54
#include "sysinfo.h"
65
#include "detail/sysinfo.h"
76
#include "system.h"
87

9-
// System - Include Files
10-
#include "gen/version.h"
8+
#include "xrt/detail/version.h"
119

1210
namespace xrt_core::sysinfo {
1311

src/runtime_src/core/common/system.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2019 Xilinx, Inc
3-
// Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
3+
// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
44
#define XRT_CORE_COMMON_SOURCE
5-
// Local - Include Files
65
#include "system.h"
76
#include "device.h"
87
#include "module_loader.h"
98

10-
#include "gen/version.h"
11-
12-
13-
// System - Include Files
149
#include <boost/property_tree/ptree.hpp>
1510

1611
#include <map>

src/runtime_src/core/include/xrt/detail/abi.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2021 Xilinx, Inc. All rights reserved.
3-
// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3+
// Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
44
#ifndef XRT_DETAIL_ABI_H
55
#define XRT_DETAIL_ABI_H
66

7-
// Generated version.h file is installed into include/xrt/detail/version.h
8-
// but at build time it is picked up from compile include search path
9-
#if defined(XRT_BUILD) && !defined(DISABLE_ABI_CHECK)
10-
# include "version.h"
11-
#elif !defined(XRT_BUILD)
12-
# include "xrt/detail/version.h"
13-
#endif
7+
#include "xrt/detail/version-slim.h"
148

159
#ifdef __cplusplus
1610

@@ -26,15 +20,9 @@ namespace xrt { namespace detail {
2620
// The struct is used to guarantee schema compability between old
2721
// version of XRT and new version.
2822
struct abi {
29-
#ifndef DISABLE_ABI_CHECK
3023
const unsigned int major {XRT_MAJOR(XRT_VERSION_CODE)};
3124
const unsigned int minor {XRT_MINOR(XRT_VERSION_CODE)};
3225
const unsigned int code {XRT_VERSION_CODE};
33-
#else
34-
const unsigned int major {0};
35-
const unsigned int minor {0};
36-
const unsigned int code {0};
37-
#endif
3826
};
3927

4028
}} // detail, xrt

0 commit comments

Comments
 (0)