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

cannot load vim mode after install on m1 #74

Closed
yangsui9999 opened this issue Feb 21, 2021 · 14 comments
Closed

cannot load vim mode after install on m1 #74

yangsui9999 opened this issue Feb 21, 2021 · 14 comments

Comments

@yangsui9999
Copy link

Hi I am a vim fans, thanks for your awesome spoon , referred to the quick installer script and installed VimMode successfully, but failed to load the configuration file.

My system info

MacBook Pro (13-inch, M1, 2020) APPLE M1
macOS Big Sur 11.2.1

lua and luajit info

➜  bin git:(stable) which lua
/opt/homebrew/bin/lua

➜  bin git:(stable) which luajit
/opt/homebrew/bin/luajit

➜  bin git:(stable) ll | grep lua
lrwxr-xr-x  1 yangsui  wheel    27B  2 14 10:53 lua -> ../Cellar/lua/5.4.2/bin/lua
lrwxr-xr-x  1 yangsui  wheel    31B  2 14 10:53 lua-5.4 -> ../Cellar/lua/5.4.2/bin/lua-5.4
lrwxr-xr-x  1 yangsui  wheel    30B  2 14 10:53 lua5.4 -> ../Cellar/lua/5.4.2/bin/lua5.4
lrwxr-xr-x  1 yangsui  wheel    28B  2 14 10:53 luac -> ../Cellar/lua/5.4.2/bin/luac
lrwxr-xr-x  1 yangsui  wheel    32B  2 14 10:53 luac-5.4 -> ../Cellar/lua/5.4.2/bin/luac-5.4
lrwxr-xr-x  1 yangsui  wheel    31B  2 14 10:53 luac5.4 -> ../Cellar/lua/5.4.2/bin/luac5.4
lrwxr-xr-x  1 yangsui  wheel    40B  2 20 00:23 luajit -> ../Cellar/luajit/HEAD-ec6edc5/bin/luajit
lrwxr-xr-x  1 yangsui  wheel    52B  2 20 00:23 luajit-2.1.0-beta3 -> ../Cellar/luajit/HEAD-ec6edc5/bin/luajit-2.1.0-beta3
lrwxr-xr-x  1 yangsui  wheel    37B  2 20 00:25 luarocks -> ../Cellar/luarocks/3.5.0/bin/luarocks
lrwxr-xr-x  1 yangsui  wheel    43B  2 20 00:25 luarocks-admin -> ../Cellar/luarocks/3.5.0/bin/luarocks-admin

Here is the hammerspoon's console log

2021-02-21 23:47:29: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

2021-02-21 23:47:29: -- Lazy extension loading enabled
2021-02-21 23:47:29: -- Loading ~/.hammerspoon/init.lua
2021-02-21 23:47:29: 23:47:29     hotkey: Enabled hotkey ⌥L
2021-02-21 23:47:29: -- Loading extension: hotkey
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌘⌃.
2021-02-21 23:47:29: -- Loading extension: window
2021-02-21 23:47:29: -- Loading extensions: window.filter
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃H
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃L
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃K
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃J
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃Y
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃O
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃U
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃I
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃F
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃C
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃M
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧/
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧H
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧LEFT
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧RIGHT
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃⌥LEFT
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃⌥RIGHT
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧1
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧2
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥⇧3
2021-02-21 23:47:29: -- Loading extension: menubar
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃[
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥1: Pycharm
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥4: Typora
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥G: GoLand
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥C: Google Chrome
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥T: iTerm
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥F: Finder
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥V: Visual Studio Code
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥W: Wechat
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥D: TablePlus
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥Y: Activity Monitor
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌥S: SmartGit
2021-02-21 23:47:29:              hotkey: Disabled previous hotkey ⌃H
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃H
2021-02-21 23:47:29:              hotkey: Disabled previous hotkey ⌃J
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃J
2021-02-21 23:47:29:              hotkey: Disabled previous hotkey ⌃K
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃K
2021-02-21 23:47:29:              hotkey: Disabled previous hotkey ⌃L
2021-02-21 23:47:29:              hotkey: Enabled hotkey ⌃L
2021-02-21 23:47:29: -- Loading Spoon: SpeedMenu
2021-02-21 23:47:29: -- Loading extension: network
2021-02-21 23:47:29: -- Loading extension: osascript
2021-02-21 23:47:30: -- Loading extension: timer
2021-02-21 23:47:30: -- Loading extension: screen
2021-02-21 23:47:30: -- Loading extension: webview
2021-02-21 23:47:30: -- Loading extension: drawing
2021-02-21 23:47:30: 23:47:30     hotkey: Enabled hotkey ⌘⌃G
2021-02-21 23:47:30: -- Loading extension: notify
2021-02-21 23:47:30: -- Loading Spoon: VimMode
2021-02-21 23:47:30: -- Loading extension: inspect
2021-02-21 23:47:30: -- Loading extension: logger
2021-02-21 23:47:30: *** ERROR: error loading module 'luautf8.lua-utf8' from file '/Users/yangsui/.hammerspoon/Spoons/VimMode.spoon/vendor/luautf8/lua-utf8.so':
	dlopen(/Users/yangsui/.hammerspoon/Spoons/VimMode.spoon/vendor/luautf8/lua-utf8.so, 6): no suitable image found.  Did find:
	/Users/yangsui/.hammerspoon/Spoons/VimMode.spoon/vendor/luautf8/lua-utf8.so: mach-o, but wrong architecture
	/Users/yangsui/.hammerspoon/Spoons/VimMode.spoon/vendor/luautf8/lua-utf8.so: mach-o, but wrong architecture
stack traceback:
	[C]: in ?
	[C]: in function 'rawrequire'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:651: in function 'require'
	...sui/.hammerspoon/Spoons/VimMode.spoon/vendor/luautf8.lua:4: in main chunk
	[C]: in function 'dofile'
	...merspoon/Spoons/VimMode.spoon/lib/utils/string_utils.lua:2: in main chunk
	[C]: in function 'dofile'
	...yangsui/.hammerspoon/Spoons/VimMode.spoon/lib/buffer.lua:2: in main chunk
	[C]: in function 'dofile'
	...rspoon/Spoons/VimMode.spoon/lib/accessibility_buffer.lua:3: in main chunk
	[C]: in function 'dofile'
	...rs/yangsui/.hammerspoon/Spoons/VimMode.spoon/lib/vim.lua:21: in main chunk
	[C]: in function 'dofile'
	/Users/yangsui/.hammerspoon/Spoons/VimMode.spoon/init.lua:10: in main chunk
	[C]: in function 'rawrequire'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:651: in function 'require'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:324: in field 'loadSpoon'
	/Users/yangsui/.hammerspoon/init.lua:13: in main chunk
	[C]: in function 'xpcall'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:702: in function 'hs._coresetup.setup'
	(...tail calls...)
2021-02-21 23:47:31: -- Loading extension: styledtext
@dbalatero
Copy link
Owner

dbalatero commented Feb 21, 2021

Makes sense, the new M1 architecture can't load the .so, as it was compiled for Intel x86.

I have a vendored version of https://github.com/starwing/luautf8 in this repo. The reason I vendored it is that it's not clear how to pull in libraries from luarocks into a Spoon, so it was easier for me to just vendor it. Now that we have 2 architectures, I either need to vendor a second version and detect M1 (I can certainly do that), or I need a better way to work with Luarocks.

I'm going to check with the Hammerspoon mailing list on the best way to proceed, then go from there.

@timothycosta
Copy link

I had the same error, but was able to run Hammerspoon under Rosetta as a workaround.
Any progress on a proper fix?

@dbalatero
Copy link
Owner

@yangsui9999 @timothycosta

I need someone with an M1 machine to compile https://github.com/starwing/luautf8 against M1 with Lua 5.4 libraries, so I can vendor an additional .so for M1 arch.

I can't buy an M1 machine to do this, so this work is blocked until I eventually upgrade my Mac.

I'd honestly rather have an easy way for my spoon to depend on a luarocks package and just have the package manager handle this, but I haven't seen a great way to do this. See this thread for a sense of how hacked together it is: Hammerspoon/hammerspoon#363

My goal for this repo is that people can just clone it and be ready to go, and I'm really loathe to add extra install steps like:

  • install luarocks
  • make a hacky symlink from luarocks into your hammerspoon directory
  • ensure you have the right luautf8 package installed

Does this make sense?

Given that can one of you volunteer to try to get me a build of the M1 .so?

As well I need the output of uname -a and uname -p from your machine so I can try to use it for arch detection:

My intel machine for example:

$ uname -a
Darwin st-dbalatero1 19.6.0 Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64 x86_64

$ uname -p
i386

@dbalatero
Copy link
Owner

If you're rich and lazy though you're also welcome to buy me an M1 mac and ship it to me, and I'll 100% do the fix :)

@dbalatero
Copy link
Owner

Also a final option, I do attempt to load it the Luarocks version if you can figure out how to get that in your Hammerspoon include path:

-- Try to load it from luarocks, otherwise require the vendored version.
local luautf8 = prequire("lua-utf8") or require("luautf8.lua-utf8")

Hammerspoon might support Luarocks out of the box actually according to Hammerspoon/hammerspoon#363 (comment)

brew install luarocks
luarocks install lua-utf8

I'm curious if this fixes things for you?

@timothycosta
Copy link

I don't know much about Hammerspoon or Lua, but I'd be happy to try to compile the library if you can give me some instructions on how to do so.

Looks like that thread on adding luarocks spans 6 years. I don't think we should hold our breath for that.

no luck via brew:

 [I] ➜ luarocks install lua-utf8 --check-lua-versions
lua-utf8 not found for Lua 5.4.
Checking if available for other Lua versions...
Checking for Lua 5.1...
Checking for Lua 5.2...
Checking for Lua 5.3...

Error: No results matching query were found for Lua 5.4.
lua-utf8 is not available for any Lua versions.

But here is the output of uname

 [I] ➜ uname -a
Darwin Tims-Pro-13.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64

 [I] ➜ uname -p
arm

@dbalatero
Copy link
Owner

@timothycosta Can you try luarocks install utf8? I might have gotten the package name wrong.

@dbalatero
Copy link
Owner

You know what, there also might be a built-in utf8 package in Lua 5.4. Let me check on this–if Hammerspoon ships with 5.4 nowadays, we might just be able to use that and drop this one entirely for anyone on the most recent version of HS.

@timothycosta
Copy link

I just checked and my version of Hammerspoon is running 5.4.

I get the following for utf8. Presumably this would have been installed by default.

 [I] ➜ luarocks install utf8

Error: Rock utf8 5.4-1 is already provided by VM or via 'rocks_provided' in the config file.

@dbalatero
Copy link
Owner

Ok yeah, 0.9.79 is the first HS release on Lua 5.4:

http://www.hammerspoon.org/releasenotes/0.9.79.html

I think the best plan of action is:

  1. Detect the HS version.
  2. If you're >= 0.9.79, load the built-in Lua 5.4 version. This should work on M1 + x86.
  3. If you're < 0.9.79, continue to load the vendored version for backwards compatibility. This will continue to only work on x86.

It strikes me that I really have no versioning on this project, and I probably should. A separate effort to cut versions of this spoon could then drop that backwards compatibility entirely for future releases.

@dbalatero
Copy link
Owner

Ugh actually the utf8 module that ships with Lua 5.4 is not full featured and different from the one I'm using. Sorry for running around in circles - does luarocks install luautf8 work for you?

@timothycosta
Copy link

Yeah, that one was successful. 👍

@dbalatero
Copy link
Owner

I have an experimental branch on #82 with M1 support.

It seems to be working on an M1 laptop that I borrowed to compile libutf8 for arm64. I'll test it on x86 and make sure nothing is broken before merging.

@dbalatero
Copy link
Owner

Closed with #82!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants