From d8df9c2ee9498ef8ad313e5723e35c52287c6ea3 Mon Sep 17 00:00:00 2001 From: Roland Crosby Date: Mon, 31 Jan 2022 20:08:45 -0500 Subject: [PATCH] Allow `cargo build --lib` When building Rust packages that provide libraries but no executable binaries, `cargo install` doesn't do anything; you need to use `cargo build` and install any libraries manually. See e.g. rust-lang/cargo#8294. Unfortunately, Homebrew's Rubocop "use cargo install *std_cargo_args" rule, as currently written, blocks all invocations of `cargo build`. This commit changes that rule to exclude invocations of `cargo build` that use the `--lib` argument (`--lib` specifies to Cargo that a package's library targets should be built). This will enable library packages to be built while retaining the "use cargo install *std_cargo_args" message for the more common case when a Rust package provides executable binaries. --- Library/Homebrew/rubocops/text.rb | 4 +++- Library/Homebrew/test/rubocops/text_spec.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index 6f2beaf50e..9ed0887b28 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -70,7 +70,9 @@ module RuboCop problem "use \"dep\", \"ensure\", \"-vendor-only\"" end - find_method_with_args(body_node, :system, "cargo", "build") do + find_method_with_args(body_node, :system, "cargo", "build") do |m| + next if parameters_passed?(m, /--lib/) + problem "use \"cargo\", \"install\", *std_cargo_args" end diff --git a/Library/Homebrew/test/rubocops/text_spec.rb b/Library/Homebrew/test/rubocops/text_spec.rb index b8ae63dbd1..26edf5e3dd 100644 --- a/Library/Homebrew/test/rubocops/text_spec.rb +++ b/Library/Homebrew/test/rubocops/text_spec.rb @@ -205,6 +205,19 @@ describe RuboCop::Cop::FormulaAudit::Text do RUBY end + it "doesn't reports an offense if `cargo build` is executed with --lib" do + expect_no_offenses(<<~RUBY) + class Foo < Formula + url "https://brew.sh/foo-1.0.tgz" + homepage "https://brew.sh" + + def install + system "cargo", "build", "--lib" + end + end + RUBY + end + it "reports an offense if `make` calls are not separated" do expect_offense(<<~RUBY) class Foo < Formula