Closed mcchrish closed 3 years ago
I was lost without this option! Especially as there is no NPM package to wrap this with an easy npm i -g stylua
for more front-end focused devs (I only really need StyLua at this point to keep my init.lua for Neovim trim ;))
For any others lost without homebrew, if you download the binary and copy it to a folder on your path (e.g. /usr/local/bin/
) and then from /usr/local/bin/ run chmod +x stylua
to make it executable. You should then be able to verify it works with which stylua
)
I'm unfamiliar with homebrew, but I'm happy to take a look.
Just had a quick look at some well known rust tools like ripgrep, and it seems it's "formula" does depend on rust behind the scenes: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ripgrep.rb. That probably works (and gives opportunity to select features). Downloading a prebuilt binary from GitHub releases is probably quicker, but it has stringent ratelimits if not authenticated, and limits the selection of features (we currently build the binary with all features enabled, so that's not too big of a deal).
Not sure when I'll have the chance to look into this, but I can see. (I know some people have published their own community maintained install scripts for other package managers like for nix or arch, so if you want to do that instead that's fine by me)
Anybody can make a PR to homebrew with a new formula; the maintainers are very helpful in getting it in shape. For a similarly "simple" Rust program, see https://github.com/Homebrew/homebrew-core/blob/master/Formula/texlab.rb.
The biggest issue is
handling different Lua versions; homebrew handles this as different versions of the Lua formula (which are separate ruby files): there is
lua
(5.4)lua@5.3
lua@5.1
(no Lua 5.2 for some reason). Easiest would be to handle this similarly for stylua
(even though it's not technically a version of stylua) so you can add the dependence on the corresponding formula. Leaves the question how to treat LuaJIT (which is a separate -- even two separate, if you count openresty/luajit2 -- formula), but that could be just stylua-luajit
.
EDIT: Actually, if I interpret this correctly, you can just build for all features and allow switching at runtime? That would then be by far the simplest solution, and I don't see any drawbacks?
prettier
should suffice: https://github.com/Homebrew/homebrew-core/blob/a9355ebf8ab89d6db102d3ca38be1eb4df5181e1/Formula/prettier.rbIf someone -- not necessarily @JohnnyMorganz -- has time and interest in pursuing this, I'd suggest opening an issue on https://github.com/Homebrew/homebrew-core asking for guidance how they'd prefer the different features to be handled.
And just for the record: the benefit of installing via homebrew is to not have to check github releases or cargo install stylua
regularly; you'll get updates automatically via brew upgrade
. Of course, that requires someone to actually upload a new release but that is fairly trivial -- unless there are breaking changes (such that you need to adapt the tests), it's as simple as brew bump-formula-pr stylua --version=0.11.0
.
@JohnnyMorganz you probably didn't see the edit (sorry!): Is there any disadvantage to just having homebrew build with --all-features
? That would simplify matters enormously.
@JohnnyMorganz you probably didn't see the edit (sorry!): Is there any disadvantage to just having homebrew build with
--all-features
? That would simplify matters enormously.
I think it's mostly alright, but #229 shows a slight incompatibility (5.1 allows using goto as an identifier, but 5.2+ doesn't). The GitHub binary is built using --all-features
, so I don't know how much of an issue the goto thing is.
EDIT: Actually, if I interpret this correctly, you can just build for all features and allow switching at runtime? That would then be by far the simplest solution, and I don't see any drawbacks?
A future goal is to do this, allow switching between Lua versions at runtime (with some sort of version flag in the stylua.toml
). This is actually an upstream issue, as our parser doesn't allow this currently [version selection is only at compile time through cargo features] - https://github.com/Kampfkarren/full-moon/issues/152#issuecomment-802430636
Thanks for the explanation (I think @tjdevries ran across the goto
issue recently ;))
I think the homebrew binary behaving exactly like the github release is a very reasonable expectation; I'll go with that then for now. It can always be changed later on if you decide to change the default behavior. (Personally, I'd hold out until runtime selection is possible since that seems to be by far the best option.)
Wasn't hard: https://github.com/Homebrew/homebrew-core/pull/82313
And it's merged -- you can brew install stylua
now.
@JohnnyMorganz feel free to ping me on new releases and I can bump the homebrew formula.
Thank you very much!
@clason it may be worthwhile watching the repo for releases only to get notified automatically when a new release is out. Completely up to you though.
Also, if anyone wants to make a PR to add homebrew under other installation methods in the README, feel free. Otherwise, I'll do it later when I'm free
@clason it may be worthwhile watching the repo for releases only to get notified automatically when a new release is out. Completely up to you though.
Sure, I can do that. I get so many notifications from other repos, though, that I might miss it :)
Also, if anyone wants to make a PR to add homebrew under other installation methods in the README, feel free. Otherwise, I'll do it later when I'm free
You can use https://repology.org/project/stylua/badges (once they update), too
Better for managing updates and doesn't require installing rust.
I realized it's going to be tricky since there are different modes when compiling e.g. lua 5.1 vs 5.2. Since 5.1 is the default, I guess it will also be the one chosen when providing pre-built binary.