Skip to content
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

Merged
merged 5 commits into from
Apr 20, 2024

Conversation

bartbes
Copy link
Member

@bartbes bartbes commented Apr 7, 2024

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?

bartbes added 5 commits April 7, 2024 11:53
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.
@TurtleP
Copy link
Contributor

TurtleP commented Apr 7, 2024

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):

G:/GitHub/C++/lovepotion/build/_deps/lua-https-src/src/common/HTTPS.cpp:70:
(.text._Z41__static_initialization_and_destruction_0v+0x4): 
undefined reference to `LibraryLoader::GetCurrentProcessHandle()'

I've set LIBRARY_LOADER to linktime and USE_CURL_BACKEND to ON. I don't think I missed any files I need, either:

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)

@bartbes
Copy link
Member Author

bartbes commented Apr 7, 2024

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.

@TurtleP
Copy link
Contributor

TurtleP commented Apr 7, 2024

Ah, gotcha.. didn't see that part of it. It built the 3DS binary, will check if this works shortly.

@TurtleP
Copy link
Contributor

TurtleP commented Apr 7, 2024

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?

[LOVE] Error: [string "main.lua"]:5: No applicable HTTPS implementation found
stack traceback:
        [string "boot.lua"]:423: in function <[string "boot.lua"]:419>
        [C]: in function 'assert'
        [string "main.lua"]:5: in main chunk
        [C]: in function 'require'
        [string "boot.lua"]:391: in function <[string "boot.lua"]:143>
        [C]: in function 'xpcall'
        [string "boot.lua"]:433: in function <[string "boot.lua"]:426>
        [C]: in function 'xpcall'       1`

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.

@TurtleP
Copy link
Contributor

TurtleP commented Apr 7, 2024

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.

@TurtleP
Copy link
Contributor

TurtleP commented Apr 7, 2024

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.

Copy link
Contributor

@MikuAuahDark MikuAuahDark left a 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.

@bartbes bartbes mentioned this pull request Apr 13, 2024
@MikuAuahDark MikuAuahDark merged commit c40585b into love2d:main Apr 20, 2024
6 checks passed
@bartbes bartbes deleted the selectable_library_loaders branch April 21, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request] cURL compile-time option
3 participants