Skip to content

Commit

Permalink
LLVM_ENABLE_RUNTIMES=flang-rt for flang-aarch64-out-of-tree (#388)
Browse files Browse the repository at this point in the history
Make `FlangBuilder.getFlangOutOfTreeBuildFactory` build the flang-rt
runtime as an out-of-tree runtimes build with additional steps.

Fixes some issues with FlangBuilder too:
* Clears the build directories with the clean_obj flag set. Usually
buildbot deletes the build directory whenever a CMakeLists.txt in a
depends_on_projects subdirectory changes to get a clean build.
Otherwise, an incompatible CMakeCache.txt will carry on forever.
* Add `flang` and `flang-rt` as depends_on_projects. Otherwise, changes
in these subdirectories do not trigger a build. Even worse, breaking
commits will be attributed to the next commit in llvm/clang/mlir/openmp,
as happed in e.g.
https://lab.llvm.org/buildbot/#/builders/53/builds/11759 
(commit causing the failure was
llvm/llvm-project@fe8b323
)

This PR is not strictly necessary for
llvm/llvm-project#124126, it just wouldn't build
the runtime anymore.

Affected builders:
 * flang-aarch64-out-of-tree

Affected workers: 
 * linaro-flang-aarch64-out-of-tree

Tested locally on x86_64.
  • Loading branch information
Meinersbur authored Mar 7, 2025
1 parent 17c126f commit f754b71
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
3 changes: 3 additions & 0 deletions buildbot/osuosl/master/config/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,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",
]

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

0 comments on commit f754b71

Please sign in to comment.