Skip to content

Commit

Permalink
possibly mac native binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Sep 15, 2024
1 parent b148c39 commit f9a6333
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion loader/src/loader/ModImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ Result<> Mod::Impl::setup() {
CCFileUtils::get()->addSearchPath(searchPathRoot.string().c_str());
});

const auto binariesDir = searchPathRoot / m_metadata.getID() / "binaries" / PlatformID::toShortString(GEODE_PLATFORM_TARGET);
// binaries on macos are merged, so make the platform binaries merged as well
auto const binaryPlatformId = PlatformID::toShortString(GEODE_PLATFORM_TARGET GEODE_MACOS(, true));

auto const binariesDir = searchPathRoot / m_metadata.getID() / "binaries" / binaryPlatformId;
if (std::filesystem::exists(binariesDir))
LoaderImpl::get()->addNativeBinariesPath(binariesDir);

Expand Down
27 changes: 26 additions & 1 deletion loader/src/platform/mac/LoaderImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <loader/ModImpl.hpp>
#include <sys/stat.h>
#include <loader/LogImpl.hpp>
#include <dlfcn.h>

using namespace geode::prelude;

Expand Down Expand Up @@ -132,7 +133,31 @@ CFDataRef msgPortCallback(CFMessagePortRef port, SInt32 messageID, CFDataRef dat
}

void Loader::Impl::addNativeBinariesPath(std::filesystem::path const& path) {
log::warn("LoaderImpl::addNativeBinariesPath not implement on this platform, not adding path {}", path.string());
// this takes advantage of dyld using already loaded binaries when loading relative shared libraries
// however, this also means that the binaries are loaded, which could have some weird side effects
// but if you could use dlopen (and thus control when libraries are loaded), then you wouldn't be using this, would you?

for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (!entry.is_regular_file()) {
continue;
}

auto& entry_path = entry.path();

if (entry_path.extension() != ".dylib") {
continue;
}

auto handle = dlopen(entry_path.string().c_str(), RTLD_LAZY);

if (!handle) {
auto err = dlerror();
log::warn("failed to load native binary at {}: dlerror returned ({})", entry_path.string(), err);
continue;
}

dlclose(handle);
}
}

std::string Loader::Impl::getGameVersion() {
Expand Down

0 comments on commit f9a6333

Please sign in to comment.