Skip to content

Should build.rs be compiled like plugins? #5436

Open
@ehuss

Description

@ehuss

Currently, build.rs scripts (and build-dependencies) are built with the same restrictions as compiler plugins (panic and lto cannot be set, maybe other issues?). I don't think this is quite correct because build scripts are not used the same way proc-macro/plugins are.

This is caused by several parts of the code that check for_host() but don't differentiate for build scripts (but some places do!).

One consequence of the current implementation is that a dependency that is shared between regular dependencies and build-dependencies will be built without panic set. I'm not sure if there is much of a problem with this because dependencies built with unwind seem to be fine? (I'd like to better understand the difference, since the assembly output looks almost identical.) Another oddity is that with cargo test or cargo bench, these shared dependencies will be built twice, but with the exact same settings.

Repro:

cargo new --lib foo
cd foo
cat >> Cargo.toml <<EOL
shared = {path="shared"}
[build-dependencies]
shared = {path="shared"}
[profile.dev]
panic = "abort"
EOL

cargo new --lib shared
echo "fn main() {}" > build.rs

cargo build -v   # <- Notice that neither `build.rs` or `shared` is built with panic.

I think to fix it so that build.rs includes panic, it is a relatively simple change to avoid walking the RunCustomBuild unit in build_used_in_plugin_map.

Alternatively, to keep the current behavior and fix the shared dependencies, we should be clearing the panic flag in get_profile (instead of build_base_args), though I'm uncertain what other issues there might be.

In general, it seems to be dangerous to use for_host() if the code is really wanting to know if something is a plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsC-enhancementCategory: enhancementS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions