From 5ada80b9df15dff4e130f3aa7187964d46acc9c4 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 18 Sep 2022 18:27:50 -0400 Subject: [PATCH] Added in native modules suffixes. (#1111) * Added in native modules with suffixes, giving priority to those with matching architectures and platforms. * PowerPC isn't x86, and it's x86_64. * Changed things over to allow compiler to set a tuple, makes more sense from a build perspective. * Spelling mistake. * Added in arm target tuples. --- data/core/start.lua | 6 ++++-- src/main.c | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/data/core/start.lua b/data/core/start.lua index 5db22ffd..cb66b0f4 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -21,8 +21,10 @@ package.path = DATADIR .. '/?/init.lua;' .. package.path package.path = USERDIR .. '/?.lua;' .. package.path package.path = USERDIR .. '/?/init.lua;' .. package.path -local dynamic_suffix = PLATFORM == "Mac OS X" and 'lib' or (PLATFORM == "Windows" and 'dll' or 'so') -package.cpath = DATADIR .. '/?.' .. dynamic_suffix .. ";" .. USERDIR .. '/?.' .. dynamic_suffix +local suffix = PLATFORM == "Mac OS X" and 'lib' or (PLATFORM == "Windows" and 'dll' or 'so') + +package.cpath = USERDIR .. '/?.' .. ARCH .. "." .. suffix .. ";" .. DATADIR .. '/?.' .. ARCH .. "." .. suffix .. + USERDIR .. '/?.' .. suffix .. ";" .. DATADIR .. '/?.' .. suffix package.native_plugins = {} package.searchers = { package.searchers[1], package.searchers[2], function(modname) local path = package.searchpath(modname, package.cpath) diff --git a/src/main.c b/src/main.c index 1b57f93e..6c4a8466 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,28 @@ void set_macos_bundle_resources(lua_State *L); #endif #endif +#ifndef LITE_ARCH_TUPLE + #if __x86_64__ || _WIN64 || __MINGW64__ + #define ARCH_PROCESSOR "x86_64" + #elif __aarch64__ + #define ARCH_PROCESSOR "aarch64" + #elif __arm__ + #define ARCH_PROCESSOR "arm" + #else + #define ARCH_PROCESSOR "x86" + #endif + #if _WIN32 + #define ARCH_PLATFORM "windows" + #elif __linux__ + #define ARCH_PLATFORM "linux" + #elif __APPLE__ + #define ARCH_PLATFORM "darwin" + #else + #error "Please define -DLITE_ARCH_TUPLE." + #endif + #define LITE_ARCH_TUPLE ARCH_PROCESSOR "-" ARCH_PLATFORM +#endif + int main(int argc, char **argv) { #ifdef _WIN32 HINSTANCE lib = LoadLibrary("user32.dll"); @@ -151,6 +173,9 @@ init_lua: lua_pushstring(L, SDL_GetPlatform()); lua_setglobal(L, "PLATFORM"); + lua_pushstring(L, LITE_ARCH_TUPLE); + lua_setglobal(L, "ARCH"); + lua_pushnumber(L, get_scale()); lua_setglobal(L, "SCALE");