Cargo: warning: file found to be present in multiple build targets

Created on 23 Aug 2018  路  7Comments  路  Source: rust-lang/cargo

In the cargo-asm project cargo produces the warning:

warning: file found to be present in multiple build targets: cargo-asm/src/main.rs

Since it is a warning, I assume that I must be doing something wrong / not as good as possible there, and that there is something that I can do to silence it.

I have no idea what that can be: cargo-asm produces two binaries, cargo-asm and cargo-llvm-ir, both are identical. Ideally, I'd just produce one, and then create a link with a different name to it, or a copy. I have no idea how to do any of that with cargo.

If there is nothing that users can do about this warning, then it shouldn't be a warning until there is something that users can do.

Most helpful comment

Yeah @liuchong we'd recommend either using a library or a mod foo; pointing to the same location. If you use a shared library crate then you'll get better compile times though!

All 7 comments

This can happen when there are two targets (like two [[bin]] sections) which point to path = "cargo-asm/src/main.rs", is that present in your project?

Yes that's exactly the case.

i have this same warning but a different situation. im trying to build a library with tests... and a build script so i can generate tests from a list of files, at compile time.

tests/integration_tests.rs
tests/build.rs
tests/generated_tests.rs
tests/testfiles/data1.txt
tests/testfiles/data2.txt
src/lib.rs

Cargo.toml
[package]
name = "blargh"
version = "0.1.0"
authors = [me]
build = "tests/build.rs"

this layout is based on paholg's post here https://stackoverflow.com/questions/34662713/how-can-i-create-parameterized-tests-in-rust

thanks

Oh oops I meant to close this earlier as @gnzlbg's original bug was discovered and presumably fixed. @donbright mind actually opening a new issue for that as I think it's a new use case we haven't seen before!

This can happen when there are two targets (like two [[bin]] sections) which point to path = "cargo-asm/src/main.rs", is that present in your project?

This is exactly what I want, could I disable this warning? Or this better way to generate multiple binaries with same source file?

Maybe I should create a section

[lib]
name = "my_lib"
path = "src/lib.rs"

And then create two file with different name but same content in src/bin/ directory?

Yeah @liuchong we'd recommend either using a library or a mod foo; pointing to the same location. If you use a shared library crate then you'll get better compile times though!

Thanks! @alexcrichton

Was this page helpful?
0 / 5 - 0 ratings