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.
This commit is contained in:
Roland Crosby 2022-01-31 20:08:45 -05:00
parent 397afb6204
commit d8df9c2ee9
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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