yqrashawn / GokuRakuJoudo

config karabiner with ease
GNU General Public License v3.0
1.17k stars 120 forks source link

arm native homebrew install for M1 macs #172

Closed davidscotson closed 2 years ago

davidscotson commented 2 years ago

I just transferred my existing setup to a new M1 powered Mac.

Both goku and it's dependency joker installed via homebrew gave me errors like this:

$ goku exec: Failed to execute process '/opt/homebrew/bin/goku', unknown error number 86 $ gokuw sh: /opt/homebrew/bin/goku: Bad CPU type in executable

I'm assuming that they work fine for those with Rosetta2 installed, which would translate the amd64 binaries transparently, but I've not opted to install that yet as I don't want to accidentally run things non-natively if it's not necessary.

I'm not really familiar with Go or Clojure, but managed to install and build arm native versions of GraalVM, Joker and Goku (as well as run the Standalone Jar via the JDK) and it seems possible to create 'fat' binaries with the lipo by combining two archeticture specific binaries.

Currently Github Actions don't seem to provide M1 mac as an option, which may be blocker for automatically generating such a build, but thought it might be worth mentioning that it works. The GraalVM support for M1 seems fairly recent.

Also, when I ran make test-binary locally to check if the new binary worked I was a little surprised to see it overwrite my local configuration:

    cp ./resources/configurations/edn/yqrashawn.edn ~/.config/karabiner.edn
    cp ./resources/configurations/json/empty-karabiner.json ~/.config/karabiner/karabiner.json

But I had it in git so no harm done.

MuhammedZakir commented 2 years ago

Currently Github Actions don't seem to provide M1 mac as an option, which may be blocker for automatically generating such a build, [...]

You can build an ARM binary for M1 using Intel mac.

E.g.

davidscotson commented 2 years ago

The step I had trouble with was the bit where GraalVM turns a .jar into a native build. The makefile does this:

native-image --report-unsupported-elements-at-runtime --no-server --initialize-at-build-time -jar target/karabiner-configurator-0.1.0-standalone.jar

If you ask it to generate a different CPU target, it complains about it not being the current platform, then tells you to pass a command line flag to skip this check.

Error: Darwin native toolchain (arm64) implies native-image target architecture class jdk.vm.ci.aarch64.AArch64 but configured native-image target architecture is class jdk.vm.ci.amd64.AMD64. Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain

which then says:

Error: Building images for org.graalvm.nativeimage.Platform$MACOS_AMD64 requires static JDK libraries. Use most recent JDK from https://github.com/graalvm/labs-openjdk-*/releases Missing libraries: java, nio, net, zip (search path: /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.1.0/Contents/Home/lib)

It feels like it's probably supposed to be able to cross-compile, but I'm not familiar enough with GraalVM to know if it actually works at the moment, or what it requires installed to do so. But it does seem to work on the native platform with relative ease.

yqrashawn commented 2 years ago

Hi @davidscotson, I just upgraded graalvm version in the new release. You should able to compile on your mac now.

There's also a goku-arm.zip file in the release page which I compiled manually on a M1 mac.

piersolenski commented 2 years ago

I've started getting the following error, not sure if it's related?


/opt/homebrew/Library/Taps/yqrashawn/homebrew-goku/Formula/goku.rb:19: syntax error, unexpected end-of-input, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END```
yqrashawn commented 2 years ago

I've started getting the following error, not sure if it's related?

/opt/homebrew/Library/Taps/yqrashawn/homebrew-goku/Formula/goku.rb:19: syntax error, unexpected end-of-input, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END```

oops, seems my formatter is broken. It's fixed now.

piersolenski commented 2 years ago

Great, works for me!