Skip to content

Commit

Permalink
Fix tests on systems that do not have clang installed
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Jul 25, 2023
1 parent 1c17e36 commit 6b65ba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pycheribuild/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,18 +1029,17 @@ def add_lto_build_options(self, ccinfo: CompilerInfo) -> bool:
return False
ld = lld if self.lto_set_ld else None
self.set_lto_binutils(ar=llvm_ar, ranlib=llvm_ranlib, nm=llvm_nm, ld=ld)
if self.prefer_full_lto_over_thin_lto:
if self.prefer_full_lto_over_thin_lto or not self.can_use_thinlto(ccinfo):
self._lto_compiler_flags.append("-flto")
self._lto_linker_flags.append("-flto")
else:
self._lto_compiler_flags.append("-flto=thin")
self._lto_linker_flags.append("-flto=thin")
if self.can_use_lld(ccinfo.path):
thinlto_cache_flag = "--thinlto-cache-dir="
else:
if ccinfo.compiler == "apple-clang":
# Apple ld uses a different flag for the thinlto cache dir
assert ccinfo.compiler == "apple-clang"
thinlto_cache_flag = "-cache_path_lto,"
else:
thinlto_cache_flag = "--thinlto-cache-dir="
self._lto_linker_flags.append("-Wl," + thinlto_cache_flag + str(self.build_dir / "thinlto-cache"))
if self.compiling_for_cheri_hybrid([CPUArchitecture.AARCH64]):
# Hybrid flags are not inferred from the input files, so we have to explicitly pass -mattr= to ld.lld.
Expand Down
14 changes: 10 additions & 4 deletions tests/test_argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,17 @@ def enable_projects_flag(args: "list[str]"):
"llvm-native", config, BuildCheriLLVM).configure_args) == "-DLLVM_ENABLE_PROJECTS=llvm"


def test_llvm_lto_options():
config = _parse_arguments(["--llvm/use-lto"])
@pytest.mark.parametrize("args", [
pytest.param([], id="default-compiler"),
pytest.param(["--cc-path=/usr/bin/gcc"], id="gcc"),
pytest.param(["--cc-path=/this/compiler/does/not/exist"], id="invalid"),
])
def test_llvm_lto_options(args: "list[str]"):
config = _parse_arguments(["--llvm/use-lto", *args])
llvm = _get_target_instance("llvm-native", config, BuildCheriLLVM)
# depending on the host compiler we could be using ThinLTO (if supported) or full LTO.
assert "-DLLVM_ENABLE_LTO=Thin" in llvm.configure_args or "-DLLVM_ENABLE_LTO=TRUE" in llvm.configure_args
if config.clang_path.exists():
# depending on the host compiler we could be using ThinLTO (if supported) or full LTO.
assert "-DLLVM_ENABLE_LTO=Thin" in llvm.configure_args or "-DLLVM_ENABLE_LTO=TRUE" in llvm.configure_args
args_containing_flto = [x for x in llvm.configure_args if "_FLAGS_INIT=" in x and "-flto" in x]
# The LLVM build system includes logic to set the correct LTO flags. It also avoids building tests with LTO to
# reduce the build time. Explicitly adding the CFLAGS/LDFLAGS here breaks this optimization.
Expand Down

0 comments on commit 6b65ba0

Please sign in to comment.