-
Notifications
You must be signed in to change notification settings - Fork 120
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
Executable folder utilities #77
Conversation
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.
That looks like a good improvement.
) | ||
target_sources(whereami | ||
INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/_deps/whereami-external-src/src/whereami.c" | ||
) |
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.
Configure your editor to add EOL?
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.
Done.
INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/_deps/whereami-external-src/src" | ||
) | ||
target_sources(whereami | ||
INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/_deps/whereami-external-src/src/whereami.c" |
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.
Do you need this because you want to cope with old CMake?
Or just because whereami does not use modern CMake features.
You can clarify my brain by adding comments in the CMake configuration. :-)
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.
Doing this because whereami is lacking CMake support completely.
shader_stream }, | ||
std::istreambuf_iterator<GLchar>{} }; | ||
std::string shader_string = | ||
cl::util::read_exe_relative_text_file(file_path.c_str()); |
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.
Add an overload taking a std::string
. Actually a string_view
would be even better when it is available.
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 would like to make that a separate discussion, because some of the overloads would need to be version guarded.
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 agree it would be cleaner if the C++ version had a const std::string&
overload, which shouldn't need any version guards. This could be done in a subsequent PR, though.
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.
Found one typo, otherwise LGTM.
shader_stream }, | ||
std::istreambuf_iterator<GLchar>{} }; | ||
std::string shader_string = | ||
cl::util::read_exe_relative_text_file(file_path.c_str()); |
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 agree it would be cleaner if the C++ version had a const std::string&
overload, which shouldn't need any version guards. This could be done in a subsequent PR, though.
@keryell can you please check if your comments have been addressed? We'd like to merge this shortly - thanks! |
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.
Thanks.
Not sure what's caused the issue with the Windows builds but they do appear to be "real":
|
@bashbaug @keryell I added a few fixes to the tip of the branch, partly to fix what Ben pointed out and addressed some warnings. The I changed the API of GCC also argued about unhandled switch cases, and adding a |
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.
LGTM, and all CI is passing now 👍
I'll just merge this. Thanks!
Motivation
One of the annoying aspects of OpenCL/GL, Vulkan, etc. is the fact that locating assets in general on disk is a pain. Of course large projects solve this using some utility, but toy projects that are still enjoying their dependency-free world are stuck with what the CRT/STL provides if they wish to be portable (a bit like SDK samples).
fopen
andifstream
both interpret the paths relative to the current working directory (CWD), which is unfortunate, because execution success now depends on launching our code from a specific location our code assumes. This assumption definitely blows up in unsuspecting users' faces. C++ luckily has a passable solution:std::filesystem::canonical(argv[0])
which by some magical alignment happens to works on all compilers (CE recently broke execution for MSVC compilers, so those without a working Win env just have to trust me on that it works). Note that even this isn't ideal, because one has to relay theargv
symbol all the way to where this translation occurs. In sample code, that's okay, but more complex programs wantargv
out of thin air. (D2567 targets just this, so maybe in C26 🤞🏻) A mildly elegant solution would be #embed in C23, but mandating a C23 compiler in 2023 is reckless at best. Unfortunately C18 and under doesn't have a similar feature in the CRT, therefore our C samples are subject to CWD relativeness. Seeing this blow up in my students' (and co-lecturers') faces makes me sad. 😞Proposed solution
This problem needs a solution. I cooked up a utility for
OpenCLUtils.lib
. It follows the idiom ofclGetXyzInfo()
functions, first allocate, then return value. It's not dependent onargv
so one may invoke it in the depths of any library init. It wraps whereami, a project with the most permissive dual-license to date: MIT/WTFPLv2. The use of this lib is an implementation detail, it does not leak to consumers of the utility library.The samples in my opinion became much nicer and now they don't fail, regardless of where they're launched from.
Changes introduced
OPENCL_SDK_BUILD_UTILITY_LIBRARIES
CMake optionopencl.hpp
in all regards and make a utility library that is a natural extension to that.