# Please keep this package sync with FC %{!?__cmake_builddir:%global __cmake_builddir %{_vpath_builddir}} %global maj_ver 20 %global min_ver 1 %global patch_ver 3 #global rc_ver 3 %global flang_version %{maj_ver}.%{min_ver}.%{patch_ver} %global srcdir llvm-project-%{flang_version}%{?rc_ver:-rc%{rc_ver}}.src %global toolchain clang %global major %{maj_ver}.%{min_ver} %global libname %mklibname flang %{major} %global devname %mklibname flang -d # Opt out of https://fedoraproject.org/wiki/Changes/fno-omit-frame-pointer # https://bugzilla.redhat.com/show_bug.cgi?id=2158587 %undefine _include_frame_pointers Name: flang Version: %{flang_version}%{?rc_ver:~rc%{rc_ver}} Release: %mkrel 1 Summary: a Fortran language front-end designed for integration with LLVM Group: Development/Other License: Apache-2.0 WITH LLVM-exception URL: https://flang.llvm.org Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{flang_version}%{?rc_ver:-rc%{rc_ver}}/%{srcdir}.tar.xz Source1: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{flang_version}%{?rc_ver:-rc%{rc_ver}}/%{srcdir}.tar.xz.sig Source2: release-keys.asc Source8: omp_lib.h Source9: omp_lib.F90 # The Bye plugin is not distributed on Fedora. Patch3: 0001-flang-Remove-the-dependency-on-Bye.patch # Fedora uses CLANG_DEFAULT_PIE_ON_LINUX=OFF. Patch5: 0001-Match-Fedora-s-value-for-CLANG_DEFAULT_PIE_ON_LINUX.patch # Fix for standalone builds. Avoid running on non-x86 targets. Patch6: 0001-Fix-fastmath-test.patch %{lua: -- Return the maximum number of parallel jobs a build can run based on the -- amount of maximum memory used per process (per_proc_mem). function print_max_procs(per_proc_mem) local f = io.open("/proc/meminfo", "r") local mem = 0 local nproc_str = nil for line in f:lines() do _, _, mem = string.find(line, "MemTotal:%s+(%d+)%s+kB") if mem then break end end f:close() local proc_handle = io.popen("nproc") _, _, nproc_str = string.find(proc_handle:read("*a"), "(%d+)") proc_handle:close() local nproc = tonumber(nproc_str) if nproc < 1 then nproc = 1 end local mem_mb = mem / 1024 local cpu = math.floor(mem_mb / per_proc_mem) if cpu < 1 then cpu = 1 end if cpu > nproc then cpu = nproc end print(cpu) end } # Avoid gcc reaching 4GB of memory on 32-bit targets and also running out of # memory on builders with many CPUs. %global _lto_cflags %{nil} # The amount of RAM used per process has been set by trial and error. # This number may increase/decrease from time to time and may require changes. # We prefer to be on the safe side in order to avoid spurious errors. %global _smp_mflags -j%{lua: print_max_procs(6144)} # We don't produce debug info on ARM to avoid OOM during the build. %ifarch %{arm} %global debug_package %{nil} %endif # Link error on i686. # s390x is not supported upstream yet. ExcludeArch: %{ix86} s390x %{arm32} BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: cmake BuildRequires: zlib-devel BuildRequires: llvm-devel = %{version} BuildRequires: llvm-cmake-utils = %{version} BuildRequires: llvm-test = %{version} BuildRequires: llvm-googletest = %{version} BuildRequires: mlir-devel = %{version} BuildRequires: ninja-build BuildRequires: python3-lit >= 12.0.0 BuildRequires: python3-sphinx BuildRequires: python3-recommonmark BuildRequires: python3-myst-parser BuildRequires: doxygen BuildRequires: compiler-rt # The new flang drive requires clang-devel BuildRequires: clang-devel = %{version} # For origin certification BuildRequires: gnupg2 Requires: %{name}-runtime = %{version}-%{release} # flang installs headers in the clang resource directory Requires: clang-resource-filesystem = %{version} %if ! 0%{?mageia:1} # Up to version 17.0.6-1, flang used to provide a flang-devel package. # This changed in 17.0.6-2 and all development-related files are now # distributed in the main flang package. Obsoletes: flang-devel < 17.0.6-2 %endif %description Flang is a ground-up implementation of a Fortran front end written in modern C++. %package doc Summary: Documentation for Flang BuildArch: noarch Recommends: %{name} >= %{version}-%{release} %description doc Documentation for Flang. %package -n %{libname} Summary: Flang runtime libraries Group: System/Libraries Provides: %{name}-runtime%{?_isa} = %{version}-%{release} Provides: %{name}-runtime = %{version}-%{release} %description -n %{libname} Flang runtime libraries. %package -n %{devname} Summary: Development header files for flang Group: Development/Other Provides: flang-devel%{?_isa} = %{version}-%{release} Provides: flang-devel = %{version}-%{release} Requires: %{name}-runtime%{?_isa} = %{version}-%{release} Requires: %{name}%{?_isa} = %{version}-%{release} %description -n %{devname} Flang header files. %prep %{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}' %autosetup -n %{srcdir} -p1 mkdir -p flang/%{__cmake_builddir}/projects/openmp/runtime/src/ cp %{SOURCE8} flang/%{__cmake_builddir}/projects/openmp/runtime/src/ cp %{SOURCE9} flang/%{__cmake_builddir}/projects/openmp/runtime/src/ %build cd flang %cmake -GNinja \ -DLLVM_TOOL_OPENMP_BUILD:BOOL=ON \ -DMLIR_TABLEGEN_EXE=%{_bindir}/mlir-tblgen \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_RPATH=";" \ -DMLIR_DIR=%{_libdir}/cmake/mlir \ -DLLVM_DIR=%{_libdir}/cmake/llvm \ -DCLANG_DIR=%{_libdir}/cmake/clang \ -DCLANG_LINK_CLANG_DYLIB:BOOL=ON \ -DCLANG_RESOURCE_DIR=../../%{clang_resource_dir} \ -DBUILD_SHARED_LIBS:BOOL=ON \ -DLLVM_LINK_LLVM_DYLIB:BOOL=ON \ -DLLVM_EXTERNAL_LIT=%{_bindir}/lit \ -DCMAKE_PREFIX_PATH=%{_libdir}/cmake/llvm/ \ -DMLIR_LINK_MLIR_DYLIB:BOOL=ON \ \ -DFLANG_INCLUDE_DOCS:BOOL=ON \ -DLLVM_ENABLE_SPHINX:BOOL=ON \ -DSPHINX_WARNINGS_AS_ERRORS=OFF \ -DSPHINX_EXECUTABLE=%{_bindir}/sphinx-build-3 \ \ %if 0%{?__isa_bits} == 64 -DLLVM_LIBDIR_SUFFIX=64 %else -DLLVM_LIBDIR_SUFFIX= %endif # Avoid gcc reaching 4GB of memory %ifarch %{ix86} s390x %{arm32} sed -i -e 's/-g /-g1 /g' %{__cmake_builddir}/build.ninja %endif # On ARM, disable debuginfo entirely to avoid OOM. %ifarch %{arm} sed -i -e 's/-g /-g0 /g' -e 's/-O2/-O1/g' %{__cmake_builddir}/build.ninja %endif export LD_LIBRARY_PATH=%{_builddir}/%{srcdir}/flang/%{_build}/lib:%{clang_resource_dir}/lib/%{_build} %cmake_build %cmake_build --target docs-flang-html %install cd flang %cmake_install %if ! 0%{?mageia:1} # Remove unnecessary files. rm -rf %{buildroot}/%{_libdir}/cmake/ rm -f %{buildroot}/%{_libdir}/libFIRAnalysis.so \ %{buildroot}/%{_libdir}/libFIRBuilder.so \ %{buildroot}/%{_libdir}/libFIRCodeGen.so \ %{buildroot}/%{_libdir}/libFIRDialect.so \ %{buildroot}/%{_libdir}/libFIRDialectSupport.so \ %{buildroot}/%{_libdir}/libFIROpenACCSupport.so \ %{buildroot}/%{_libdir}/libFIRSupport.so \ %{buildroot}/%{_libdir}/libFIRTestAnalysis.so \ %{buildroot}/%{_libdir}/libFIRTestOpenACCInterfaces.so \ %{buildroot}/%{_libdir}/libFIRTransforms.so \ %{buildroot}/%{_libdir}/libflangFrontend.so \ %{buildroot}/%{_libdir}/libflangFrontendTool.so \ %{buildroot}/%{_libdir}/libflangPasses.so \ %{buildroot}/%{_libdir}/libFlangOpenMPTransforms.so \ %{buildroot}/%{_libdir}/libFortranCommon.so \ %{buildroot}/%{_libdir}/libFortranEvaluate.so \ %{buildroot}/%{_libdir}/libFortranLower.so \ %{buildroot}/%{_libdir}/libFortranParser.so \ %{buildroot}/%{_libdir}/libFortranSemantics.so \ %{buildroot}/%{_libdir}/libFortranSupport.so \ %{buildroot}/%{_libdir}/libHLFIRDialect.so \ %{buildroot}/%{_libdir}/libHLFIRTransforms.so %endif find %{buildroot}/%{_includedir}/flang -type f -a ! -iname '*.mod' -delete # this is a test binary rm -f %{buildroot}%{_bindir}/f18-parse-demo install -d %{buildroot}%{_pkgdocdir}/html cp -r %{_vpath_builddir}/docs/html/* %{buildroot}%{_pkgdocdir}/html/ %check cd flang %ifarch s390x rm test/Evaluate/folding07.f90 rm test/Evaluate/fold-nearest.f90 # s390x is not yet supported as a lowering target, so remove all related tests. rm -rf test/Driver/ rm -rf test/Fir/ rm -rf test/Lower/ %endif # These tests fail on 32-bit targets. %ifarch %{ix86} %{arm} rm -f test/Fir/fir-ops.fir rm -f test/Semantics/assign03.f90 rm -f test/Semantics/data05.f90 rm -f test/Semantics/offsets01.f90 rm -f test/Semantics/offsets02.f90 rm -f test/Semantics/typeinfo01.f90 rm -f test/Semantics/spec-expr.f90 rm -f test/Evaluate/folding19.f90 %endif # https://github.com/llvm/llvm-project/issues/126051 rm -rf test/Driver/linker-flags.f90 export LD_LIBRARY_PATH=%{_builddir}/%{srcdir}/flang/%{_build}/lib:%{clang_resource_dir}/lib/%{_build} %cmake_build --target check-flang %files %license LICENSE.TXT %{_bindir}/tco %{_bindir}/bbc %{_bindir}/fir-opt %{_bindir}/fir-lsp-server %{_bindir}/flang %{_bindir}/flang-%{maj_ver} %{_bindir}/flang-new %files -n %libname %{_libdir}/libFIRAnalysis.so.%{major}{,.*} %{_libdir}/libFIRBuilder.so.%{major}{,.*} %{_libdir}/libFIRCodeGen.so.%{major}{,.*} %{_libdir}/libFIRDialect.so.%{major}{,.*} %{_libdir}/libFIRDialectSupport.so.%{major}{,.*} %{_libdir}/libFIROpenACCSupport.so.%{major}{,.*} %{_libdir}/libFIRSupport.so.%{major}{,.*} %{_libdir}/libFIRTestAnalysis.so.%{major}{,.*} %{_libdir}/libFIRTestOpenACCInterfaces.so.%{major}{,.*} %{_libdir}/libFIRTransforms.so.%{major}{,.*} %{_libdir}/libflangFrontend.so.%{major}{,.*} %{_libdir}/libflangFrontendTool.so.%{major}{,.*} %{_libdir}/libflangPasses.so.%{major}{,.*} %{_libdir}/libFlangOpenMPTransforms.so.%{major}{,.*} %{_libdir}/libFortranCommon.so.%{major}{,.*} %{_libdir}/libFortranDecimal.so.%{major}{,.*} %{_libdir}/libFortranEvaluate.so.%{major}{,.*} %{_libdir}/libFortranLower.so.%{major}{,.*} %{_libdir}/libFortranParser.so.%{major}{,.*} %{_libdir}/libFortranRuntime.so.%{major}{,.*} %{_libdir}/libFortranSemantics.so.%{major}{,.*} %{_libdir}/libFortranSupport.so.%{major}{,.*} %{_libdir}/libHLFIRDialect.so.%{major}{,.*} %{_libdir}/libHLFIRTransforms.so.%{major}{,.*} %{_libdir}/libCUFAttrs.so.%{major}{,.*} %{_libdir}/libCUFDialect.so.%{major}{,.*} %files -n %devname %{_libdir}/libFIRAnalysis.so %{_libdir}/libFIRBuilder.so %{_libdir}/libFIRCodeGen.so %{_libdir}/libFIRDialect.so %{_libdir}/libFIRDialectSupport.so %{_libdir}/libFIRSupport.so %{_libdir}/libFIRTestAnalysis.so %{_libdir}/libFIRTestOpenACCInterfaces.so %{_libdir}/libFIRTransforms.so %{_libdir}/libflangFrontend.so %{_libdir}/libflangFrontendTool.so %{_libdir}/libflangPasses.so %{_libdir}/libFlangOpenMPTransforms.so %{_libdir}/libFortranCommon.so %{_libdir}/libFortranDecimal.so %{_libdir}/libFortranEvaluate.so %{_libdir}/libFortranLower.so %{_libdir}/libFortranParser.so %{_libdir}/libFortranRuntime.so %{_libdir}/libFortranSemantics.so %{_libdir}/libFortranSupport.so %{_libdir}/libHLFIRDialect.so %{_libdir}/libHLFIRTransforms.so %{_libdir}/libCUFAttrs.so %{_libdir}/libCUFDialect.so %{_includedir}/flang/ %{_libdir}/cmake/ %{clang_resource_dir}/include/ISO_Fortran_binding.h %files doc %dir %{_pkgdocdir} %doc %{_pkgdocdir}/html/