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.
This commit is contained in:
Adam 2022-09-18 18:27:50 -04:00 committed by GitHub
parent 4134b30ffd
commit 5ada80b9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

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

View File

@ -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");