Homebrew and Rustup conflict inquiry

My current version of rust is installed using rustup. Rustup itself is installed without using homebrew. Now when I try to install some packages like brew install bat, as bat depends on rust on build, homebrew pulls rust also. It doesn't recognize the rust toolchain installed using rustup. Upon a few searching I found this comment, saying that homebrew doesnt cooperate intentionally with non-homebrew rust.

If it's the case, do I let homebrew install it's own version of rust? Will it not have conflict in rustup's version?

1 Like

If you already have a working Rust toolchain, why are you installing cargo apps through homebrew? Just use cargo install. You'll also have more control of the installation, e.g. you can set RUSTFLAGS='-C target-cpu=native' and get potentially better performance.

It seems that bat is packaged weirdly. Homebrew usually has pre-built binaries for tools written in Rust, and therefore doesn't require brew-rust at install time.

2 Likes

Still, I don't see a reason to use prebuilt binaries, when you can easily build them yourself. Understandable that not everyone would want to mess with language toolchains, or that one wouldn't want to mess with C/C++ libraries, but bat doesn't use those, and the OP already uses Rust.

I'll ask the opposite question: why do you want Homebrew to use your rustup-installed toolchain instead of its own, for building its packages? It's usually desirable for a source build to be done using the tools that were expected when the package was created (though with Rust stability, it probably wouldn't matter either way, so I can see that saving disk space might be desirable).

1 Like

I was a long-time Linux user. When Homebrew claimed to be "The Missing Package Manager for macOS," I expected it to be the tool I would use when installing apps on Mac, similar to how pacman works in Arch or portage in Gentoo.

Also, I'm what you might call a "newb" in Rust, as it was just recently introduced in a Computer Science course I'm taking at school. Being a curious person, I wanted to study Rust in advance before the professor covered it in class. I'm just getting started learning it and haven't delved deep into its documentation. I didn't know we could use cargo to install apps system-wide; I thought it was just a package manager for a project in a folder.

I actually had Rust installed through Homebrew beforehand. After reading in a discussion that it's better to install Rust using rustup instead of Homebrew, I uninstalled it and began using rustup instead. The main reason is that I'm afraid I might mess up my installs, and having to read troubleshooting guides to fix it and cost me time.

There is little harm from having Rust installed twice. You merely need to make sure your PATH prioritizes the one you actually want to use.

1 Like

I see. I don't know whether Cargo can install apps systemwide, meaning that I don't know whether it's possible to do for all users simultaneously. Normally it installs apps in ~/.cargo/bin, thus they are available only to the current user. On the other hand, why would one do otherwise on a modern system? I guess on Linux one could use cargo install --root /bin <package> or something like that for systemwide installation.

Keeping all apps up to date can be an issue, though. It's definitely easier to do with homebrew, Cargo doesn't have any easy built-in way to do updates. You can always run the install command again, and it will update to a new version if available, but you need to do it manually for all installed apps, and you need to remember their original installation options (package name, or git url if it was installed from git, and any other possible options). Personally I use the just command runner, and keep a Just script which installs all my tools with desired options.

1 Like

There is also

which even does support a few configuration options, too, on a per-crate basis, for things like ... well ... I'll just quote the manpage

Settable options:

  • toolchain,
  • whether to use default features,
  • additional feature list,
  • build profile,
  • whether to install prereleases,
  • Cargo.lock enforcement,
  • version range locks.
2 Likes