Skip to content

Commit

Permalink
Unhardcode Apple M1 brew paths for SDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrm committed Mar 22, 2023
1 parent 7b7a609 commit c8f36e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ffi/SDL2_0.lua
Expand Up @@ -25,8 +25,7 @@ local SDL = util.ffiLoadCandidates{
-- this unfortunately needs to be written in full due to the . in the name
"libSDL2-2.0.so",
"libSDL2-2.0.so.0",
"/usr/local/opt/lib/libSDL2.dylib",
"/opt/homebrew/lib/libSDL2.dylib",
util.KO_DYLD_PREFIX .. "/lib/libSDL2.dylib",
}

-- Some features (like SDL_GameControllerRumble) may require a minimum version
Expand Down
19 changes: 18 additions & 1 deletion ffi/util.lua
Expand Up @@ -60,10 +60,27 @@ int WideCharToMultiByte(
);
]]

local getlibprefix = function()
-- Apple M1 homebrew installs libraries outside of default searchpaths,
-- and dyld environment variables are sip-protected on MacOS, cf. https://github.com/Homebrew/brew/issues/13481#issuecomment-1181592842
local libprefix = os.getenv("KO_DYLD_PREFIX");

if not libprefix then
local std_out = io.popen("brew --prefix", "r")
if std_out then
libprefix = std_out:read("*line")
std_out:close()
end
end

return libprefix or "";
end

require("ffi/posix_h")

local util = {}

util.KO_DYLD_PREFIX = getlibprefix()

if ffi.os == "Windows" then
util.gettime = function()
Expand Down Expand Up @@ -619,7 +636,7 @@ function util.haveSDL2()
if haveSDL2 == nil then
local candidates
if jit.os == "OSX" then
candidates = {"libs/libSDL2.dylib", "/opt/homebrew/lib/libSDL2.dylib", "SDL2"}
candidates = {"libs/libSDL2.dylib", "SDL2", util.KO_DYLD_PREFIX .. "/lib/libSDL2.dylib"}
else
candidates = {"SDL2", "libSDL2-2.0.so", "libSDL2-2.0.so.0"}
end
Expand Down

0 comments on commit c8f36e3

Please sign in to comment.