Tree Sitter on M1 Mac?

Is there anything special you need to do to get treesitter working with an M1 Mac?

I’m currently trying to test out tree-sitter-elixir and I’m getting the error “Error during compilation”.

I made sure to update neovim to latest nightly build and update the nvim-treesitter plugin.

Oh, I just read another thread and learned about :TSInstallSync. My error is now

Hmm, works fine for me on M1 using latest master nvim and tree-sitter version 0.19.4, with this nvim-treesitter config:

local parser_configs = require('nvim-treesitter.parsers').get_parser_configs()
-- ...
parser_configs.elixir = {
  install_info = {
    url = 'path/to/tree-sitter-elixir',
    files = { 'src/parser.c', 'src/scanner.cc' }
  },
  filetype = 'ex'
}

What configuration are you using for nvim-treesitter, if it’s different?

Also, how’d you install tree-sitter and neovim? I’m using a native homebrew install under /opt/homebrew; if you’re using Rosetta for tree-sitter and/or neovim, maybe that’s breaking things?

At the very least, based on the error, it seems like you’re trying to compile/use the parser for arm64 with cc, but it’s expecting to run under x86. My (admittedly not that educated) guess is that maybe you’re using tree-sitter under Rosetta, but I’m really not sure.

It looks like you’re running Neovim in Rosetta. To check, you can look at the output of

file /path/to/nvim

It should say something like

/path/to/nvim: Mach-O 64-bit executable arm64

rather than

/path/to/nvim: Mach-O 64-bit executable x86_64

Ahh, this makes sense. I download Neovim from the GitHub releases page and didn’t remember to check if they were providing an arm64 build yet. Looks like there is an issue to capture that Provide a release asset for the Apple Silicon (M1) platform · Issue #13880 · neovim/neovim · GitHub.

I’m guessing i’ll need to compile from source to get an arm64 build for now.

My config looks like

require("nvim-treesitter.configs").setup {
  highlight = {enable = true},
  indent = {enable = true}
}

local parser_config = require("nvim-treesitter.parsers").get_parser_configs()

parser_config.elixir = {
  install_info = {
    url = "https://github.com/wingyplus/tree-sitter-elixir",
    files = {"src/parser.c"},
    branch = "main"
  }
}

Yes, the most commonly available pre-built binaries for the nightly version are Intel-only.

Building from source is pretty easy. If you use brew, it’ll take under a minute. You can also build straight from the repo, which takes slightly longer (but not by much) as you’ll also need to build the dependencies.

I recently added ref support to the neovim asdf plugin, so just do asdf install neovim ref:master :grinning_face_with_smiling_eyes:.

1 Like