commit:     1ec9b7d4bb0cce7a501686733565b0221ee1db69
Author:     Benda Xu <heroxbd <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 19 14:34:10 2021 +0000
Commit:     Benda XU <heroxbd <AT> gentoo <DOT> org>
CommitDate: Wed Jan 20 04:51:53 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1ec9b7d4

sys-devel/llvm-roc: replace HIP finder with Gentoo paths.

remove isystem include path.

Set USE=runtime as default.

Suggested-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com>
Suggested-by: Wilfried Holzke <gentoo <AT> holzke.net>
Reference: https://github.com/justxi/rocm/issues/174#issuecomment-749479598
Package-Manager: Portage-3.0.12, Repoman-3.0.1
Signed-off-by: Benda Xu <heroxbd <AT> gentoo.org>

 .../files/llvm-roc-4.0.0-hip-location.patch        | 47 +++++++++++
 ...llvm-roc-4.0.0-remove-isystem-usr-include.patch | 29 +++++++
 sys-devel/llvm-roc/llvm-roc-4.0.0-r1.ebuild        | 94 ++++++++++++++++++++++
 3 files changed, 170 insertions(+)

diff --git a/sys-devel/llvm-roc/files/llvm-roc-4.0.0-hip-location.patch 
b/sys-devel/llvm-roc/files/llvm-roc-4.0.0-hip-location.patch
new file mode 100644
index 00000000000..8342299f113
--- /dev/null
+++ b/sys-devel/llvm-roc/files/llvm-roc-4.0.0-hip-location.patch
@@ -0,0 +1,47 @@
+replace hardcoded hip finder with Gentoo paths.
+
+Author: Benda Xu <[email protected]>
+
+Index: llvm-project-rocm-4.0.0/clang/lib/Driver/ToolChains/AMDGPU.cpp
+===================================================================
+--- llvm-project-rocm-4.0.0.orig/clang/lib/Driver/ToolChains/AMDGPU.cpp
++++ llvm-project-rocm-4.0.0/clang/lib/Driver/ToolChains/AMDGPU.cpp
+@@ -116,37 +116,8 @@ RocmInstallationDetector::getInstallatio
+     return Candidates;
+   }
+ 
+-  // Try to find relative to the compiler binary.
+-  const char *InstallDir = D.getInstalledDir();
++  Candidates.emplace_back(D.SysRoot + "/usr/lib/hip", 
/*StrictChecking=*/true);
+ 
+-  // Check both a normal Unix prefix position of the clang binary, as well as
+-  // the Windows-esque layout the ROCm packages use with the host architecture
+-  // subdirectory of bin.
+-
+-  // Strip off directory (usually bin)
+-  StringRef ParentDir = llvm::sys::path::parent_path(InstallDir);
+-  StringRef ParentName = llvm::sys::path::filename(ParentDir);
+-
+-  // Some builds use bin/{host arch}, so go up again.
+-  if (ParentName == "bin") {
+-    ParentDir = llvm::sys::path::parent_path(ParentDir);
+-    ParentName = llvm::sys::path::filename(ParentDir);
+-  }
+-
+-  // Some versions of the rocm llvm package install to /opt/rocm/llvm/bin
+-  if (ParentName == "llvm")
+-    ParentDir = llvm::sys::path::parent_path(ParentDir);
+-
+-  Candidates.emplace_back(ParentDir.str(), /*StrictChecking=*/true);
+-
+-  // Device library may be installed in clang resource directory.
+-  Candidates.emplace_back(D.ResourceDir, /*StrictChecking=*/true);
+-
+-  Candidates.emplace_back(D.SysRoot + "/opt/rocm", /*StrictChecking=*/true);
+-  if (ParentName.startswith("aomp")) {
+-    // Some versions of the aomp package install to /opt/rocm/aomp/bin
+-    Candidates.emplace_back(ParentDir.str());
+-  }
+   return Candidates;
+ }
+ 

diff --git 
a/sys-devel/llvm-roc/files/llvm-roc-4.0.0-remove-isystem-usr-include.patch 
b/sys-devel/llvm-roc/files/llvm-roc-4.0.0-remove-isystem-usr-include.patch
new file mode 100644
index 00000000000..f14ec4ac0db
--- /dev/null
+++ b/sys-devel/llvm-roc/files/llvm-roc-4.0.0-remove-isystem-usr-include.patch
@@ -0,0 +1,29 @@
+Author: Wilfried (justxi) Holzke
+
+Adopted from 
https://github.com/justxi/rocm/blob/master/sys-devel/llvm-roc/files/llvm-roc-4.0.0-remove-isystem-usr-include.patch
+
+Index: llvm-project-rocm-4.0.0/clang/lib/Driver/ToolChains/AMDGPU.cpp
+===================================================================
+--- llvm-project-rocm-4.0.0.orig/clang/lib/Driver/ToolChains/AMDGPU.cpp
++++ llvm-project-rocm-4.0.0/clang/lib/Driver/ToolChains/AMDGPU.cpp
+@@ -326,11 +326,6 @@ void RocmInstallationDetector::AddHIPInc
+     //
+     // ROCm 3.5 does not fully support the wrapper headers. Therefore it needs
+     // a workaround.
+-    SmallString<128> P(D.ResourceDir);
+-    if (UsesRuntimeWrapper)
+-      llvm::sys::path::append(P, "include", "cuda_wrappers");
+-    CC1Args.push_back("-internal-isystem");
+-    CC1Args.push_back(DriverArgs.MakeArgString(P));
+   }
+ 
+   if (DriverArgs.hasArg(options::OPT_nogpuinc))
+@@ -341,8 +336,6 @@ void RocmInstallationDetector::AddHIPInc
+     return;
+   }
+ 
+-  CC1Args.push_back("-internal-isystem");
+-  CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
+   if (UsesRuntimeWrapper)
+     CC1Args.append({"-include", "__clang_hip_runtime_wrapper.h"});
+ }

diff --git a/sys-devel/llvm-roc/llvm-roc-4.0.0-r1.ebuild 
b/sys-devel/llvm-roc/llvm-roc-4.0.0-r1.ebuild
new file mode 100644
index 00000000000..5714ae9b719
--- /dev/null
+++ b/sys-devel/llvm-roc/llvm-roc-4.0.0-r1.ebuild
@@ -0,0 +1,94 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit cmake
+
+DESCRIPTION="Radeon Open Compute llvm,lld,clang"
+HOMEPAGE="https://github.com/RadeonOpenCompute/ROCm/";
+SRC_URI="https://github.com/RadeonOpenCompute/llvm-project/archive/rocm-${PV}.tar.gz
 -> llvm-rocm-ocl-${PV}.tar.gz"
+
+LICENSE="UoI-NCSA rc BSD public-domain"
+SLOT="0"
+KEYWORDS="~amd64"
+IUSE="debug +runtime"
+
+RDEPEND="virtual/cblas
+       dev-libs/libxml2
+       sys-libs/zlib
+       sys-libs/ncurses:="
+DEPEND="${RDEPEND}"
+PDEPEND="dev-libs/rocr-runtime"
+
+S="${WORKDIR}/llvm-project-rocm-${PV}/llvm"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-3.7.0-current_pos.patch"
+       "${FILESDIR}/${PN}-3.9.0-tensorflow.patch"
+)
+
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+src_prepare() {
+       cd "${WORKDIR}/llvm-project-rocm-${PV}" || die
+       eapply "${FILESDIR}/${PN}-3.0.0-add_libraries.patch"
+       eapply "${FILESDIR}/${PN}-4.0.0-remove-isystem-usr-include.patch"
+       eapply "${FILESDIR}/${PN}-4.0.0-hip-location.patch"
+
+       if [[ -n ${EPREFIX} ]]; then
+               pushd "${S}"/../clang >/dev/null || die
+               sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT 
\"${EPREFIX}\"@" CMakeLists.txt
+               eend $?
+               ebegin "Use ${EPREFIX} as default sysroot"
+               cd lib/Driver/ToolChains >/dev/null || die
+               ebegin "Use dynamic linker from ${EPREFIX}"
+               sed -i -e "/LibDir.*Loader/s@return \"\/\"@return 
\"${EPREFIX}/\"@" Linux.cpp
+               eend $?
+
+               ebegin "Remove --sysroot call on ld for native toolchain"
+               sed -i -e "$(grep -n -B1 sysroot= Gnu.cpp | sed -ne 
'{1s/-.*//;1p}'),+1 d" Gnu.cpp
+               eend $?
+               popd >/dev/null || die
+       fi
+
+       # handled by sysroot, don't prefixify here.
+       sed -e 's:/opt/rocm:/usr/lib/hip:' \
+               -i "${S}"/../clang/lib/Driver/ToolChains/AMDGPU.cpp
+
+       eapply_user
+       cmake_src_prepare
+}
+
+src_configure() {
+       PROJECTS="clang;lld"
+
+       if usex runtime; then
+               PROJECTS+=";compiler-rt"
+       fi
+
+       local mycmakeargs=(
+               -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/roc"
+               -DLLVM_ENABLE_PROJECTS="${PROJECTS}"
+               -DLLVM_TARGETS_TO_BUILD="AMDGPU;X86"
+               -DLLVM_BUILD_DOCS=NO
+               -DLLVM_ENABLE_OCAMLDOC=OFF
+               -DLLVM_ENABLE_SPHINX=NO
+               -DLLVM_ENABLE_DOXYGEN=OFF
+               -DLLVM_INSTALL_UTILS=ON
+               -DLLVM_VERSION_SUFFIX=roc
+               -DOCAMLFIND=NO
+       )
+
+       use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+
+       cmake_src_configure
+}
+
+src_install() {
+       cmake_src_install
+       cat > "99${PN}" <<-EOF
+               LDPATH="${EROOT}/usr/lib/llvm/roc/lib"
+       EOF
+       doenvd "99${PN}"
+}

Reply via email to