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
Makefile / library path modifications to make M1 building work (koreader/koreader#8797) #1570
Conversation
ffi/SDL2_0.lua
Outdated
"/usr/local/opt/lib/libSDL2.dylib", | ||
"/opt/homebrew/lib/libSDL2.dylib", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go lower since SDL2 is the default. See http://luajit.org/ext_ffi_api.html#ffi_load.
On POSIX systems, if the name contains no dot, the extension .so is appended. Also, the lib prefix is prepended if necessary. So ffi.load("z") looks for "libz.so" in the default shared library search path.
On Windows systems, if the name contains no dot, the extension .dll is appended. So ffi.load("ws2_32") looks for "ws2_32.dll" in the default DLL search path.
ffi/util.lua
Outdated
@@ -619,7 +619,7 @@ function util.haveSDL2() | |||
if haveSDL2 == nil then | |||
local candidates | |||
if jit.os == "OSX" then | |||
candidates = {"libs/libSDL2.dylib", "SDL2"} | |||
candidates = {"/opt/homebrew/lib/libSDL2.dylib", "SDL2"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this should be added, not replaced.
thirdparty/glib/CMakeLists.txt
Outdated
set(CFLAGS "-I/usr/local/opt/gettext/include -I/opt/homebrew/include ${CFLAGS}") | ||
set(LDFLAGS "${LDFLAGS} -L/usr/local/opt/gettext/lib -L/opt/homebrew/lib -L${LIBICONV_DIR}/lib -L${ZLIB_DIR}/lib -L${LIBFFI_DIR}/.libs -L${BINARY_DIR}/gmodule/.libs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this hardcoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean /opt/homebrew/lib
should get a variable and become ${HOMEBREW_PREFIX}/lib?
Also is it a good idea to check for brew binary in Makefile.defs
in case of Darwin host and set the HOMEBREW_PREFIX
from $(shell brew --prefix)
? And could this be passed to the lua files somehow? This way custom prefixes set during brew installation could be covered, though probably people who bother to set them know how to fix their builds later on ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely that, but I'd also prefer to be able to plug in e.g. Nix or gentoo-prefix with little effort if reasonably possible. HOMEBREW_PREFIX
might allow for that but then the name (at least further down at this point) should really just be something like MAC_LIBRARY_PREFIX
. But you could always write MAC_LIBRARY_PREFIX := HOMEBREW_PREFIX
up above in defs or something so it's self-documenting without comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, there's a runtime homebrew command that will actually spit out the right prefix for the current system ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, there's brew --prefix
. I'll try to unhardcode the paths around evening CET.
What about the paths in lua part, can / should they somehow be based on brew --prefix
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But SIP probably means that if you exec
from an SIP/hardened app, you're essentially fucked? Yay, Apple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, yeah, seems like a giant "fuck you, FOSS", from Apple. c.f., Homebrew/brew#13481 for more context (notably the hilarious bit about the consequences of stuff like env
being hardened, it's fantastic).
TL;DR: Hardcoded search paths it is. >_<"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you still meant to base these ones on brew --prefix or some such as well? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just pushed a commit with variables instead of hardcoded brew path ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks very promising.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(goddamnit GH review UI sucks)
Makefile.defs
Outdated
@@ -189,8 +190,14 @@ endif | |||
|
|||
ifneq (,$(filter $(UNAME), Darwin)) | |||
export DARWINHOST=1 | |||
ifneq (,$(filter $(UNAME_ARCH), arm64)) | |||
export DARWINM1HOST=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: arm64, m2 chips already exist ;p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, not without a reason being called Apple Sillicon ;> Will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 5 files at r1, 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @Frenzie and @ptrm)
Makefile.defs
line 11 at r3 (raw file):
UNAME:=$(shell uname -s) UNAME_ARCH:=$(shell uname -m)
nit: I'd rename that to HOST_ARCH
(and I'm mildly intrigued by the fact that we don't already have that stored somewhere?).
EDIT: Oh, yeah, we have it, but we use it for the actual march flag, meh :/. Nevermind that one, then.
Makefile.defs
line 194 at r3 (raw file):
export DARWINHOST=1 ifneq (,$(filter $(UNAME_ARCH), arm64)) export DARWINM1HOST=1
nit: DARWIN_AARCH64_HOST
(extra columns are free!)
Makefile.defs
line 199 at r3 (raw file):
export DARWIN=1 ifdef DARWINM1HOST export DARWIN_M1=1
nit: DARWIN_AARCH64
Makefile.defs
line 511 at r3 (raw file):
ifdef DARWINM1HOST HOST_ARCH:=-mcpu=apple-m1
And a comment that M1 is the lowest common denominator for Apple AARCH64 silicon for future archeologists ;).
ffi/SDL2_0.lua
line 28 at r3 (raw file):
"libSDL2-2.0.so", "libSDL2-2.0.so.0", util.KO_DYLD_PREFIX .. "/lib/libSDL2.dylib",
Mildly mystified why this one doesn't have the libs/libSDL2.dylib
variant found in util
?
ffi/util.lua
line 63 at r3 (raw file):
]] local getlibprefix = function()
Missing a jit.os == "OSX"
branch, so we don't try to run brew everywhere.
ffi/util.lua
line 64 at r3 (raw file):
local getlibprefix = function() -- Apple M1 homebrew installs libraries outside of default searchpaths,
nit: AArch64 ;)
thirdparty/glib/CMakeLists.txt
line 73 at r1 (raw file):
Previously, Frenzie (Frans de Jonge) wrote…
I think you still meant to base these ones on brew --prefix or some such as well? :-)
These are still hard-coded ;).
My GH "review" comments may be outdated, I had once again forgotten to hit the big green button. The Reviewable stuff is current ;). |
And I just noticed that I mixed aarch64 w/ arm64 in my renaming requests; aarch64 is technically more correct, but arm64 might be easier on the eyes? ;). |
ffi/util.lua
Outdated
end | ||
end | ||
|
||
return libprefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: trailing semicolon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, better add some more:
return libprefix; | |
return libprefix;;;;;;;;;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides that very small nit ;).
Removed the semicolon, I'm blind to them at EOL ;) Also added a comment proposed in Reviewable about apple-m1 being lowest common denominator for Apple silicon chips. |
require("ffi/posix_h") | ||
|
||
local util = {} | ||
|
||
util.KO_DYLD_PREFIX = getlibprefix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be called except on OS X, so probably on line 654 below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks for the unbreaking commit elsewhere, I didn't consider this might throw an exception ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing the CI caught it. ;-)
Regression from koreader#1570.
These are mostly changes mentioned in issue koreader/koreader#8797 implemented. So far koreader builds and shows the emulator.
I used both
/usr/local/opt
and/opt/homebrew/
Homebrew prefixes, as the Apple Silicon Homebrew path has been only recently established to/opt/homebrew
(https://apple.stackexchange.com/a/410829), though some users may have older brew installation with/usr/local/opt
prefix (as opposed to/usr/local/
withoutopt
for Intel brew).This change is