Skip to content

Commit

Permalink
Remove LLVM imports from compilation_targets
Browse files Browse the repository at this point in the history
This speeds up pytype by another 10 seconds by improving parallelism.
  • Loading branch information
arichardson committed Dec 11, 2023
1 parent f6b50c1 commit ce9b862
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 46 deletions.
65 changes: 26 additions & 39 deletions pycheribuild/config/compilation_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@
from ..projects.simple_project import SimpleProject
from ..utils import cached_property, is_jenkins_build, warning_message

if typing.TYPE_CHECKING: # no-combine
from ..projects.cross.llvm import BuildLLVMMonoRepoBase # no-combine

class BuildLLVMInterface(Project if typing.TYPE_CHECKING else object):
@classmethod
def get_native_install_path(cls, config: CheriConfig) -> Path:
# This returns the path where the installed compiler is expected to be
# Note: When building LLVM in Jenkins this will not match the install_directory
raise NotImplementedError()


class LaunchFreeBSDInterface:
Expand Down Expand Up @@ -109,7 +114,7 @@ def sdk_root_dir(self) -> Path:
return self._sdk_root_dir

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
raise NotImplementedError()

def _get_sdk_root_dir_lazy(self) -> Path:
Expand Down Expand Up @@ -455,10 +460,8 @@ def localbase(self) -> Path:
return Path("usr/local")

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildUpstreamLLVM

return BuildUpstreamLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("upstream-llvm", None))

def _get_rootfs_class(self, xtarget: "CrossCompileTarget") -> "type[Project]":
return Project.get_class_for_target_name("freebsd", xtarget)
Expand Down Expand Up @@ -625,10 +628,8 @@ class CheriBSDTargetInfo(FreeBSDTargetInfo):
FREEBSD_VERSION: int = 13

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriLLVM

return BuildCheriLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("llvm", None))

def _get_run_project(self, xtarget: "CrossCompileTarget", caller: SimpleProject) -> LaunchFreeBSDInterface:
result = SimpleProject.get_instance_for_target_name("run", xtarget, caller.config, caller)
Expand Down Expand Up @@ -704,10 +705,8 @@ class CheriBSDMorelloTargetInfo(CheriBSDTargetInfo):
uses_morello_llvm: bool = True

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildMorelloLLVM

return BuildMorelloLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("morello-llvm", None))

@classmethod
def triple_for_target(cls, target: "CrossCompileTarget", config, *, include_version):
Expand Down Expand Up @@ -757,10 +756,8 @@ def _get_sdk_root_dir_lazy(self) -> Path:
return self._get_compiler_project().get_native_install_path(self.config)

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriOSLLVM

return BuildCheriOSLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("cherios-llvm", None))

@property
def sysroot_dir(self):
Expand Down Expand Up @@ -826,10 +823,8 @@ def sysroot_install_prefix_relative(self) -> Path:
return Path(self.target_triple)

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriLLVM

return BuildCheriLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("llvm", None))

@property
def must_link_statically(self):
Expand Down Expand Up @@ -885,10 +880,8 @@ def sysroot_dir(self) -> Path:
return sysroot_dir / "baremetal" / suffix

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriLLVM

return BuildCheriLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("llvm", None))

@classmethod
def triple_for_target(cls, target, config, include_version: bool) -> str:
Expand Down Expand Up @@ -958,10 +951,8 @@ def sysroot_dir(self) -> Path:
return sysroot_dir / "picolibc" / self.target.get_rootfs_target().generic_arch_suffix

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriLLVM

return BuildCheriLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("llvm", None))

def semihosting_ldflags(self) -> "list[str]":
stack_size = "4k"
Expand Down Expand Up @@ -1009,10 +1000,8 @@ class BaremetalFreestandingTargetInfo(BaremetalClangTargetInfo):
os_prefix: str = "baremetal-"

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildCheriLLVM

return BuildCheriLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("llvm", None))

@classmethod
def base_sysroot_targets(cls, target: "CrossCompileTarget", config: "CheriConfig") -> "list[str]":
Expand All @@ -1034,10 +1023,8 @@ class MorelloBaremetalTargetInfo(BaremetalFreestandingTargetInfo):
uses_morello_llvm: bool = True

@classmethod
def _get_compiler_project(cls) -> "type[BuildLLVMMonoRepoBase]":
from ..projects.cross.llvm import BuildMorelloLLVM

return BuildMorelloLLVM
def _get_compiler_project(cls) -> "type[BuildLLVMInterface]":
return typing.cast("type[BuildLLVMInterface]", Project.get_class_for_target_name("morello-llvm", None))

@property
def sysroot_dir(self) -> Path:
Expand Down
9 changes: 2 additions & 7 deletions pycheribuild/projects/cross/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from ..simple_project import SimpleProject
from ...config.chericonfig import CheriConfig
from ...config.compilation_targets import (
BuildLLVMInterface,
CheriBSDMorelloTargetInfo,
CheriBSDTargetInfo,
CompilationTargets,
Expand Down Expand Up @@ -556,7 +557,7 @@ def prepare_install_dir_for_archiving(self):
self.run_cmd("du", "-sh", self.install_dir)


class BuildLLVMMonoRepoBase(BuildLLVMBase):
class BuildLLVMMonoRepoBase(BuildLLVMBase, BuildLLVMInterface):
do_not_add_to_targets = True
root_cmakelists_subdirectory = Path("llvm")

Expand Down Expand Up @@ -626,12 +627,6 @@ def process(self):
)
return super().process()

@classmethod
def get_native_install_path(cls, config: CheriConfig):
# This returns the path where the installed compiler is expected to be
# Note: When building LLVM in Jenkins this will not match the install_directory
raise NotImplementedError()


class BuildCheriLLVM(BuildLLVMMonoRepoBase):
repository = GitRepository("https://github.com/CTSRD-CHERI/llvm-project.git")
Expand Down

0 comments on commit ce9b862

Please sign in to comment.