Makefile / library path modifications to make M1 building work (koreader/koreader#8797)#1570
Conversation
| "/usr/local/opt/lib/libSDL2.dylib", | ||
| "/opt/homebrew/lib/libSDL2.dylib", |
There was a problem hiding this comment.
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.
| 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.
It looks like this should be added, not replaced.
| 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.
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.
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.
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.
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.
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.
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.
I think you still meant to base these ones on brew --prefix or some such as well? :-)
There was a problem hiding this comment.
Ok, just pushed a commit with variables instead of hardcoded brew path ;)
Frenzie
left a comment
There was a problem hiding this comment.
Thanks! Looks very promising.
NiLuJe
left a comment
There was a problem hiding this comment.
(goddamnit GH review UI sucks)
| ifneq (,$(filter $(UNAME), Darwin)) | ||
| export DARWINHOST=1 | ||
| ifneq (,$(filter $(UNAME_ARCH), arm64)) | ||
| export DARWINM1HOST=1 |
There was a problem hiding this comment.
nit: arm64, m2 chips already exist ;p
There was a problem hiding this comment.
True, not without a reason being called Apple Sillicon ;> Will fix
NiLuJe
left a comment
There was a problem hiding this comment.
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? ;). |
| end | ||
| end | ||
|
|
||
| return libprefix; |
There was a problem hiding this comment.
Indeed, better add some more:
| return libprefix; | |
| return libprefix;;;;;;;;;; |
NiLuJe
left a comment
There was a problem hiding this comment.
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. |
|
|
||
| local util = {} | ||
|
|
||
| util.KO_DYLD_PREFIX = getlibprefix() |
There was a problem hiding this comment.
This shouldn't be called except on OS X, so probably on line 654 below.
There was a problem hiding this comment.
Yeah, thanks for the unbreaking commit elsewhere, I didn't consider this might throw an exception ;)
There was a problem hiding this comment.
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/optand/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/optprefix (as opposed to/usr/local/withoutoptfor Intel brew).This change is