Skip to content

Commit

Permalink
FlangClassic: Split Compiler and RTLib (#5316)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno authored Aug 16, 2022
1 parent dba5be5 commit d7d5cf9
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 84 deletions.
20 changes: 20 additions & 0 deletions F/FlangClassic/FlangClassic/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name = "FlangClassic"
version = v"13.0.0"

include("../common.jl")

# The products that we will ensure are always built
products = Product[
ExecutableProduct("flang", :flang),
ExecutableProduct("flang1", :flang1),
ExecutableProduct("flang2", :flang2)
]

# We only build the compiler for musl. The rtlibs get built for all platforms in the RTLib jll
platforms = [
Platform("x86_64", "linux"; libc = "musl"),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, flang_script(true), platforms, products, dependencies;
julia_compat="1.6", preferred_gcc_version=v"10", lock_microarchitecture=false)
23 changes: 23 additions & 0 deletions F/FlangClassic/FlangClassic_RTLib/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "FlangClassic_RTLib"
version = v"13.0.0"

include("../common.jl")

push!(dependencies,
HostBuildDependency("FlangClassic_jll")
)

products = Product[
LibraryProduct("libflang", :libflang),
LibraryProduct("libflangrti", :libflangrti),
LibraryProduct("libompstub", :libompstub)
]

platforms = [
Platform("x86_64", "linux"; libc = "musl"),
Platform("x86_64", "linux"; libc = "glibc"),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, flang_script(false), platforms, products, dependencies;
julia_compat="1.6", preferred_gcc_version=v"10", lock_microarchitecture=false)
84 changes: 0 additions & 84 deletions F/FlangClassic/build_tarballs.jl

This file was deleted.

47 changes: 47 additions & 0 deletions F/FlangClassic/bundled/patches/flang-no-tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt
index aefc4a4a..ca0a8312 100644
--- a/runtime/flang/CMakeLists.txt
+++ b/runtime/flang/CMakeLists.txt
@@ -457,7 +457,6 @@ add_custom_command(
> "${I8_FILES_DIR}/ieee_arithmetic.F95"
COMMENT "Preprocessing ieee_arithmetic.F95"
VERBATIM
- DEPENDS flang1 flang2
)

add_custom_command(
@@ -467,7 +466,6 @@ add_custom_command(
> "${I8_FILES_DIR}/ieee_exceptions.F95"
COMMENT "Preprocessing ieee_exceptions.F95"
VERBATIM
- DEPENDS flang1 flang2
)

add_custom_command(
@@ -477,7 +475,6 @@ add_custom_command(
COMMAND "${CMAKE_Fortran_COMPILER}" -E -DPGFLANG -cpp ${SEPARATED_CMAKE_Fortran_FLAGS}
${CMAKE_CURRENT_SOURCE_DIR}/norm2.F95 > "norm2_1.F95"
VERBATIM
- DEPENDS flang1 flang2
)

# REAL*16 is not yet available on all platforms.
@@ -697,18 +694,6 @@ target_include_directories(flang_shared
${CMAKE_CURRENT_BINARY_DIR}
)

-# Make sure the compiler is built before we bootstrap
-add_dependencies(flang_static
- flang1
- flang2
- )
-
-# Make sure the compiler is built before we bootstrap
-add_dependencies(flang_shared
- flang1
- flang2
- )
-
if (NOT MSVC)
target_compile_options(flang_static PRIVATE -fPIC)
target_compile_options(flang_shared PRIVATE -fPIC)
93 changes: 93 additions & 0 deletions F/FlangClassic/common.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

# Collection of sources required to complete build
sources = [
GitSource("https://github.com/flang-compiler/flang.git", "a459f3ca34b244c6c1e59d6495e8ec90952c2448"),
GitSource("https://github.com/flang-compiler/classic-flang-llvm-project.git", "528906c87cd4cae63a52c3170365cb382daf94cb"),
DirectorySource(joinpath(@__DIR__, "bundled"))
]

# Bash recipe for building across all platforms
function flang_script(build_compiler)
script = build_compiler ? "export build_compiler=1\n" : "export build_compiler=0\n"
script *= raw"""
cd $WORKSPACE/srcdir
# Clear clang leftovers
rm /workspace/x86_64-linux-musl-cxx11/destdir/lib/libclang* || true
# Begin (LLVM + flang driver) build
mkdir llvm-build
cd llvm-build/
## Apply LLVM patches
atomic_patch -p1 -d ../classic-flang-llvm-project ../patches/0010-add-musl-triples.patch
atomic_patch -p1 -d ../classic-flang-llvm-project ../patches/nosincos.patch
## Configure & Build
if [[ ${build_compiler} == 1 ]]; then
export LLVM_TARGET="-DLLVM_ENABLE_CLASSIC_FLANG=ON -DLLVM_ENABLE_PROJECTS=clang;openmp ../classic-flang-llvm-project/llvm/"
else
export LLVM_TARGET="-DOPENMP_ENABLE_LIBOMPTARGET=OFF ../classic-flang-llvm-project/openmp"
fi
cmake -GNinja -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} -DCMAKE_BUILD_TYPE=Release ${LLVM_TARGET}
ninja
ninja install
install_license ../classic-flang-llvm-project/llvm/LICENSE.TXT
cd ..
# Begin pgmath build
mkdir pgmath-build
cd pgmath-build
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} -DCMAKE_BUILD_TYPE=Release ../flang/runtime/libpgmath/
ninja
ninja install
cd ..
# Begin Flang (Compiler/Runtime) build
mkdir flang-build
cd flang-build
## Apply flang patches
atomic_patch -p1 -d ../flang ../patches/musl-patches.patch
atomic_patch -p1 -d ../flang ../patches/no-fastmath.patch
atomic_patch -p1 -d ../flang ../patches/flang2-install-dir.patch
## Create Compiler wrapper for flang
if [[ ${build_compiler} == 1 ]]; then
# For the just-built compiler
cat /opt/bin/x86_64-linux-musl-cxx11/x86_64-linux-musl-clang | sed 's/clang/flang/g' > /opt/bin/${bb_full_target}/${target}-flang
chmod +x /opt/bin/${bb_full_target}/${target}-flang
ln -s ${WORKSPACE}/destdir/bin/flang /opt/x86_64-linux-musl/bin/flang
else
# For the host compiler
cat /opt/bin/${bb_full_target}/${target}-clang | sed 's/clang/flang/g' > /opt/bin/${bb_full_target}/${target}-flang
chmod +x /opt/bin/${bb_full_target}/${target}-flang
ln -s ${WORKSPACE}/x86_64-linux-musl-cxx11/destdir/bin/flang /opt/x86_64-linux-musl/bin/flang
# Disable building flang1/flang2
atomic_patch -p1 -d ../flang ../patches/flang-no-tools.patch
fi
export FC=${target}-flang
## Configure & Build
export PATH=${WORKSPACE}/srcdir/flang-build/bin:$PATH
cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_Fortran_COMPILER=${FC} -DCMAKE_Fortran_COMPILER_ID=Flang -DCMAKE_BUILD_TYPE=Release -DWITH_WERROR=OFF ../flang
if [[ ${build_compiler} == 1 ]]; then
make -j$(nproc)
make install
else
make -j$(nproc) -C runtime/
make -j$(nproc) -C runtime/ install
fi
install_license ../flang/LICENSE.txt
"""
end

# Dependencies that must be installed before this package can be built
dependencies = Any[
Dependency("Zlib_jll")
]

0 comments on commit d7d5cf9

Please sign in to comment.