#20 set custom profile for cargo to override incompatible upstream settings
Merged by decathorpe. Opened by decathorpe.
Unknown source main

Download 20.patch

This is an implementation of the idea described in issue #19.

  • %cargo_prep injects a profile named "rpm" into the cargo configuration, which inherits from the "release" profile, with overrides as necessary
  • %cargo_build, %cargo_install and %cargo_test macros are adjusted to use --profile rpm instead of --release
  • a symbolic link from target/release to target/rpm is created by %cargo_build for backwards compatibility
    (for example, some packages install files from target/release/*, like bash completions that are dynamically generated during the build)

Also, this PR includes a change that ensures that any pre-existing .cargo directory is removed before a new .cargo/config is written. This works around crates that ship their own .cargo/config or .cargo/config.toml, which currently causes cargo to print warnings when both files exist (though it does use .cargo/config over .cargo/config.toml if the former exists).

I set up a COPR that has rust-packaging v25 snapshot with these patches applied, and they appear to work as intended:
https://copr.fedorainfracloud.org/coprs/decathorpe/rust-packaging-v25/monitor/


Reviewing the commits separately might be easier than reviewing the full diff.

Also, this PR includes a change that ensures that any pre-existing .cargo directory is removed before a new .cargo/config is written.

Perhaps keeping the warning is a good thing? Upstreams might include extra flags in here that we may want to preserve and having a visible warning alerts packagers of that.

passing -v to rm might be a good idea so its clearer what's being removed

We shouldn't need the subshell + pipefail thing if there's no pipes here.

Also, this PR includes a change that ensures that any pre-existing .cargo directory is removed before a new .cargo/config is written.

Perhaps keeping the warning is a good thing? Upstreams might include extra flags in here that we may want to preserve and having a visible warning alerts packagers of that.

I have never seen upstream .cargo/config{,.toml} files that had settings that we could apply to our builds. They often either override rustflags to build for target-cpu=native (which we cannot support), or set some other custom --cfg flags (which we also don't support). So I still think getting rid of them completely is the right choice (since they're also not taken into account right now, they only cause useless warnings).

passing -v to rm might be a good idea so its clearer what's being removed

RPM will already print this line to the log, there's no need for -v. All other occurrences of %{__rm} don't have it either.

We shouldn't need the subshell + pipefail thing if there's no pipes here.

Right. I'll remove it.

1 new commit added

  • simplify cargo_build macro (no need for subshell here)

1 new commit added

  • move creation of target/release compat symlink to %cargo_prep

Hm ... maybe -C strip=none should be added to the default RUSTFLAGS in addition to setting it in the profile? That way all applications should get the setting, whether they're compiled with %cargo_build or not.

1 new commit added

  • also include -Cstrip=none in $RUSTFLAGS / %build_rustflags

Pull-Request has been merged by decathorpe

Metadata