-
Notifications
You must be signed in to change notification settings - Fork 19
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
Selectable library loaders, including link-time #30
Conversation
Makes it easier to replace, centralises the platform-dependent logic, and means we can more easily re-use things like the templated LoadSymbol.
Which does not call dlsym or equivalents, but links directly against the library and dispatches on name. This can be useful on platforms without (working) dlsym-implementations, without affecting the structure of lua-https too much.
Apparently on macOS we weren't building using c++11, causing a compile error because of a nullptr. Considering the ubiquitous support for c++11 these days, just enable it.
Alright, so I have set up my CMakeLists.txt to pull in your branch via FetchContent @bartbes (and set up LÖVE Potion as needed), but I am running into the following error (which might be where I need to patch things on my end):
I've set add_library(lua-https STATIC
${lua-https_SOURCE_DIR}/src/common/config.h
${lua-https_SOURCE_DIR}/src/common/LibraryLoader.h
${lua-https_SOURCE_DIR}/src/common/Connection.h
${lua-https_SOURCE_DIR}/src/common/ConnectionClient.h
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.h
${lua-https_SOURCE_DIR}/src/common/HTTPS.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPS.h
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.h
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.cpp
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.h
${lua-https_SOURCE_DIR}/src/generic/LinktimeLibraryLoader.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.h
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.cpp
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.h
${lua-https_SOURCE_DIR}/src/lua/main.cpp
)
set(LIBRARY_LOADER "linktime")
set(USE_CURL_BACKEND ON) |
I see you’ve set LIBRARY_LOADER, but that is a cmake-only variable. Is the define HTTPS_LIBRARY_LOADER_LINKTIME set? Otherwise LinktimeLibraryLoader.cpp will be ifdeffed out. |
Ah, gotcha.. didn't see that part of it. It built the 3DS binary, will check if this works shortly. |
Alright, it kind of works. I got the following error, which I vaguely remember how I solved it last time, but I'm not 100% sure. If memory serves it failed the connection test. I might be misremembering, though?
The version of cURL we have uses certificates that are placed on the SD Card, but I doubt it's expired by now, but I can also check that. |
Digging further, it's not even enabling cURL as a backend: HTTPSClient::Reply request(const HTTPSClient::Request& req)
{
std::printf("request\n");
for (size_t i = 0; clients[i]; ++i)
{
HTTPSClient& client = *clients[i];
std::printf("client.valid()? %d\n", client.valid());
if (client.valid())
return client.request(req);
}
throw std::runtime_error("No applicable HTTPS implementation found");
} This doesn't even print inside the for loop. I'm sure I missed something stupid, going to check the source a bit closer to see what it might be. |
Okay, got it to work with the following: set(LIBRARY_LOADER "linktime")
add_library(lua-https STATIC
${lua-https_SOURCE_DIR}/src/common/config.h
${lua-https_SOURCE_DIR}/src/common/LibraryLoader.h
${lua-https_SOURCE_DIR}/src/common/Connection.h
${lua-https_SOURCE_DIR}/src/common/ConnectionClient.h
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.h
${lua-https_SOURCE_DIR}/src/common/HTTPS.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPS.h
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.h
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.cpp
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.h
${lua-https_SOURCE_DIR}/src/generic/LinktimeLibraryLoader.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.h
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.cpp
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.h
${lua-https_SOURCE_DIR}/src/lua/main.cpp
)
target_compile_definitions(lua-https PRIVATE
HTTPS_LIBRARY_LOADER_LINKTIME
HTTPS_BACKEND_CURL
)
# link curl
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl)
target_link_libraries(lua-https PRIVATE PkgConfig::lua51 PkgConfig::libcurl) It's likely because of the way I'm doing this that lua-https isn't happy with certain things. If there's a better way for me to do this, let me know. |
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.
In overall, I think it looks good to me.
Resolves #16, as per my proposal there. Alternative to #22.
I wanted to do the first commit for OpenSSL 3 support anyway, and it provided an alternative solution for #16. It does feel slightly more invasive than I'd like.
@TurtleP can you check whether this works for you?