flox icon indicating copy to clipboard operation
flox copied to clipboard

flox init setup for rust

Open jennymahmoudi opened this issue 11 months ago • 4 comments

When I am in a project directory with a Rust project, I want Flox to suggest packages to install so that I don't have to know that I need to install the rustup bundled packages individually, and so that I don't have to do the manual work to install them.

Suggested packages to install based on the Rust cookbook

# Rust toolchain
cargo.pkg-path = "cargo"
cargo.pkg-group = "rust-toolchain"
rustc.pkg-path = "rustc"
rustc.pkg-group = "rust-toolchain"
clippy.pkg-path = "clippy"
clippy.pkg-group = "rust-toolchain"
rustfmt.pkg-path = "rustfmt"
rustfmt.pkg-group = "rust-toolchain"
rust-lib-src.pkg-path = "rustPlatform.rustLibSrc"
rust-lib-src.pkg-group = "rust-toolchain"
libiconv.pkg-path = "libiconv"
libiconv.systems = ["aarch64-darwin", "x86_64-darwin"]

# rust-analyzer goes in its own group because it's updated
# on a different cadence from the compiler and doesn't need
# to match versions
rust-analyzer.pkg-path = "rust-analyzer"
rust-analyzer.pkg-group = "rust-analyzer"

TBD: what is the best way to detect a Rust project? eg. for python, Flox looks for requirements.txt

jennymahmoudi avatar Mar 28 '25 20:03 jennymahmoudi

Also detect the Rust version from an existing rust-toolchain or rust-toolchain.toml file.

zmitchell avatar Mar 28 '25 20:03 zmitchell

For Rust you'll look for Cargo.toml

zmitchell avatar Mar 28 '25 20:03 zmitchell

Also, it's important that all of the build tooling be in the same package group. It's also important to include gcc/clang and pkg-config because some Rust libraries link against native libraries, or have explicit build scripts that call the linker directly.

zmitchell avatar Mar 28 '25 20:03 zmitchell

I'll also note that this looks much cleaner when you use the "inline table" form rather than the dotted form:

cargo = { pkg-path = "cargo", pkg-group = "rust-toolchain" }
rustc = { pkg-path = "rustc", pkg-group = "rust-toolchain" }
clippy = { pkg-path = "clippy", pkg-group = "rust-toolchain" }
rustfmt = { pkg-path = "rustfmt", pkg-group = "rust-toolchain" }
rust-lib-src = { pkg-path = "rustPlatform.rustLibSrc", pkg-group = "rust-toolchain" }

zmitchell avatar Mar 28 '25 20:03 zmitchell