1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 rocmUpdateScript,
6 cmake,
7 writeText,
8}:
9
10# rocm-core is used by most distros for a few purposes:
11# - meta package that all rocm packages depend so `apt-get remove rocm-core` removes all rocm packages
12# - provide overall ROCM_PATH
13# - provide rocm version info and path to rocm version headers
14# only the last usage makes sense in nixpkgs
15let
16 padIfSingle = s: if lib.stringLength s == 1 then "0${s}" else s;
17in
18stdenv.mkDerivation (finalAttrs: {
19 pname = "rocm-core";
20 version = "6.3.3";
21
22 src = fetchFromGitHub {
23 owner = "ROCm";
24 repo = "rocm-core";
25 rev = "rocm-${finalAttrs.version}";
26 hash = "sha256-UDnPGvgwzwv49CzF+Kt0v95CsxS33BZeqNcKw1K6jRI=";
27 };
28
29 patches = [
30 ./env-rocm-path.patch
31 ];
32
33 nativeBuildInputs = [ cmake ];
34 env = {
35 ROCM_LIBPATCH_VERSION = "${lib.versions.major finalAttrs.version}${padIfSingle (lib.versions.minor finalAttrs.version)}${padIfSingle (lib.versions.patch finalAttrs.version)}";
36 BUILD_ID = "nixpkgs-${finalAttrs.env.ROCM_LIBPATCH_VERSION}";
37 ROCM_BUILD_ID = "${finalAttrs.env.BUILD_ID}";
38 };
39 cmakeFlags = [
40 "-DROCM_LIBPATCH_VERSION=${finalAttrs.env.ROCM_LIBPATCH_VERSION}"
41 "-DROCM_VERSION=${finalAttrs.version}"
42 "-DBUILD_ID=${finalAttrs.env.BUILD_ID}"
43 "-DCMAKE_INSTALL_LIBDIR=lib"
44 "-DCMAKE_INSTALL_INCLUDEDIR=include"
45 "-DCMAKE_INSTALL_BINDIR=bin"
46 ];
47
48 setupHook = writeText "setupHook.sh" ''
49 export ROCM_VERSION="${finalAttrs.version}"
50 export ROCM_LIBPATCH_VERSION="${finalAttrs.env.ROCM_LIBPATCH_VERSION}"
51 export ROCM_BUILD_ID="${finalAttrs.env.ROCM_BUILD_ID}"
52 '';
53
54 doInstallCheck = true;
55 preInstallCheck =
56 # Test that the CMake config file can be included and sets expected vars
57 ''
58 mkdir test_project
59 pushd test_project
60
61 echo '
62 cmake_minimum_required(VERSION 3.16)
63 project(test_rocm_core)
64 find_package(rocm-core REQUIRED)
65 if(NOT DEFINED ROCM_CORE_INCLUDE_DIR)
66 message(FATAL_ERROR "ROCM_CORE_INCLUDE_DIR not set")
67 endif()
68 message(STATUS "Found ROCM_CORE_INCLUDE_DIR: ''${ROCM_CORE_INCLUDE_DIR}")
69 message(STATUS "Found ROCM_PATH: ''${ROCM_PATH}")
70 ' > CMakeLists.txt
71
72 CMAKE_PREFIX_PATH="$out" cmake .
73 popd
74
75 . $out/nix-support/setup-hook
76 env | grep '^ROCM'
77 '';
78
79 passthru.ROCM_LIBPATCH_VERSION = finalAttrs.env.ROCM_LIBPATCH_VERSION;
80 passthru.updateScript = rocmUpdateScript {
81 name = finalAttrs.pname;
82 inherit (finalAttrs.src) owner;
83 inherit (finalAttrs.src) repo;
84 page = "tags?per_page=4";
85 };
86
87 meta = with lib; {
88 description = "Utility for getting the ROCm release version";
89 homepage = "https://github.com/ROCm/rocm-core";
90 license = with licenses; [ mit ];
91 teams = [ teams.rocm ];
92 platforms = platforms.linux;
93 };
94})