Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM_ENABLE_RUNTIMES=flang-rt for flang-aarch64-out-of-tree #388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildbot/osuosl/master/config/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,9 @@
flang_extra_configure_args=[
"-DFLANG_ENABLE_WERROR=ON",
"-DCMAKE_BUILD_TYPE=Release",
],
flang_rt_extra_configure_args=[
"-DCMAKE_BUILD_TYPE=Release",
])},

{'name' : "flang-aarch64-debug-reverse-iteration",
Expand Down
77 changes: 76 additions & 1 deletion zorg/buildbot/builders/FlangBuilder.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from zorg.buildbot.commands.CmakeCommand import CmakeCommand
from zorg.buildbot.process.factory import LLVMBuildFactory
from zorg.buildbot.builders.UnifiedTreeBuilder import addNinjaSteps, getCmakeWithNinjaBuildFactory
from buildbot.plugins import util, steps
import os

def getFlangOutOfTreeBuildFactory(
checks = None,
clean = False,
llvm_extra_configure_args = None,
flang_extra_configure_args = None,
flang_rt_extra_configure_args = None,
env = None,
**kwargs):

if env is None:
env = dict()

f = getCmakeWithNinjaBuildFactory(
depends_on_projects=['llvm','clang','mlir','openmp'],
depends_on_projects=['llvm','clang','mlir','openmp','flang','flang-rt'],
enable_projects=['llvm','clang','mlir'],
enable_runtimes=['openmp'],
obj_dir="build_llvm",
checks=[],
clean=clean,
Expand All @@ -25,6 +30,12 @@ def getFlangOutOfTreeBuildFactory(
if checks is None:
checks = ['check-all']

cleanBuildRequested = (
lambda step: step.build.getProperty("clean")
or step.build.getProperty("clean_obj")
or clean
)

# Make a local copy of the flang configure args, as we are going to modify that.
if flang_extra_configure_args:
flang_cmake_args = flang_extra_configure_args[:]
Expand Down Expand Up @@ -52,6 +63,16 @@ def getFlangOutOfTreeBuildFactory(
LLVMBuildFactory.pathRelativeTo(clang_dir, flang_obj_dir)),
])

f.addStep(
steps.RemoveDirectory(
name=f"clean-{flang_obj_dir}-dir",
dir=flang_obj_dir,
haltOnFailure=False,
flunkOnFailure=False,
doStepIf=cleanBuildRequested,
)
)

# We can't use addCmakeSteps as that would use the path in f.llvm_srcdir.
f.addStep(CmakeCommand(name="cmake-configure-flang",
haltOnFailure=True,
Expand All @@ -71,4 +92,58 @@ def getFlangOutOfTreeBuildFactory(
stage_name="flang",
**kwargs)

## Build Flang-RT as a standalone runtime
flang_rt_obj_dir = "build_flang-rt"

flang_rt_cmake_args = ["-GNinja"]
if flang_rt_extra_configure_args:
flang_rt_cmake_args += flang_rt_extra_configure_args

# Use LLVM from the getCmakeWithNinjaBuildFactory step.
flang_rt_cmake_args += [
util.Interpolate(f"-DLLVM_BINARY_DIR=%(prop:builddir)s/{f.obj_dir}"),
"-DLLVM_ENABLE_RUNTIMES=flang-rt",
]

# Use the Fortran compiler from the previous step.
flang_rt_cmake_args += [
util.Interpolate(
f"-DCMAKE_Fortran_COMPILER=%(prop:builddir)s/{flang_obj_dir}/bin/flang"
),
"-DCMAKE_Fortran_COMPILER_WORKS=ON",
]
Comment on lines +108 to +114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to use the C/C++ compiler from the previous step too?

Copy link
Member Author

@Meinersbur Meinersbur Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be possible, but not necessary. We already many builders that are using the bootstrapping build (which by design use just-built Clang to build the runtime), keeping at least one that also tests compilation with gcc might be a good idea. The other one that explicitly uses gcc, flang-runtime-cuda-gcc, is a bootstrapping build, therefore effectively changed to use Clang to build flang-rt in #393.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that the existing bot does not use the clang from the previous step, so I'm in favour of leaving this as it is just for that reason.

We have other 2 stage bots that enable flang, and I expect most out of tree problems to be found by a single stage build anyway.


f.addStep(
steps.RemoveDirectory(
name=f"clean-{flang_rt_obj_dir}-dir",
dir=flang_rt_obj_dir,
haltOnFailure=False,
flunkOnFailure=False,
doStepIf=cleanBuildRequested,
)
)

f.addStep(
CmakeCommand(
name="cmake-configure-flang-rt",
haltOnFailure=True,
description=["CMake", "configure", "Flang-RT"],
options=flang_rt_cmake_args,
path=LLVMBuildFactory.pathRelativeTo(
os.path.join(f.monorepo_dir, "runtimes"), flang_rt_obj_dir
),
env=env,
workdir=flang_rt_obj_dir,
**kwargs,
)
)

addNinjaSteps(
f,
obj_dir=flang_rt_obj_dir,
checks=['check-flang-rt'],
env=env,
stage_name="flang-rt",
**kwargs)

return f
8 changes: 8 additions & 0 deletions zorg/buildbot/builders/UnifiedTreeBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

def getLLVMBuildFactoryAndPrepareForSourcecodeSteps(
depends_on_projects = None,
enable_projects = "auto",
enable_runtimes = "auto",
llvm_srcdir = None,
src_to_build_dir = None,
Expand All @@ -34,6 +35,7 @@ def cleanBuildRequestedByProperty(step):

f = LLVMBuildFactory(
depends_on_projects=depends_on_projects,
enable_projects=enable_projects,
enable_runtimes=enable_runtimes,
llvm_srcdir=llvm_srcdir,
src_to_build_dir=src_to_build_dir,
Expand All @@ -56,6 +58,7 @@ def cleanBuildRequestedByProperty(step):

def getLLVMBuildFactoryAndSourcecodeSteps(
depends_on_projects = None,
enable_projects = "auto",
enable_runtimes = "auto",
llvm_srcdir = None,
src_to_build_dir = None,
Expand All @@ -66,6 +69,7 @@ def getLLVMBuildFactoryAndSourcecodeSteps(

f = getLLVMBuildFactoryAndPrepareForSourcecodeSteps(
depends_on_projects=depends_on_projects,
enable_projects=enable_projects,
enable_runtimes=enable_runtimes,
llvm_srcdir=llvm_srcdir,
src_to_build_dir=src_to_build_dir,
Expand Down Expand Up @@ -254,6 +258,7 @@ def trunc50(name):

def getCmakeBuildFactory(
depends_on_projects = None,
enable_projects = "auto",
enable_runtimes = "auto",
llvm_srcdir = None,
src_to_build_dir = None,
Expand All @@ -267,6 +272,7 @@ def getCmakeBuildFactory(

f = getLLVMBuildFactoryAndSourcecodeSteps(
depends_on_projects=depends_on_projects,
enable_projects=enable_projects,
enable_runtimes=enable_runtimes,
llvm_srcdir=llvm_srcdir,
src_to_build_dir=src_to_build_dir,
Expand Down Expand Up @@ -298,6 +304,7 @@ def getCmakeBuildFactory(

def getCmakeWithNinjaBuildFactory(
depends_on_projects = None,
enable_projects = "auto",
enable_runtimes = "auto",
targets = None,
llvm_srcdir = None,
Expand Down Expand Up @@ -335,6 +342,7 @@ def getCmakeWithNinjaBuildFactory(

f = getCmakeBuildFactory(
depends_on_projects=depends_on_projects,
enable_projects=enable_projects,
enable_runtimes=enable_runtimes,
llvm_srcdir=llvm_srcdir,
src_to_build_dir=src_to_build_dir,
Expand Down
24 changes: 18 additions & 6 deletions zorg/buildbot/process/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,25 @@ def __init__(self, steps=None, depends_on_projects=None, hint=None, **kwargs):
# Let's just use the given list, no need to discover.
self.enable_runtimes = frozenset(enable_runtimes)

# Update the list of dependencies.
if depends_on_projects is None:
self.depends_on_projects.update(self.enable_runtimes)

# Build the list of projects to enable.
self.enable_projects = \
self.depends_on_projects.difference(self.enable_runtimes)
enable_projects = kwargs.pop('enable_projects', None)
if enable_projects is None or enable_projects == "auto":
# Assume that all non-runtimes depends_on_projects dirs are projects.
self.enable_projects = \
self.depends_on_projects.difference(self.enable_runtimes)
elif enable_projects == "all":
raise Exception("enable_projects='all' not yet supported")
else:
self.enable_projects = frozenset(enable_projects)

# Update the list of dependencies.
if depends_on_projects is None:
self.depends_on_projects.update(self.enable_projects)
self.depends_on_projects.update(self.enable_runtimes)

assert self.enable_projects.issubset(self.depends_on_projects), \
"all enable_projects must be listed in depends_on_projects, or it will be skipped by the scheduler"
#FIXME: The same must hold for self.enable_runtimes but some builders violate it.

# Directories.
self.monorepo_dir = kwargs.pop('llvm_srcdir', None)
Expand Down