-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[compiler-rt] Allow running tests without installing first #83088
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
Changes from 13 commits
3c41df9
494438e
eba1687
b4e0c27
413077b
3893ba4
54cdd2c
9c8044e
19ac5a9
32cc6e6
72ccac7
7678819
c4cb965
54b27e8
e1fb66b
c69a737
1576ce0
a6eb747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,27 @@ | |
import lit.util | ||
|
||
|
||
def get_path_from_clang(args, allow_failure): | ||
clang_cmd = [ | ||
config.clang.strip(), | ||
f"--target={config.target_triple}", | ||
*args, | ||
] | ||
path = None | ||
try: | ||
result = subprocess.run( | ||
clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True | ||
) | ||
path = result.stdout.decode().strip() | ||
except subprocess.CalledProcessError as e: | ||
msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}" | ||
if allow_failure: | ||
lit_config.warning(msg) | ||
else: | ||
lit_config.fatal(msg) | ||
return path, clang_cmd | ||
|
||
|
||
def find_compiler_libdir(): | ||
""" | ||
Returns the path to library resource directory used | ||
|
@@ -26,26 +47,6 @@ def find_compiler_libdir(): | |
# TODO: Support other compilers. | ||
return None | ||
|
||
def get_path_from_clang(args, allow_failure): | ||
clang_cmd = [ | ||
config.clang.strip(), | ||
f"--target={config.target_triple}", | ||
] | ||
clang_cmd.extend(args) | ||
path = None | ||
try: | ||
result = subprocess.run( | ||
clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True | ||
) | ||
path = result.stdout.decode().strip() | ||
except subprocess.CalledProcessError as e: | ||
msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}" | ||
if allow_failure: | ||
lit_config.warning(msg) | ||
else: | ||
lit_config.fatal(msg) | ||
return path, clang_cmd | ||
|
||
# Try using `-print-runtime-dir`. This is only supported by very new versions of Clang. | ||
# so allow failure here. | ||
runtime_dir, clang_cmd = get_path_from_clang( | ||
|
@@ -168,10 +169,45 @@ def push_dynamic_library_lookup_path(config, new_path): | |
r"/i386(?=-[^/]+$)", "/x86_64", config.compiler_rt_libdir | ||
) | ||
|
||
|
||
# Check if the test compiler resource dir matches the local build directory | ||
# (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are | ||
# using an installed clang to test compiler-rt standalone. In the latter case | ||
# we may need to override the resource dir to match the path of the just-built | ||
# compiler-rt libraries. | ||
test_cc_resource_dir, _ = get_path_from_clang( | ||
shlex.split(config.target_cflags) + ["-print-resource-dir"], allow_failure=True | ||
) | ||
# Normalize the path for comparison | ||
if test_cc_resource_dir is not None: | ||
test_cc_resource_dir = os.path.realpath(test_cc_resource_dir) | ||
if lit_config.debug: | ||
lit_config.note(f"Resource dir for {config.clang} is {test_cc_resource_dir}") | ||
local_build_resource_dir = os.path.realpath(config.compiler_rt_output_dir) | ||
if test_cc_resource_dir != local_build_resource_dir: | ||
if config.test_standalone_build_libs and config.compiler_id == "Clang": | ||
if lit_config.debug: | ||
lit_config.note( | ||
f"Overriding test compiler resource dir to use " | ||
f'libraries in "{config.compiler_rt_libdir}"' | ||
) | ||
# Ensure that we use the just-built static libraries when linking by | ||
# overriding the Clang resource directory. Additionally, we want to use | ||
# the builtin headers shipped with clang (e.g. stdint.h), so we | ||
# explicitly add this as an include path (since the headers are not | ||
# going to be in the current compiler-rt build directory). | ||
# We also tell the linker to add an RPATH entry for the local library | ||
# directory so that the just-built shared libraries are used. | ||
config.target_cflags += f" -nobuiltininc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this would be cleaner, I will submit an independent cleanup PR. |
||
config.target_cflags += f" -I{config.compiler_rt_src_root}/include" | ||
config.target_cflags += f" -idirafter {test_cc_resource_dir}/include" | ||
config.target_cflags += f" -resource-dir={config.compiler_rt_output_dir}" | ||
config.target_cflags += f" -Wl,-rpath,{config.compiler_rt_libdir}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to the fix for Windows that was made in 10b1864, this bit here also would need a similar condition - otherwise testing fails with the same error, see e.g. https://github.com/mstorsjo/llvm-mingw/actions/runs/8592846078/job/23549755414. I see that this whole PR was reverted later, but when preparing for a reland, make sure to conditionalize this case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Unfortunately I don't have a way of testing this on Windows, and I was hoping the pre-commit CI would have caught it but I guess that does not include mingw. |
||
|
||
# Ask the compiler for the path to libraries it is going to use. If this | ||
# doesn't match config.compiler_rt_libdir then it means we might be testing the | ||
# compiler's own runtime libraries rather than the ones we just built. | ||
# Warn about about this and handle appropriately. | ||
# Warn about this and handle appropriately. | ||
compiler_libdir = find_compiler_libdir() | ||
if compiler_libdir: | ||
compiler_rt_libdir_real = os.path.realpath(config.compiler_rt_libdir) | ||
|
@@ -182,7 +218,7 @@ def push_dynamic_library_lookup_path(config, new_path): | |
f'compiler-rt libdir: "{compiler_rt_libdir_real}"' | ||
) | ||
if config.test_standalone_build_libs: | ||
# Use just built runtime libraries, i.e. the the libraries this built just built. | ||
# Use just built runtime libraries, i.e. the libraries this build just built. | ||
if not config.test_suite_supports_overriding_runtime_lib_path: | ||
# Test suite doesn't support this configuration. | ||
# TODO(dliew): This should be an error but it seems several bots are | ||
|
Uh oh!
There was an error while loading. Please reload this page.