Closed nathanvy closed 1 year ago
I'd love it if you could experiment, as I don't have access to an arm64 machine. I suspect that it's possible to conditionalise somehow, and it would be a useful pattern to have in other cases where we distribute binary shared libraries, like BLAS.
My *features*
has :x86-64 in it; I suspect that there's a similar symbol in an arm64 implementation that could be used to detect the right architecture/library to load.
You know, it occurred to me we might be overthinking this. There's no reason the libraries can't have different names, e.g. libmd-macos-x86-64.dylib
and libmd-macos-arm64.dylib
and then have the code conditionalised on the architecture in *features*
. Untested stab at a solution (init.lisp):
(:darwin (:or "libmd"
#+x86-64 #.(merge-pathnames "scipy-cephes/libmd-macos-x86-64.dylib" *compile-file-pathname*)
#+arm-64 #.(merge-pathnames "scipy-cephes/libmd-macos-arm-64.dylib" *compile-file-pathname*)))
For completeness' sake, here is my *features*
on an M2 Macbook pro, sbcl being installed from homebrew:
* *features*
(:QUICKLISP :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-MACOSX :OS-UNIX
:NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :ARM64 :GENCGC :64-BIT :ANSI-CL :BSD
:COMMON-LISP :DARWIN :IEEE-FLOATING-POINT :LITTLE-ENDIAN :MACH-O
:PACKAGE-LOCAL-NICKNAMES :SB-CORE-COMPRESSION :SB-LDB :SB-PACKAGE-LOCKS
:SB-THREAD :SB-UNICODE :SBCL :UNIX)
So you could branch on the contents of *features*
but the reader macro seems simpler to me. The only caveat is that if libmd.dylib
is not present then the makefile builds it, so editing init.lisp
in such a way also requires edits to the .asd file as well as the makefile.
Fortunately, when building the library from source it compiles correctly on my arm64 machine.
So maybe the simplest solution is to not include a prebuilt .dylib
at all?
The reason we include the shared library is that most mac users don't have a compiler tool chain installed, and we want it to be 'ready to run' for as many as possible.
If the user does have a compiler and wants to rebuild the shared library, then I hope they have enough knowledge to edit the init.lisp and rename the file. Unless your suggestion is to also modify the makefile to detect the architecture and write out a dylib with the correct name? Actually, thinking about it, that's probably the 'correct' answer here.
Unless your suggestion is to also modify the makefile to detect the architecture and write out a dylib with the correct name?
This is what I was getting at, yes. I can send you a pull request shortly.
I'm unable to properly load
lisp-stat
on Apple Silicon because this particular package fails to load, because the packaged version oflibmd
is compiled for x86_64.A quick demonstration
Remove the
cephes
directory from quicklisp:And then:
Furthermore:
Note here in particular the mismatch between the dylib arch and that reported by
uname
.Workaround
If I manually replace the included dylib with an arm64 build from homebrew, everything builds correctly.
Discussion
I'm not sure how you want to approach this because you can't very well include two files with identical names. I'm not particularly familiar with ASDF and whether or not it allows us to include a file conditional on the target OS, but I'm able to conduct some tests on my end if you don't have access to an arm64 machine.