@@ -6,22 +6,42 @@ pkgbase=rocm-llvm
66pkgname=(rocm-llvm rocm-device-libs comgr)
77epoch=2
88pkgver=7.2.4
9- pkgrel=1
9+ pkgrel=2
1010arch=(aarch64)
1111url=' https://rocm.docs.amd.com/en/latest/reference/rocmcc.html'
1212makedepends=(' git' ' cmake' ' python' ' ninja' ' rocm-core' ' rocm-cmake' ' perl'
1313 ' gcc-libs' ' zlib' ' zstd' ' libffi' ' libedit' ' ncurses' ' libxml2' ' patchelf' )
14- source=(" $pkgbase ::git+https://github.com/ROCm/llvm-project#tag=rocm-$pkgver " )
15- sha256sums=(' cda215d04dfb6ede38c542d4604711d4a4623267df0f3d678491cd9fbcc32fd9' )
14+ source=(" $pkgbase ::git+https://github.com/ROCm/llvm-project#tag=rocm-$pkgver "
15+ ' 0001-compiler-rt-sanitizer-Remove-linux-scc.h.patch' )
16+ sha256sums=(' cda215d04dfb6ede38c542d4604711d4a4623267df0f3d678491cd9fbcc32fd9'
17+ ' 3592a157f9c8c748a5f75d79c9e328f1c359ec6609d260a58d4b68ba97f7fe9b' )
1618options=(staticlibs ! lto)
1719
20+ prepare () {
21+ # linux/scc.h is gone from linux-api-headers >= 7.1
22+ patch -Np1 -d " $pkgbase " -i " $srcdir /0001-compiler-rt-sanitizer-Remove-linux-scc.h.patch"
23+ }
24+
1825build () {
1926 CXXFLAGS+=' -Wno-error -Wno-narrowing'
2027 CFLAGS+=' -Wno-error -Wno-narrowing'
2128 # Build only minimal debug info to reduce size
2229 CFLAGS+=' -g1'
2330 CXXFLAGS+=' -g1'
2431
32+ # flang-rt compiles the Fortran modules with the just-built flang, which
33+ # errors out on the C-only flags makepkg exports in FFLAGS (see
34+ # /usr/share/makepkg/buildenv/fortran.sh) instead of ignoring them. Drop
35+ # exactly those and keep the rest, so -march, -O2, -g and
36+ # -fno-omit-frame-pointer still apply. If Arch ever adds another C-only flag
37+ # this fails loudly rather than silently dropping hardening.
38+ local _unsupported=' -(pipe|fno-plt|fexceptions|fstack-clash-protection)\b'
39+ _unsupported+=' |-(mno-omit-leaf-frame-pointer|Wformat|Werror=format-security)\b'
40+ _unsupported+=' |-fcf-protection(=[^ ]*)?|-ffile-prefix-map=[^ ]*|-Wp,[^ ]*'
41+ FFLAGS=$( sed -E " s@($_unsupported )@@g" <<< " $FFLAGS" )
42+ FCFLAGS=$( sed -E " s@($_unsupported )@@g" <<< " $FCFLAGS" )
43+ export FFLAGS FCFLAGS
44+
2545 local _rocm_exe_rpath=' \$ORIGIN/../lib:\$ORIGIN/../../../lib'
2646 local _rocm_lib_rpath=' \$ORIGIN'
2747 # Flags according to
@@ -33,10 +53,17 @@ build() {
3353 -D CMAKE_BUILD_TYPE=Release
3454 -D CMAKE_INSTALL_PREFIX=" /opt/rocm/lib/llvm"
3555 -D LLVM_HOST_TRIPLE=$CHOST
36- -D LLVM_ENABLE_PROJECTS=' clang;lld;clang-tools-extra'
56+ # mlir is a hard dependency of flang. flang provides the `flang` driver
57+ # that `amdflang` dispatches to; without it CLANG_ENABLE_AMDCLANG still
58+ # installs `amdflang`, leaving it pointing at a non-existent binary.
59+ -D LLVM_ENABLE_PROJECTS=' clang;lld;clang-tools-extra;mlir;flang'
3760 -D CLANG_ENABLE_AMDCLANG=ON
3861 -D PACKAGE_VENDOR=" AMD"
39- -D LLVM_ENABLE_RUNTIMES=' compiler-rt;libunwind;libcxx;libcxxabi'
62+ # flang-rt is the Fortran runtime; without it flang cannot link anything.
63+ # The OpenMP host runtime and the AMDGPU offload plugin are built by the
64+ # separate rocm-openmp package, because the plugin needs the HSA headers
65+ # from hsa-rocr, which in turn makedepends on this package.
66+ -D LLVM_ENABLE_RUNTIMES=' compiler-rt;libunwind;libcxx;libcxxabi;flang-rt'
4067 -D LIBCXX_ENABLE_SHARED=OFF
4168 -D LIBCXX_ENABLE_STATIC=ON
4269 -D LIBCXX_INSTALL_LIBRARY=OFF
@@ -64,16 +91,15 @@ build() {
6491 -D CMAKE_SKIP_INSTALL_RPATH=TRUE
6592 -D CMAKE_EXE_LINKER_FLAGS=" -Wl,--enable-new-dtags,--build-id=sha1,--rpath,$_rocm_exe_rpath "
6693 -D CMAKE_SHARED_LINKER_FLAGS=" -Wl,--enable-new-dtags,--build-id=sha1,--rpath,$_rocm_lib_rpath "
67- -D CLANG_LINK_FLANG_LEGACY=ON
6894 -D CMAKE_CXX_STANDARD=17
95+ # Fortran driver and runtime. FLANG_RT_INCLUDE_AMD additionally builds
96+ # libflang_rt.amd.a, the part of the Fortran runtime that rocm-openmp
97+ # needs to make Fortran callable from inside OpenMP target regions.
98+ -D FLANG_RT_INCLUDE_AMD=ON
99+ -D FLANG_INCLUDE_DOCS=OFF
100+ -D FLANG_INCLUDE_TESTS=OFF
69101 )
70102 cmake " ${cmake_args[@]} "
71- # Bootstrapping libcxx, see
72- # https://github.com/ROCm/ROCm/blob/87bc26e672e06294bd2a6a1b507ad5c9ae4cffba/tools/rocm-build/build_lightning.sh#L352-L359
73- cmake --build build -- clang lld compiler-rt
74- cmake --build build -- runtimes cxx
75- cmake --build build
76- cmake --build build -- clang-tidy
77103
78104 local cmake_device_libs_args=(
79105 -Wno-dev
@@ -83,6 +109,24 @@ build() {
83109 -D CMAKE_INSTALL_PREFIX=/opt/rocm
84110 -D CMAKE_PREFIX_PATH=" $srcdir /build"
85111 )
112+
113+ # The ROCm fork adds FIR/HLFIR includes to flang/Support/OpenMP-utils.h that
114+ # upstream does not have, without declaring the matching TableGen
115+ # dependencies in flang/lib/Support/CMakeLists.txt. FortranSupport therefore
116+ # races the TableGen step and intermittently fails with
117+ # "flang/Optimizer/HLFIR/HLFIRDialect.h.inc: No such file or directory".
118+ # Building the dialects first materialises every generated header it needs;
119+ # neither dialect depends on FortranSupport, so this does not deadlock.
120+ cmake --build build -- HLFIRDialect CUFDialect
121+
122+ # Bootstrapping libcxx, see
123+ # https://github.com/ROCm/ROCm/blob/87bc26e672e06294bd2a6a1b507ad5c9ae4cffba/tools/rocm-build/build_lightning.sh#L352-L359
124+ # llvm-link and opt are pulled in early because device-libs needs them.
125+ cmake --build build -- clang lld compiler-rt llvm-link opt
126+ cmake --build build -- runtimes cxx
127+ cmake --build build
128+ cmake --build build -- clang-tidy
129+
86130 cmake " ${cmake_device_libs_args[@]} "
87131 cmake --build build-device-libs
88132
@@ -100,10 +144,11 @@ build() {
100144}
101145
102146package_rocm-llvm () {
103- pkgdesc=' Radeon Open Compute - LLVM toolchain (llvm, clang, lld)'
147+ pkgdesc=' Radeon Open Compute - LLVM toolchain (llvm, clang, lld, flang )'
104148 license=(' Apache-2.0 WITH LLVM-exception' )
105149 depends=(' rocm-core' ' perl' ' glibc' ' libgcc' ' libstdc++' ' zlib' ' zstd' ' libffi' ' libedit'
106150 ' ncurses' ' libxml2' )
151+ optdepends=(' rocm-openmp: OpenMP host runtime and GPU offloading' )
107152
108153 DESTDIR=" $pkgdir " cmake --install build
109154
@@ -113,7 +158,7 @@ package_rocm-llvm() {
113158 # Some packages require amdclang to be found in /opt/rocm/bin
114159 mkdir -p " $pkgdir /opt/rocm/bin"
115160 local _compiler
116- for _compiler in amdclang amdclang++ amdclang-cl amdclang-cpp amdlld; do
161+ for _compiler in amdclang amdclang++ amdclang-cl amdclang-cpp amdflang amdlld; do
117162 ln -s /opt/rocm/lib/llvm/bin/$_compiler " $pkgdir /opt/rocm/bin/$_compiler "
118163 done
119164
@@ -127,6 +172,9 @@ package_rocm-llvm() {
127172 install -Dm644 clang-tools-extra/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /clang-tools-extra-LICENSE"
128173 install -Dm644 compiler-rt/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /compiler-rt-LICENSE"
129174 install -Dm644 lld/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /lld-LICENSE"
175+ install -Dm644 flang/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /flang-LICENSE"
176+ install -Dm644 flang-rt/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /flang-rt-LICENSE"
177+ install -Dm644 mlir/LICENSE.TXT " $pkgdir /usr/share/licenses/$pkgname /mlir-LICENSE"
130178}
131179
132180package_rocm-device-libs () {
0 commit comments