Skip to content

Passing multiple --target options behaves differently than compiling separately #16038

@mohe2015

Description

@mohe2015

Problem

Passing multiple --target options fails to compile while running cargo separately works.

Steps

Create an empty lib project with

[package]
name = "cargo-multiple-targets-bug"
version = "0.1.0"
edition = "2024"

[dependencies]
tokio = { version = "1", features = [] }

[target.'cfg(target_arch = "x86_64")'.dependencies]
tokio = { version = "1", features = ["full"] }

Run: cargo build --target wasm32-unknown-unknown --target x86_64-unknown-linux-gnu. It fails with This wasm target is unsupported by mio. If using Tokio, disable the net feature.
Running cargo build --target wasm32-unknown-unknown and cargo build --target x86_64-unknown-linux-gnu separately works.

Possible Solution(s)

No response

Notes

Feature introduced in https://blog.rust-lang.org/2022/09/22/Rust-1.64.0/#cargo-improvements-workspace-inheritance-and-multi-target-builds
Maybe related to #1197 ?
Found this while using rust-analyzer with multiple targets in the config and first thought it was a rust-analyzer specific problem.

Version

cargo 1.90.0 (840b83a10 2025-07-30)
release: 1.90.0
commit-hash: 840b83a10fb0e039a83f4d70ad032892c287570a
commit-date: 2025-07-30
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.14.1-DEV (sys:0.4.82+curl-8.14.1 vendored ssl:OpenSSL/3.5.0)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: NixOS 25.5.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cross-compilingArea: using --target flag for other platformsA-features2Area: issues specifically related to the v2 feature resolverC-bugCategory: bugS-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