rpav / cl-autowrap

(c-include "file.h") => complete FFI wrapper
BSD 2-Clause "Simplified" License
210 stars 41 forks source link

Support for Modern OS X and "apple silicon" hardware #135

Open ryanobjc opened 1 month ago

ryanobjc commented 1 month ago

Hi all,

I've been doing some work on cl-autowrap, and c2ffi. I have a MacBookPro18,4 that identifies itself as an "Apple M1 Max" chip in the system information. In terms of c2ffi, I got it building using homebrew llvm 18.1.5.

As I understand it, c2ffi get it's triples from llvm. And on this machine, LLVM/clang says I have:

/Library/Developer/CommandLineTools/usr/bin/clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

And using the homebrew variant:

/opt/homebrew/Cellar/llvm/18.1.5/bin/clang --version
Homebrew clang version 18.1.5
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/18.1.5/bin

Furthermore the 'arch' CLI says we are on "arm64".

I'm using SBCL 2.4.1 and inside the cl-autowrap code it identifies the feature #+arm64 as "aarch64", and #+darwin as "darwin9". Seems like these don't line up with modern OSX.

I'm thinking we should be extending the supported versions to cover "arm64-apple-darwin23.4.0" (or possibly just darwin?) and jury rig (local-arch) to return the appropriate string when on the appropriate machine.

Furthermore, the alloc.lisp needs a branch for #+arm64 to define 'size-t (as uint64 as per the c2ffi output) otherwise the c-malloc, etc, functions aren't defined.

I'm not 100% sure how wise just straight up changing #+arm64 from aarch64 -> arm64 is, given other platforms, but local architecture definitively is now called arm64!