-
Notifications
You must be signed in to change notification settings - Fork 795
[LIBCLC] Modify libclc-remangler cmds for cross-compile support #16182
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
Conversation
Because libclc-remangler commands executed in cmake use `libclc::libclc-remangler`, builds where `CMAKE_CROSSCOMPILING=ON` do not work correctly since cmake assumes the target is not executable on the host machine. This change modifies the custom commands to use the cache variable `LIBCLC_REMANGLER_PATH` instead, where this variable is set in a similar way as llvm tools such as `llvm-config` by calling `compile_native_tool`. Signed-off-by: Jack Myers <jackhyers97@gmail.com>
frasercrmck
left a comment
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.
CC @hvdijk who fixed cross-compilation issues upstream
| if(CMAKE_CROSSCOMPILING) | ||
| if(LLVM_NATIVE_TOOL_DIR AND NOT LIBCLC_REMANGLER_PATH) | ||
| if(EXISTS "${LLVM_NATIVE_TOOL_DIR}/libclc-remangler${LLVM_HOST_EXECUTABLE_SUFFIX}") | ||
| set(LLVM_CONFIG_PATH "${LLVM_NATIVE_TOOL_DIR}/libclc-remangler${LLVM_HOST_EXECUTABLE_SUFFIX}") |
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.
Should this be setting LIBCLC_REMANGLER_PATH?
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.
Yes it should've but I have decided to not do all the cross compiling logic manually, instead using setup_host_tool.
libclc/cmake/modules/AddLibclc.cmake
Outdated
| add_custom_command( OUTPUT "${builtins_remangle_path}" | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR} | ||
| COMMAND libclc::libclc-remangler | ||
| COMMAND ${LIBCLC_REMANGLER_PATH} |
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.
Perhaps the variable should be named libclc-remangler_exe like the other tools: clang_exe, llvm-link_exe?
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.
Same thing as my previous comment above, but yes:
Yes it should've but I have decided to not do all the cross compiling logic manually, instead using
setup_host_tool.
| add_dependencies(libclc-remangler NativeLibCLCRemangler) | ||
| endif() | ||
| else() | ||
| set(LIBCLC_REMANGLER_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin/libclc-remangler" CACHE STRING "") |
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 not sure relying on the path like this is the best idea. Perhaps we can get the path to the binary using the libclc-remangler target itself? Does $<TARGET_PROPERTY:libclc-remangler,TARGET_FILE> work?
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.
Referencing again 😅:
Same thing as my previous comment above, but yes:
Yes it should've but I have decided to not do all the cross compiling logic manually, instead using
setup_host_tool.
|
|
||
| # If we've not already imported a libclc-remangler tool from an external build, | ||
| # set it up now. | ||
| if(NOT TARGET libclc::libclc-remangler) |
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.
This comment makes me realise this PR breaks the ability to import libclc-remangler from another build, using LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR. We should keep that.
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.
Yeah, this is actually a bit confusing to me. I found PR #13743 that introduced this, but as far as I can tell, this breaks the LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR functionality since the target is never imported through anything like find_package.
I'm realizing now that this might be because I was testing everything with CMAKE_CROSSCOMPILING enabled which may have messed with the target import.
Regardless, the libclc::libclc-remangler pattern seems to be unique among the rest of LLVM where other tools used during the build that are also built as a part of LLVM use things like compile_native_tool or setup_host_tool + LLVM_NATIVE_TOOL_DIR which is assigned automatically if needed.
My latest commit uses libclc-remangler_target which is populated by setup_host_tool. But I think LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR might still be broken.
I see why LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR is used since it can be built as a standalone. I'm wondering if in the case that it has not been set, then it should be set to LLVM_NATIVE_TOOL_DIR if it has been set. Thoughts?
Because libclc-remangler commands executed in cmake use `libclc::libclc-remangler`, builds where `CMAKE_CROSSCOMPILING=ON` do not work correctly since cmake assumes the target is not executable on the host machine. This change modifies the custom commands to use the cache variable `LIBCLC_REMANGLER_PATH` instead, where this variable is set in a similar way as llvm tools such as `llvm-config` by calling `compile_native_tool`. Signed-off-by: Jack Myers <jackhyers97@gmail.com>
Because libclc-remangler commands executed in cmake use `libclc::libclc-remangler`, builds where `CMAKE_CROSSCOMPILING=ON` do not work correctly since cmake assumes the target is not executable on the host machine. This change modifies the custom commands to use the cache variable `LIBCLC_REMANGLER_PATH` instead, where this variable is set in a similar way as llvm tools such as `llvm-config` by calling `compile_native_tool`. Signed-off-by: Jack Myers <jackhyers97@gmail.com>
|
Hi @jackm97. I've been comparing this with #16244 which is fixing the same issues (and more besides). I notice that the |
|
@frasercrmck, yes I do run into issues with cross-compiling that this PR alone does not fix, but not llvm-spirv I don't think. It might help to add that my scenario is a pseudo-cross-compiling workflow using conda build from x86 to x86. This mostly just to isolate what's causing things to fail without adding the complexity of a true cross build. Some issues I've found:
I've worked around the issue with flags needed for cross compiling by putting clang config files in the build/NATIVE/bin directory (e.g. -clang.cfg) with the flags required, after configuring with CMake. This was a quick and brute force fix that eliminated the need to alter the LLVM project itself, but I’m not sure if this makes a good permanent solution. That said, it’s worked really well so far. IIRC, it's important to specify the triple implicitly via config file naming scheme, rather than by passing it via the target flag by cmd line (which I tried by modifying cmake files) or within the config files themselves. This makes sense, some clang calls use the target flag which overrides the target set in the config file. It seems clang still respects the triple encoded in the cfg filename wrt sysroot layout while still allowing for different targets to specified on the cmdline. Ultimately it boils down to two issues: not all CMake files are adhering to LLVM patterns for native tools used during the build and flags necessary for cross compiling like sysroot and gcc install location not getting passed to the custom targets calling clang. |
I'll take a look at the PR in the morning, but it's a fairly simple change, so I don't think I'll have a preference other than that I was looking forward to my first contribution to LLVM 😅 In all seriousness, if it is pretty much the same PR, it's not a big deal. Whatever makes the most sense :) |
|
Thanks @jackm97. We will be building in slightly different ways, please do let me know if you should find that my PR doesn't cover your use. |
|
Closing now that #16244 is merged |
Because libclc-remangler commands executed in cmake use
libclc::libclc-remangler, builds whereCMAKE_CROSSCOMPILING=ONdo not work correctly since cmake assumes the target is not executable on the host machine.This change modifies the custom commands to use the cache variable
LIBCLC_REMANGLER_PATHinstead, where this variable is set in a similar way as llvm tools such asllvm-configby callingcompile_native_tool.