Skip to content

cargo:: syntax should be permitted despite MSRV with the right configuration #13868

@joshlf

Description

@joshlf

Currently, zerocopy's build.rs script contains the following:

    for version_cfg in version_cfgs {
        if rustc_version >= version_cfg.version {
            println!("cargo:rustc-cfg={}", version_cfg.cfg_name);
        }
    }

We have a lot of cfgs that are now triggering the recently-added unexpected_cfgs lint. In order to fix this, I added the following to our build script:

    if rustc_version >= (Version { major: 1, minor: 77, patch: 0 }) {
        for version_cfg in &version_cfgs {
            println!("cargo::rustc-check-cfg=cfg({})", version_cfg.cfg_name);
        }
    }

Note that this is gated to only run on Rust version 1.77 or later, since that's when the cargo:: syntax was introduced.

Unfortunately, this causes the following error to be emitted:

error: the `cargo::` syntax for build script output instructions was added in Rust 1.77.0, but the minimum supported Rust version of `zerocopy v0.8.0-alpha.9 (.../zerocopy)` is 1.56.0.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script for more information about build script outputs.

This is spurious since our version detection logic will ensure that we don't emit these annotations prior to 1.77, but since it's a hard error, there's no way to work around it.

It would be great if there were a way to ask Cargo to disable this error for cases like these. The alternative for us is to just add a blanket #![allow(unexpected_cfgs)], which would be a shame since that lint is genuinely useful.

(I will also note that this error seems especially odd given that pre-1.77 toolchains simply ignore cargo::; it doesn't cause a compilation error or even a warning)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-diagnosticsArea: Error and warning messages generated by Cargo itself.E-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions