Skip to content
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

Unable to build on M1 Mac #8797

Closed
JasonInOttawa opened this issue Feb 10, 2022 · 70 comments
Closed

Unable to build on M1 Mac #8797

JasonInOttawa opened this issue Feb 10, 2022 · 70 comments
Labels
help-wanted We'd like help with this issue
Milestone

Comments

@JasonInOttawa
Copy link
Contributor

I'm trying to build on an M1 Mac but am getting the following error. I was hoping someone could point me at a possible fix.

------------------------------
** Build for Mac OS X 10.11 **
------------------------------
ld: warning: ignoring file /Users/jason/koreader/base/thirdparty/openssl/build/arm64-apple-darwin21.3.0/openssl-prefix/src/openssl/libssl.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/jason/koreader/base/thirdparty/openssl/build/arm64-apple-darwin21.3.0/openssl-prefix/src/openssl/libcrypto.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
[100%] Completed 'luasec'
[100%] Built target luasec
install_name_tool -change \
		`otool -L "build/arm64-apple-darwin21.3.0/common/ssl.so" | grep "libcrypto.1.1.dylib " | awk '{print $1}'` \
		libs/libcrypto.1.1.dylib \
		build/arm64-apple-darwin21.3.0/common/ssl.so
Usage: /Library/Developer/CommandLineTools/usr/bin/install_name_tool [-change old new] ... [-rpath old new] ... [-add_rpath new] ... [-delete_rpath old] ... [-id name] input
make[1]: *** [build/arm64-apple-darwin21.3.0/common/ssl] Error 1
make: *** [base/build/arm64-apple-darwin21.3.0/luajit] Error 2
@pazos
Copy link
Member

pazos commented Feb 10, 2022

@JasonInOttawa: #8767 (comment)

My suggestion would be:

  1. Try to build the emulator first
  2. Fix the errors found while building the emulator

Once you get the emulator running the rest of changes (mostly brew deps and the tiny c launcher) should be way easier to attempt.

@pazos pazos added the help-wanted We'd like help with this issue label Feb 10, 2022
@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Feb 10, 2022

Thank you. I'll try getting the emulator built.

Right now, the error I am seeing is as follows:

CMake Error at /opt/homebrew/Cellar/cmake/3.22.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/Library/Developer/CommandLineTools/usr/bin/gcc"

  is not able to compile a simple test program.

  It fails with the following output:

...

    clang: error: the clang compiler does not support '-march=native'

EDIT: It appears that M1 supports "-mcpu=apple-m1" rather than "-march=native"

@pazos
Copy link
Member

pazos commented Feb 10, 2022

I'm fairly sure you'll find a lot of issues building the emulator.

The cheapest way of workaround issues is by hacking the code locally, even if that destroys compatibility with the rest of targets. Then with all required changes documented it's a matter of spending time tweaking makefiles.

The specific issue you mention is caused by https://github.com/koreader/koreader-base/blob/master/Makefile.defs#L457. You can try to use https://github.com/koreader/koreader-base/blob/master/Makefile.defs#L468 instead (or the one in your edit :p)

@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Feb 10, 2022

I hope you don't mind a quick question: I'm getting the following error message

ld: warning: ignoring file /Users/jason/koreader/base/thirdparty/openssl/build/arm64-apple-darwin21.3.0-debug/openssl-prefix/src/openssl/libssl.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

I think that implies that an x86_64 library for openssl is being downloaded rather than built, because if it were built it would be arm64 instead.

Does that sound right?

@NiLuJe
Copy link
Member

NiLuJe commented Feb 10, 2022

OpenSSL's build system is a nightmare, it's entirely plausible it's happily been building an x64 binary behind your back...

@pazos
Copy link
Member

pazos commented Feb 10, 2022

OpenSSL's build system is a nightmare, it's entirely plausible it's happily been building an x64 binary behind your back...

Yup.

Does that sound right?

It is expected if your CHOST doesn't match https://github.com/koreader/koreader-base/blob/master/thirdparty/openssl/CMakeLists.txt#L48-L54

According to https://github.com/stuartcarnie/openssl/blob/0a76703445ff6f8aafdb9ace1bc8fd484fc6e85f/Configurations/10-main.conf you'll need to add a new branch with set(CFG_OPTS "darwin64-arm64-cc ${CFG_OPTS}") matching your CHOST.

There're probably other 3rd party deps relying on CHOST. What's yours?

@mdbraber
Copy link

Running into the same problem. My CHOST is empty (didn't check why). But my guess is the x86_64 target is hardcoded at https://github.com/koreader/koreader-base/blob/64bdeda85efe127357c9b969a8cc72b46521ad87/Makefile.third#L575. You can remove that and openssl will compile

@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Feb 17, 2022 via email

@mdbraber
Copy link

Also: the path for Lua include files is hardcoded for compilation on Darwin, which seems wrong with the new /opt locations of brew: https://github.com/koreader/koreader-base/blob/64bdeda85efe127357c9b969a8cc72b46521ad87/Makefile.defs#L878

@mdbraber
Copy link

And another one: also the include paths for glib are not pointing to opt https://github.com/koreader/koreader-base/blob/64bdeda85efe127357c9b969a8cc72b46521ad87/thirdparty/glib/CMakeLists.txt#L72

@mdbraber
Copy link

The last one I needed to fix was libSDL being in the wrong place. The easiest / quick way to fix this is to link libSDL* from /opt/homebrew/lib to /usr/local/lib

@JasonInOttawa
Copy link
Contributor Author

@mdbraber Thank you very much! Did you happen to run into this error while trying to build libzmq:

In file included from /Users/jason/koreader/base/thirdparty/libzmq/build/arm64-apple-darwin21.3.0-debug/libzmq-prefix/src/libzmq/src/curve_server.cpp:31:
/Users/jason/koreader/base/thirdparty/libzmq/build/arm64-apple-darwin21.3.0-debug/libzmq-prefix/src/libzmq/src/curve_server.hpp:30:10: fatal error: 'sodium.h' file not found
#include "sodium.h"

@mdbraber
Copy link

No haven't seen that. Seems to be some header files for libsodium?

@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Feb 17, 2022

I don't have sodium.h in either ~/koreader or /opt/homebrew. I installed the dependencies mentioned in the build guide. Do you happen to know where sodium.h comes from? Thanks!

@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Feb 17, 2022

Some progress -- I ran

brew install libsodium

and made this revision to line 21 of base/thirdparty/libzmq/CMakeLists.txt

set(CFG_ENV_VAR "CC=\"${CC}\" CXX=\"${CXX}\" CFLAGS=\"${CFLAGS}\" CXXFLAGS=\"${CXXFLAGS} -I/opt/homebrew/include -Wno-unused-result\" LDFLAGS=\"${LDFLAGS}\" LIBS=\"${STATIC_LIBSTDCPP}\"")

and the emulator builds! It also doesn't crash when I open an epub, per issue #8686

I'm not able to build the mac application with koreader release macos though - still working on that

@arooni
Copy link

arooni commented Mar 31, 2022

Following as I vastly prefer koreader to Apple books. I've got Koreader running on 4 devices and really would love to see it running on my macbook too

@Frenzie
Copy link
Member

Frenzie commented Mar 31, 2022

Shouldn't the Intel build work on M1?

@arooni
Copy link

arooni commented Mar 31, 2022

@Frenzie I recall trying to run one of the intel builds on my mac and it errored out somehow. It was a different ticket.

@JasonInOttawa

This comment was marked as off-topic.

@JasonInOttawa
Copy link
Contributor Author

I was hoping someone could help out with this error, from trying to "kodev build", from base/thirdparty/leptonica"

libversions.c:70:10: fatal error: 'webp/encode.h' file not found
#include "webp/encode.h"
         ^~~~~~~~~~~~~~~
1 error generated.

@NiLuJe
Copy link
Member

NiLuJe commented May 25, 2022

Try again after installing webp from brew ;)

@JasonInOttawa
Copy link
Contributor Author

@NiLuJe

I did (and do) have webp installed

Warning: webp 1.2.2 is already installed and up-to-date.

I can confirm that encode.h etc are in this folder

/opt/homebrew/include/webp

but I'm not sure how to get it into the build environment. I'm guessing a need to put a magic symlink in someplace but I'm not sure where.

@NiLuJe
Copy link
Member

NiLuJe commented May 25, 2022

I'm not entirely convinced it's actually coming from leptonica itself.

Can't really say without a full verbose build log.

(And/or try to just disable webp in leptonica by passing --without-libwebp --without-libwebpmux to leptonica's configure, as we don't care about lpeotnica supporting webp anyway).

@JasonInOttawa
Copy link
Contributor Author

@pazos @NiLuJe

I built emulator version 2022-05.1-8 with the following notes. Most of the errors are related to homebrew putting things in /opt/homebrew rather than /usr/local it seems, with a couple of issues related to arm64 v x86_64

It also doesn't crash when I open an epub, per issue #8686

Running ./kodev build

FIRST ERROR

koreader/base/thirdparty/luajit
clang: error: the clang compiler does not support ‘-march=native'

Revise base/Makefile.defs

457c457
< HOST_ARCH:=-march=native
---
> HOST_ARCH:=-mcpu=apple-m1

Do a “./kodev clean”

SECOND ERROR

libversions.c:70:10: fatal error: 'webp/encode.h' file not found
#include "webp/encode.h"
         ^~~~~~~~~~~~~~~
1 error generated.

Revise base/thirdparty/libk2pdfopt/CMakeLists.txt

26c26
<     set(CFLAGS "${CFLAGS} -Wno-error=implicit-function-declaration")
---
>     set(CFLAGS "${CFLAGS} -Wno-error=implicit-function-declaration -I/opt/homebrew/include")

THIRD ERROR

install_name_tool -change \
		`otool -L "build/arm64-apple-darwin21.3.0/common/ssl.so" | grep "libcrypto.1.1.dylib " | awk '{print $1}'` \
		libs/libcrypto.1.1.dylib \
		build/arm64-apple-darwin21.3.0/common/ssl.so
Usage: /Library/Developer/CommandLineTools/usr/bin/install_name_tool [-change old new] ... [-rpath old new] ... [-add_rpath new] ... [-delete_rpath old] ... [-id name] input

Revise line 575 from base/Makefile.third

575c575
< 		-DCONFIG_SCRIPT="$(if $(EMULATE_READER),$(if $(DARWIN),Configure darwin64-x86_64-cc,config),Configure $(if $(WIN32),mingw,))" \
---
>                 -DCONFIG_SCRIPT="$(if $(EMULATE_READER),$(if $(DARWIN),Configure darwin64-arm64-cc,config),Configure $(if $(WIN32),mingw,))" \

FOURTH ERROR

[ 75%] Performing build step for 'lua-htmlparser'

Error: Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.

Revise base/Makefile.defs

878,879c878,879
< LUA_INCDIR=$(if $(DARWINHOST),/usr/local/include/lua5.1,"$(LUAJIT_DIR)/src")
< LUA_LIBDIR=$(if $(DARWINHOST),/usr/local/lib,"$(CURDIR)/$(dir $(LUAJIT_LIB))")
---
> LUA_INCDIR=$(if $(DARWINHOST),/opt/homebrew/include/lua5.1,"$(LUAJIT_DIR)/src")
> LUA_LIBDIR=$(if $(DARWINHOST),/opt/homebrew/lib,"$(CURDIR)/$(dir $(LUAJIT_LIB))")

FIFTH ERROR

[ 12%] Performing build step for 'libzmq'
…
fatal error: 'sodium.h' file not found
#include “sodium.h”

Revise base/thirdparty/libzmq/CMakeLists.txt

21c21
< set(CFG_ENV_VAR "CC=\"${CC}\" CXX=\"${CXX}\" CFLAGS=\"${CFLAGS}\" CXXFLAGS=\"${CXXFLAGS} -I/opt/homebrew/include -Wno-unused-result\" LDFLAGS=\"${LDFLAGS}\" LIBS=\"${STATIC_LIBSTDCPP}\"")
---
> set(CFG_ENV_VAR "CC=\"${CC}\" CXX=\"${CXX}\" CFLAGS=\"${CFLAGS}\" CXXFLAGS=\"${CXXFLAGS} -Wno-unused-result\" LDFLAGS=\"${LDFLAGS}\" LIBS=\"${STATIC_LIBSTDCPP}\"")

SIXTH ERROR

[ 62%] Performing configure step for 'glib'
…
configure: error: 
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html)

Revise base/thirdparty/glib/CMakeLists.txt

72,73c72,73
<     set(CFLAGS "-I/usr/local/opt/gettext/include ${CFLAGS}")
<     set(LDFLAGS "${LDFLAGS} -L/usr/local/opt/gettext/lib -L${LIBICONV_DIR}/lib -L${ZLIB_DIR}/lib -L${LIBFFI_DIR}/.libs -L${BINARY_DIR}/gmodule/.libs")
---
>     set(CFLAGS "-I/opt/homebrew/opt/gettext/include ${CFLAGS}")
>     set(LDFLAGS "${LDFLAGS} -L/opt/homebrew/opt/gettext/lib -L${LIBICONV_DIR}/lib -L${ZLIB_DIR}/lib -L${LIBFFI_DIR}/.libs -L${BINARY_DIR}/gmodule/.libs”)

SEVENTH ERROR

Undefined symbols for architecture arm64:
  "_ffi_call", referenced from:
      _ffi_raw_call in raw_api.o
      _ffi_java_raw_call in java_raw_api.o
  "_ffi_closure_trampoline_table_page", referenced from:
      _ffi_trampoline_table_alloc in closures.o
  "_ffi_prep_cif_machdep", referenced from:
      _ffi_prep_cif_core in prep_cif.o
  "_ffi_prep_cif_machdep_var", referenced from:
      _ffi_prep_cif_core in prep_cif.o
  "_ffi_prep_closure_loc", referenced from:
      _ffi_prep_closure in prep_cif.o
      _ffi_prep_raw_closure_loc in raw_api.o
      _ffi_prep_java_raw_closure_loc in java_raw_api.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Run ./kodev build again and this error doesn’t happen

@JasonInOttawa
Copy link
Contributor Author

For the second error, I will look into @NiLuJe 's suggestions re

-without-libwebp --without-libwebpmux

@JasonInOttawa

This comment was marked as off-topic.

@JasonInOttawa

This comment was marked as off-topic.

@JasonInOttawa
Copy link
Contributor Author

JasonInOttawa commented Oct 11, 2022

I tried building and running after the SDL2 and base bumps and am getting the same error. The stack trace suggested by NiLuJe looks like this

ffi.load: libs/liblodepng.dylib
stack traceback:
	frontend/logger.lua:75: in function 'info'
	frontend/device/generic/device.lua:194: in function 'init'
	frontend/device/sdl/device.lua:311: in function 'init'
	frontend/device.lua:62: in main chunk
	[C]: in function 'require'
	reader.lua:166: in main chunk
failed to run lua chunk: frontend/logger.lua:76: table overflow

@NiLuJe
Copy link
Member

NiLuJe commented Oct 11, 2022

What about the print?

@JasonInOttawa
Copy link
Contributor Author

It didn't actually cause a stack overflow. I added these lines to logger.lua near line 75

print("BEFORE print")
print(...)
print("AFTER print")
print(debug.traceback())
        for _, v in ipairs({...}) do <====== LINE 79
            if type(v) == "table" then
                table.insert(line, serpent.block(v, serpent_opts))
            else
                table.insert(line, tostring(v))
            end
        end

and it prints

BEFORE print
initializing for device	Mac OS X
AFTER print
stack traceback:
	frontend/logger.lua:78: in function 'info'
	frontend/device/generic/device.lua:194: in function 'init'
	frontend/device/sdl/device.lua:311: in function 'init'
	frontend/device.lua:62: in main chunk
	[C]: in function 'require'
	reader.lua:166: in main chunk
failed to run lua chunk: frontend/logger.lua:79: table overflow

@NiLuJe
Copy link
Member

NiLuJe commented Oct 11, 2022

Weeeeell, that's interesting :D.

@JasonInOttawa
Copy link
Contributor Author

Sure is. It looks like the logger is crashing when trying to print a simple string, but only in the application bundle.

@pazos
Copy link
Member

pazos commented Oct 11, 2022

@JasonInOttawa: lets refocus on the emulator for a moment.

Could you check that all the libraries (both in /common, /libs and some under rocks/.../...) were built for arm?.

Both file and otool should be able to tell you that.

@JasonInOttawa
Copy link
Contributor Author

@pazos They seem to be built for arm64. I also checked the application bundle and they are as well.

jason@nnn libs % pwd
/Users/jason/koreader/koreader-emulator-arm64-apple-darwin21.6.0-debug/koreader/libs
jason@nnn libs % file ` find . -name '*so' -o -name '*dylib' `
./libkoreader-nnsvg.so:                                                    Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-xtext.so:                                                    Mach-O 64-bit dynamically linked shared library arm64
./libk2pdfopt.2.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./liblodepng.dylib.dSYM/Contents/Resources/DWARF/liblodepng.dylib:         Mach-O 64-bit dSYM companion file arm64
./libunibreak.5.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./libcrengine.dylib:                                                       Mach-O 64-bit dynamically linked shared library arm64
./libblitbuffer.so:                                                        Mach-O 64-bit dynamically linked shared library arm64
./liblept.5.dylib:                                                         Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-lfs.so.dSYM/Contents/Resources/DWARF/libkoreader-lfs.so:     Mach-O 64-bit dSYM companion file arm64
./libpng16.16.dylib:                                                       Mach-O 64-bit dynamically linked shared library arm64
./libczmq.1.dylib:                                                         Mach-O 64-bit dynamically linked shared library arm64
./libwrap-mupdf.so.dSYM/Contents/Resources/DWARF/libwrap-mupdf.so:         Mach-O 64-bit dSYM companion file arm64
./libssl.1.1.dylib:                                                        Mach-O 64-bit dynamically linked shared library arm64
./libdjvulibre.21.dylib:                                                   Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-cre.so:                                                      Mach-O 64-bit dynamically linked shared library arm64
./libglib-2.0.dylib:                                                       Mach-O 64-bit dynamically linked shared library arm64
./libfreetype.6.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./libturbojpeg.dylib:                                                      Mach-O 64-bit dynamically linked shared library arm64
./libharfbuzz.0.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./libgif.7.dylib:                                                          Mach-O 64-bit dynamically linked shared library arm64
./libzmq.4.dylib:                                                          Mach-O 64-bit dynamically linked shared library arm64
./libtesseract.3.dylib:                                                    Mach-O 64-bit dynamically linked shared library arm64
./libwebp.7.dylib:                                                         Mach-O 64-bit dynamically linked shared library arm64
./libwrap-mupdf.so:                                                        Mach-O 64-bit dynamically linked shared library arm64
./libfribidi.0.dylib:                                                      Mach-O 64-bit dynamically linked shared library arm64
./liblunasvg.dylib:                                                        Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-cre.so.dSYM/Contents/Resources/DWARF/libkoreader-cre.so:     Mach-O 64-bit dSYM companion file arm64
./libutf8proc.2.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./libluajit.so:                                                            Mach-O 64-bit dynamically linked shared library arm64
./libwebpdemux.2.dylib:                                                    Mach-O 64-bit dynamically linked shared library arm64
./libzstd.1.dylib:                                                         Mach-O 64-bit dynamically linked shared library arm64
./libjpeg.8.dylib:                                                         Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-xtext.so.dSYM/Contents/Resources/DWARF/libkoreader-xtext.so: Mach-O 64-bit dSYM companion file arm64
./liblodepng.dylib:                                                        Mach-O 64-bit dynamically linked shared library arm64
./libsqlite3.dylib:                                                        Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-lfs.so:                                                      Mach-O 64-bit dynamically linked shared library arm64
./libmupdf.dylib:                                                          Mach-O 64-bit dynamically linked shared library arm64
./libcrypto.1.1.dylib:                                                     Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-nnsvg.so.dSYM/Contents/Resources/DWARF/libkoreader-nnsvg.so: Mach-O 64-bit dSYM companion file arm64
./libz.1.dylib:                                                            Mach-O 64-bit dynamically linked shared library arm64
./libkoreader-djvu.so.dSYM/Contents/Resources/DWARF/libkoreader-djvu.so:   Mach-O 64-bit dSYM companion file arm64
./libblitbuffer.so.dSYM/Contents/Resources/DWARF/libblitbuffer.so:         Mach-O 64-bit dSYM companion file arm64
./libkoreader-djvu.so:                                                     Mach-O 64-bit dynamically linked shared library arm64
jason@nnn libs % cd ../common
jason@nnn common % !file
file ` find . -name '*so' -o -name '*dylib' `
./ssl.so:             Mach-O 64-bit bundle arm64
./libtffi_wrap.dylib: Mach-O 64-bit dynamically linked shared library arm64
./mime/mcore.so:      Mach-O 64-bit bundle arm64
./socket/score.so:    Mach-O 64-bit bundle arm64
jason@nnn common % cd ../rocks
jason@nnn rocks % !file
file ` find . -name '*so' -o -name '*dylib' `
./lib/lua/5.1/rapidjson.so: Mach-O 64-bit bundle arm64
./lib/lua/5.1/lpeg.so:      Mach-O 64-bit bundle arm64

@JasonInOttawa
Copy link
Contributor Author

Further notes

  1. The emulator requires copies of the SDL library to be copied from /opt/homebrew/lib to /usr/local/lib. I noticed that this morning when I uninstalled brew from /usr/local.
  2. The emulator fails to run with the same error as the application if you copy the application's SDL libraries to /opt/homebrew, so the issue appears to be in them and not anything to do with the application structure

@JasonInOttawa
Copy link
Contributor Author

I just did a debug M1 build after applying a couple of the fixes from above and the resulting application seems to work. Still poking.

@dgarrett
Copy link
Contributor

Further notes

  1. The emulator requires copies of the SDL library to be copied from /opt/homebrew/lib to /usr/local/lib. I noticed that this morning when I uninstalled brew from /usr/local.
  2. The emulator fails to run with the same error as the application if you copy the application's SDL libraries to /opt/homebrew, so the issue appears to be in them and not anything to do with the application structure

I thought setting DYLD_LIBRARY_PATH=/opt/homebrew/lib would fix this, but it didn't. However, I was able to change a couple of files in koreader-base to use full paths instead of copying libSDL around. I'm not sure what the real fix is though.

diff --git a/ffi/SDL2_0.lua b/ffi/SDL2_0.lua
index bf69bfbb..4883553c 100644
--- a/ffi/SDL2_0.lua
+++ b/ffi/SDL2_0.lua
@@ -21,6 +21,7 @@ require("ffi/linux_input_h")
 -----------------------------------------------------------------
 
 local SDL = util.ffiLoadCandidates{
+    "/opt/homebrew/lib/libSDL2.dylib",
     "SDL2",
     -- this unfortunately needs to be written in full due to the . in the name
     "libSDL2-2.0.so",
diff --git a/ffi/util.lua b/ffi/util.lua
index fa6476ea..99a699ae 100644
--- a/ffi/util.lua
+++ b/ffi/util.lua
@@ -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"}
         else
             candidates = {"SDL2", "libSDL2-2.0.so", "libSDL2-2.0.so.0"}
         end

@JasonInOttawa
Copy link
Contributor Author

I noticed a recent base bump that I believe fixes M1 building. When I try to build, I get the following error. If things should work now, I'd appreciate a pointer toward fixing this error.

[ 75%] Performing build step for 'czmq'
Making all in src
  CC       zactor.lo
  CC       zauth.lo
  CC       zcert.lo
  CC       czmq_selftest.o
  CC       zbeacon.lo
  CC       zchunk.lo
  CC       zclock.lo
  CC       zcertstore.lo
  CC       zconfig.lo
  CC       zdigest.lo
/Users/jason/koreader/base/thirdparty/czmq/build/arm64-apple-darwin22.4.0/czmq-prefix/src/czmq/src/zbeacon.c:556:52: error: no member named 'ifr_netmask' in 'struct ifreq'
        memcpy (&self->netmask, ((inaddr_t *) &ifr.ifr_netmask), sizeof (inaddr_t));
                                               ~~~ ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_string.h:63:33: note: expanded from macro 'memcpy'
                __builtin___memcpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest))
                                              ^~~~~~~~~~~
1 error generated.
make[7]: *** [zbeacon.lo] Error 1
make[7]: *** Waiting for unfinished jobs....
make[6]: *** [all] Error 2
make[5]: *** [all-recursive] Error 1
make[4]: *** [czmq-prefix/src/czmq-stamp/czmq-build] Error 2
make[3]: *** [CMakeFiles/czmq.dir/all] Error 2
make[2]: *** [all] Error 2
make[1]: *** [build/arm64-apple-darwin22.4.0/libs/libczmq.1.dylib] Error 2
make: *** [base/build/arm64-apple-darwin22.4.0/luajit] Error 2

@Frenzie
Copy link
Member

Frenzie commented Apr 6, 2023

@ptrm said the same thing on Gitter here.

after upgrading to Mac Os Catalina Ventura 13.3 from 13.2, I started getting this compiler error. Google says ancient Darwins also didn't have ifr_netmask

I guess that means fixed on 13.2 and older, newly broken on 13.3.

@JasonInOttawa
Copy link
Contributor Author

Oh dang. I am running 13.3.

@Frenzie
Copy link
Member

Frenzie commented Apr 6, 2023

I hear they've been breaking things to fix other things, in 13.3 SMB being the fixed thing.

To get it to build you can probably just change this line to PATCH_COMMAND ./autogen.sh COMMAND ${PATCH_CMD2}, which will be completely fine if you don't use czmq-based functionality (and possibly also even if you do).

@ptrm
Copy link
Contributor

ptrm commented Apr 6, 2023

Yeah, Apple keeps us entertained ;) This was either recent XCode Tools upgrade or OS X upgrade from 13.2 to .3. I installed them together, so it's hard to say.

@Frenzie
Copy link
Member

Frenzie commented Apr 7, 2023 via email

@ptrm
Copy link
Contributor

ptrm commented Apr 8, 2023

PATCH_COMMAND ./autogen.sh COMMAND ${PATCH_CMD2}

This does the job. Haven't tried any mq-related feature yet, but at least the emulator builds and launches ;)

@ptrm
Copy link
Contributor

ptrm commented Apr 8, 2023

Also, running an amd64 distro via docker is always an option on Apple Silicon ;) Docker supports Rosetta emulation in experimental features:
image
image

(and then dpkg --add-architecture arm64 and use arm binaries as well)

@ryanwwest
Copy link
Contributor

I was able to build on my M1 Mac (not sure if it built to M1 or Intel, I didn't change any defaults from the build instructions) but it seems the touch interface might be messed up on 2023.04 and later version. E.g., I use the mouse cursor to tap somewhere and it seems to register a click as if my mouse was a few hundred pixels higher up.

The reason I wonder if it's a recent bug is because mouse clicking works as expected using the prebuilt artiface from within 2023-03 here: https://github.com/koreader/koreader/actions/runs/4584196480. But then this prebuilt artifact produced earlier today has the same cursor issue above: https://github.com/koreader/koreader/actions/runs/4843953756. (I'm also curious if these prebuilt artifacts I'm linking to are built for M1 architecture or Intel and my computer is just doing Rosetta translation).

(Another issue: resizing the window on any of these builds seems to eventually lead to KOReader crashing. It works for awhile but when I try to open the file browser, it crashes. I haven't tested this enough yet, so it might not be specifically related to opening the file browser).

@Frenzie Frenzie added this to the 2023.04 milestone Apr 30, 2023
@Frenzie Frenzie closed this as completed Apr 30, 2023
@Frenzie
Copy link
Member

Frenzie commented Apr 30, 2023

@ryanwwest I didn't notice anything off on the M1 Air but try with this reverted: koreader/koreader-base@8724254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted We'd like help with this issue
Projects
None yet
Development

No branches or pull requests

9 participants