Skip to content

rustc-link-arg does not propagate transitively #9554

Closed
@tronical

Description

@tronical

Problem
With #9523 the following use-case does not compile anymore with nightly. It works with current stable.

  1. A -sys crate links against an external library using cargo:rustc-link-lib/cargo:rustc-link-lib-framework in its build.rs. The crate is to be consumed by a cdylib crate. To make consumption easy, build.rs of the -sys crate also prints out cargo:rustc-cdylib-link-arg=-Wl,-rpath,/some/path.
  2. The cdylib crate depends on the -sys crate and the cdylib is linked in a way that the external library becomes a dependency for the dynamic linker and the rpath is set due to the propagation of rustc-cdylib-link-arg from the -sys crate to the final cdylib crate.

With stable rust this works as described, with nightly this now produces a build error when compiling the -sys crate due to the use of rustc-cdylib-link-arg in the non-cdylib -sys crate.

Concrete example:

Building the qttypes crate from https://github.com/woboq/qmetaobject-rs/tree/master/qttypes produces the error that #9523 introduced:

$ cargo +nightly build
   Compiling qttypes v0.2.1 (/Users/simon/src/qmetaobject-rs/qttypes)
error: invalid instruction `cargo:rustc-cdylib-link-arg` from build script of `qttypes v0.2.1 (/Users/simon/src/qmetaobject-rs/qttypes)`
The package qttypes v0.2.1 (/Users/simon/src/qmetaobject-rs/qttypes) does not have a cdylib target.

Possible Solution(s)

Allow rustc-cdylib-link-arg again in non-cdylib crates to avoid breaking their build with the next stable release.

Notes

Output of cargo version:

cargo 1.54.0-nightly (0cecbd6 2021-06-01)
cargo 1.52.0 (6976741 2021-04-21)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions