Skip to content

cargo::rustc-link-arg-cdylib should not be rejected if cdylib is not in crate-type #16487

@usamoi

Description

@usamoi

Problem

Consider this package.

Cargo.toml:

[package]
name = "foo"
version = "0.0.0"
edition = "2024"

build.rs:

fn main() {
    println!("cargo::rustc-link-arg-cdylib=-lhack");
}

Cargo emits a warning for it.

warning: [email protected]: cargo::rustc-link-arg-cdylib was specified in the build script of foo v0.0.0, but that package does not contain a cdylib target

Allowing this was an unintended change in the 1.50 release, and may become an error in the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.

This warning may seem reasonable; however, users may take advantage of it by using

cargo rustc --crate-type cdylib

And it totally works. In this case, there should be no warning. The warning is configured only to inform the user not to rely on rustc-link-arg-cdylib being transitive through dependencies. Therefore, we should remove this warning, or at least stop telling the user that it will be rejected.

cc #9562

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version


Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-crate-typesArea: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)C-bugCategory: bugCommand-rustcS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions