Skip to content

Commit

Permalink
rustup-init: install proxy binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Jul 19, 2024
1 parent e9c8e9d commit 9d0f5a5
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions Formula/r/rustup-init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class RustupInit < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "5d9ff7b986a355cb60bff64754c0cb7213361a48e02991e246d8f7b242f38de9"
end

keg_only "it conflicts with rust"

depends_on "rust" => :build

uses_from_macos "curl"
Expand All @@ -27,26 +29,45 @@ class RustupInit < Formula
end

def install
system "cargo", "install", "--features", "no-self-update", *std_cargo_args
system "cargo", "install", "--features=no-self-update", *std_cargo_args

%w[cargo cargo-clippy cargo-fmt cargo-miri clippy-driver rls rust-analyzer
rust-gdb rust-gdbgui rust-lldb rustc rustdoc rustfmt rustup].each do |name|
bin.install_symlink bin/"rustup-init" => name
end
generate_completions_from_executable(bin/"rustup", "completions", base_name: "rustup")
end

def post_install
(HOMEBREW_PREFIX/"bin").install_symlink bin/"rustup", bin/"rustup-init"
end

def caveats
<<~EOS
Please run `rustup-init` to initialize `rustup` and install other Rust components.
To initialize `rustup`, set a default toolchain:
rustup default stable
EOS
end

test do
ENV["CARGO_HOME"] = testpath/".cargo"
ENV["RUSTUP_HOME"] = testpath/".multirust"
ENV["RUSTUP_HOME"] = testpath/".rustup"
ENV.prepend_path "PATH", bin

assert_match "no default is configured", shell_output("#{bin}/rustc --version 2>&1", 1)
system bin/"rustup", "default", "stable"

system bin/"cargo", "init", "--bin"
system bin/"cargo", "fmt"
system bin/"rustc", "src/main.rs"
assert_equal "Hello, world!", shell_output("./main").chomp
assert_empty shell_output("#{bin}/cargo clippy")

# Check for stale symlinks
system bin/"rustup-init", "-y"
(testpath/"hello.rs").write <<~EOS
fn main() {
println!("Hello World!");
}
EOS
system testpath/".cargo/bin/rustc", "hello.rs"
assert_equal "Hello World!", shell_output("./hello").chomp
bins = bin.glob("*").to_set(&:basename).delete(Pathname("rustup-init"))
expected = testpath.glob(".cargo/bin/*").to_set(&:basename)
assert (extra = bins - expected).empty?, "Symlinks need to be removed: #{extra.join(",")}"
assert (missing = expected - bins).empty?, "Symlinks need to be added: #{missing.join(",")}"
end
end

0 comments on commit 9d0f5a5

Please sign in to comment.