Skip to content

Commit 5c6def2

Browse files
authored
Amend platform repo paths with version specific path (#9503)
Under XDG_DATA_DIR use XRT_VERSION_STRING for application data dir directory. Make sure version specific directory is searched prior to non-versioned directory. This is facilitating xrt-smi in its search for validation artifact archives, such that the search can be specific to an XRT version. Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
1 parent 3b58b8a commit 5c6def2

3 files changed

Lines changed: 54 additions & 13 deletions

File tree

src/CMake/settings.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ endif (NOT CMAKE_BUILD_TYPE)
5757
# --- version settings ---
5858
# Version adjusted to 2.21 for 2026.1
5959
set(XRT_VERSION_RELEASE 202610)
60-
SET(XRT_VERSION_MAJOR 2)
61-
SET(XRT_VERSION_MINOR 21)
60+
set(XRT_VERSION_MAJOR 2)
61+
set(XRT_VERSION_MINOR 21)
6262

63-
if (DEFINED ENV{XRT_VERSION_PATCH})
64-
SET(XRT_VERSION_PATCH $ENV{XRT_VERSION_PATCH})
65-
else(DEFINED $ENV{XRT_VERSION_PATCH})
66-
SET(XRT_VERSION_PATCH 0)
67-
endif(DEFINED ENV{XRT_VERSION_PATCH})
63+
if (XRT_VERSION_PATCH)
64+
set(XRT_VERSION_PATCH ${XRT_VERSION_PATCH})
65+
elseif (DEFINED ENV{XRT_VERSION_PATCH})
66+
set(XRT_VERSION_PATCH $ENV{XRT_VERSION_PATCH})
67+
else()
68+
set(XRT_VERSION_PATCH 0)
69+
endif(XRT_VERSION_PATCH)
6870

6971
# Also update cache to set version for external plug-in .so
7072
set(XRT_SOVERSION ${XRT_VERSION_MAJOR} CACHE INTERNAL "")

src/runtime_src/core/common/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ target_include_directories(core_common_library_objects
7171

7272
set_property(SOURCE module_loader.cpp APPEND PROPERTY COMPILE_DEFINITIONS
7373
XRT_VERSION_MAJOR="${XRT_VERSION_MAJOR}"
74+
XRT_VERSION_STRING="${XRT_VERSION_STRING}"
7475
XRT_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
7576
XRT_LIB_DIR="${CMAKE_INSTALL_LIBDIR}"
7677
)
@@ -169,4 +170,4 @@ else()
169170
install(TARGETS xrt_coreutil_static
170171
EXPORT xrt-targets
171172
ARCHIVE DESTINATION ${XRT_INSTALL_LIB_DIR} COMPONENT ${XRT_BASE_DEV_COMPONENT})
172-
endif()
173+
endif()

src/runtime_src/core/common/detail/linux/xilinx_xrt.h

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

4+
// This file is an implementation detail of the XRT coreutil library.
5+
// It is not part of the public XRT API. Include guards are not
6+
// at this level.
47
#include "core/common/debug.h"
58
#include "core/common/module_loader.h"
69

710
#include <dlfcn.h>
11+
12+
#include <cstdlib>
813
#include <filesystem>
914
#include <stdexcept>
1015
#include <string>
@@ -14,6 +19,10 @@
1419
# error "XRT_INSTALL_PREFIX is undefined"
1520
#endif
1621

22+
#ifndef XRT_VERSION_STRING
23+
# error "XRT_VERSION_STRING is undefined"
24+
#endif
25+
1726
namespace xrt_core::detail {
1827

1928
namespace sfs = std::filesystem;
@@ -29,11 +38,36 @@ xilinx_xrt()
2938
if (std::string(info.dli_fname).find("libxrt_coreutil") == std::string::npos)
3039
return sfs::path(XRT_INSTALL_PREFIX);
3140

32-
// Relocatable path based on install location of this DSO
33-
sfs::path so_path(sfs::canonical(info.dli_fname)); // /.../lib/libxrt_coreutil.so
34-
return so_path.parent_path().parent_path();
41+
try {
42+
// Relocatable path based on install location of this DSO
43+
sfs::path so_path(sfs::canonical(info.dli_fname)); // /.../lib/libxrt_coreutil.so
44+
return so_path.parent_path().parent_path();
45+
}
46+
catch (const std::exception&) {
47+
return sfs::path(XRT_INSTALL_PREFIX);
48+
}
3549
}
3650

51+
// platform_repo_path() - Get candidate paths for platform repository data
52+
//
53+
// Returns a prioritized list of filesystem paths where
54+
// platform-specific data files (e.g., FPGA platform metadata) may be
55+
// located. The search order is:
56+
//
57+
// 1. XRT installation share directory:
58+
// - <xrt_root>/share (if xrt_root ends with "xrt")
59+
// - <xrt_root>/share/xrt (otherwise)
60+
//
61+
// 2. XDG user data directory (if XDG_DATA_HOME is set):
62+
// - $XDG_DATA_HOME/xrt/<version>
63+
// - $XDG_DATA_HOME/xrt
64+
//
65+
// 3. User's local share directory (if HOME is set):
66+
// - $HOME/.local/share/xrt/<version>
67+
// - $HOME/.local/share/xrt
68+
//
69+
// Returned paths are not validated - caller must check existence
70+
// Follows XDG Base Directory Specification for user data paths
3771
std::vector<sfs::path>
3872
platform_repo_path()
3973
{
@@ -51,10 +85,14 @@ platform_repo_path()
5185
paths.push_back(xrt / "share/xrt");
5286

5387
// 2. XDG data path ($HOME/.local/share) is also a candidate
54-
if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg)
88+
if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg) {
89+
paths.push_back(sfs::path(xdg) / "xrt" / XRT_VERSION_STRING);
5590
paths.push_back(sfs::path(xdg) / "xrt");
56-
else if (const char* home = std::getenv("HOME"); home && *home)
91+
}
92+
else if (const char* home = std::getenv("HOME"); home && *home) {
93+
paths.push_back(sfs::path(home) / ".local/share/xrt" / XRT_VERSION_STRING);
5794
paths.push_back(sfs::path(home) / ".local/share/xrt");
95+
}
5896

5997
return paths;
6098
}

0 commit comments

Comments
 (0)