-
Notifications
You must be signed in to change notification settings - Fork 423
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
Fix issues with using a non-default system LLVM with CHPL_LLVM_CONFIG #26428
Open
jabraham17
wants to merge
3
commits into
chapel-lang:main
Choose a base branch
from
jabraham17:fix-non-default-system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1024,6 +1024,42 @@ def get_clang_prgenv_args(): | |
|
||
return (comp_args, link_args) | ||
|
||
@memoize | ||
def get_system_include_directories(flag, lang): | ||
""" | ||
Runs 'COMPILER -E -Wp,-v -' to determine the system include directories | ||
""" | ||
directories = [] | ||
compiler = chpl_compiler.get_compiler_command(flag, lang) | ||
_, _, stdout, _ = try_run_command( | ||
compiler + ["-E", "-Wp,-v", "-", "-o", "/dev/null"], | ||
combine_output=True, cmd_input="" | ||
) | ||
if stdout: | ||
lines = stdout.splitlines() | ||
start_includes_regex = re.compile(r"#include.+search starts here") | ||
end_includes_regex = re.compile(r"End of search list") | ||
ignoring_regex = re.compile(r"(?:ignoring nonexistent)|(?:as it is a non-system)") | ||
collecting = False | ||
for line in lines: | ||
if start_includes_regex.search(line): | ||
collecting = True | ||
elif end_includes_regex.search(line): | ||
collecting = False | ||
break | ||
elif collecting and not ignoring_regex.search(line): | ||
directories.append(line.strip()) | ||
return directories | ||
|
||
@memoize | ||
def is_path_system_include_directory(path, flag, lang): | ||
""" | ||
Returns True if the given path is a system include directory | ||
""" | ||
directories = get_system_include_directories(flag, lang) | ||
p = os.path.realpath(os.path.abspath(path)) | ||
return any([os.path.realpath(os.path.abspath(d)) == p for d in directories]) | ||
|
||
# Filters out C++ compilation flags from llvm-config. | ||
# The flags are passed as a list of strings. | ||
# Returns a list of strings containing the kept flags. | ||
|
@@ -1048,18 +1084,25 @@ def filter_llvm_config_flags(llvm_val, flags): | |
continue # filter out these flags | ||
|
||
# | ||
# include LLVM headers as system headers | ||
# include LLVM headers as system headers using -isystem | ||
# this avoids warnings inside of LLVM headers by treating LLVM headers | ||
# | ||
# when adding LLVM=system as system headers, we should not perturb the | ||
# include search path, so use -isystem-after/-idirafter | ||
# If the header is already a system header, using -isystem will break | ||
# the include search. In that case, just use -I (which technically wont do anythings) | ||
# | ||
# when adding LLVM=bundled, we should include the LLVM headers as system | ||
# headers and prefer the bundled headers, so use -isystem | ||
# | ||
include_flag = '-idirafter' if llvm_val == 'system' else '-isystem' | ||
if flag.startswith('-I'): | ||
ret.append(include_flag + flag[2:]) | ||
directory = flag[2:] | ||
if llvm_val == "system": | ||
if not is_path_system_include_directory(directory, 'host', 'c++'): | ||
# its not included by the compiler, so its safe to use -isystem | ||
ret.append('-isystem' + directory) | ||
else: | ||
# technically don't need to add this for | ||
# but it's harmless to use -I | ||
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. comment wording got weird |
||
ret.append("-I" + directory) | ||
else: | ||
# bundled LLVM is always safe to use -isystem | ||
ret.append("-isystem" + directory) | ||
continue | ||
|
||
if flag.startswith('-W'): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this code will only work for
gcc
andclang
. I'd recommend limiting it to those compilers. We can add other compilers as needed.