-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CMake] Use Clang to infer the target triple #89425
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 3 commits
eb24598
2c89c50
302fa32
5044cde
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 |
---|---|---|
|
@@ -368,14 +368,22 @@ macro(construct_compiler_rt_default_triple) | |
"Default triple for which compiler-rt runtimes will be built.") | ||
endif() | ||
|
||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") | ||
if(CMAKE_C_COMPILER_ID MATCHES "Clang") | ||
set(option_prefix "") | ||
if (CMAKE_C_SIMULATE_ID MATCHES "MSVC") | ||
set(option_prefix "/clang:") | ||
endif() | ||
execute_process(COMMAND ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple | ||
OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
set(print_target_triple ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple) | ||
execute_process(COMMAND ${print_target_triple} | ||
RESULT_VARIABLE result | ||
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if(result EQUAL 0) | ||
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${output}) | ||
else() | ||
string(REPLACE ";" " " print_target_triple "${print_target_triple}") | ||
message(WARNING "Failed to execute `${print_target_triple}` to normalize target triple.") | ||
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 think that it should be a fetal error instead of just a warning? 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. Currently we ignore any errors so my preference would be to start with a warning and change it to an error in a follow up change after we verify there are no issues. 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. Maybe you are right. I tested with some quite bad --target values, it will output the original values. |
||
endif() | ||
endif() | ||
|
||
string(REPLACE "-" ";" LLVM_TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,24 @@ message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}") | |
|
||
set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}") | ||
|
||
if(CMAKE_C_COMPILER_ID MATCHES "Clang") | ||
set(option_prefix "") | ||
if (CMAKE_C_SIMULATE_ID MATCHES "MSVC") | ||
set(option_prefix "/clang:") | ||
endif() | ||
set(print_target_triple ${CMAKE_C_COMPILER} ${option_prefix}--target=${LLVM_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple) | ||
execute_process(COMMAND ${print_target_triple} | ||
RESULT_VARIABLE result | ||
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
if(result EQUAL 0) | ||
set(LLVM_DEFAULT_TARGET_TRIPLE ${output}) | ||
else() | ||
string(REPLACE ";" " " print_target_triple "${print_target_triple}") | ||
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. Ditto. I guess that we need to test on more target. As some target doesn't use the new filesystem struct. 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. Ditto. 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. Since most of the CIs monitor the commit only. I have no idea how to trigger them before commit. |
||
message(WARNING "Failed to execute `${print_target_triple}` to normalize target triple.") | ||
endif() | ||
endif() | ||
|
||
option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON) | ||
option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON) | ||
option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF) | ||
|
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.
It seems offtopic of commit msg?
Since the normalize format of
aarch64-linux-gnu
is just aarch64-unknown-linux-gnu, why do we need to modify them?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 included this as a regression test, without this change the build of our toolchain would break, but I'm fine omitting this if you prefer.