#25 add macros for overriding installation of crate sources and binaries
Merged by decathorpe. Opened by decathorpe.
Unknown source main

Download 25.patch

I'm trying to address https://pagure.io/fedora-rust/rust-packaging/issue/22.

This PR add two new macros to allow modifying the default behaviour of the %cargo_install macro:

  • %cargo_install_lib 1
  • %cargo_install_bin 1

Setting the first macro to 0 prevents installation of crate sources to %{crate_instdir} even if the crate provides a [lib] interface. Setting the second macro to 0 prevents installation of executables even of the crate defines any [[bin]] targets explicitly or implicitly.

This should address two use cases that are currently not correctly supported:

  • Disable installation of binaries that need to be built but should not be installed (for example, binaries that are required for running tests).
  • Disable installation of library sources in packages that are not Rust crates / published on crates.io.

Support for setting both macros will be added to rust2rpm separately once this lands in cargo-rpm-macros.

isn't %{__cargo_is_lib} going to expand to either 0 or 1 as well?

bash-5.2$ if 1; then echo true-ish; fi
bash: 1: command not found
bash-5.2$ 

We should probably compare them both to 1 explicitly

e.g.

bash-5.2$ if [ 1 == 1 ] && [ 0 == 1 ]; then echo true-ish; fi
bash-5.2$ if [ 1 == 1 ] && [ 1 == 1 ]; then echo true-ish; fi
true-ish

No, %__cargo_is_lib expands to [ $(/usr/bin/cargo2rpm --path Cargo.toml is-lib) -eq 1 ], so that should be fine. I can add the -eq 1 to the second one too if you think that would be better?

rebased onto fa7e229eb3223d7f574f9872ad75de3739b1cb6e

I think we do need -eq 1

michel@michel-fedora-PC198L6J:~$ [ 0 ] && echo true
true
michel@michel-fedora-PC198L6J:~$ [ 0 -eq 1 ] && echo true
michel@michel-fedora-PC198L6J:~$ 

Ok, I tested the new version with a package, and setting either %global cargo_install_lib 0 and %global cargo_install_bin 0 both had the intended effect (and not setting either did not change the default behaviour), so I'm going to merge this.

Pull-Request has been merged by decathorpe

Metadata