Skip to content

"cannot produce proc-macro for crate as the target x86_64-unknown-linux-gnu does not support these crate types" with +crt-static #78210

Closed

Description

@otavio

Build error

% RUSTFLAGS="-C target-feature=+crt-static" cargo +nightly check
error: cannot produce proc-macro for `ctor v0.1.16` as the target `x86_64-unknown-linux-gnu` does not support these crate types

Version it worked on

It most recently worked on: rustc 1.48.0-beta.4 (fb94aa5 2020-10-20)

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Activity

  1. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 21, 2020
  2. camelid commented on Oct 21, 2020

    @camelid
    Member

    Could you provide a reproduction?

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    T-libs-api[DEPRECATED; DO NOT USE]
    on Oct 21, 2020
  4. camelid commented on Oct 21, 2020

    @camelid
    Member

    And also the version you're testing with?

  5. otavio commented on Oct 22, 2020

    @otavio
    ContributorAuthor

    And also the version you're testing with?

    The nightly of 2020-10-20.

    Could you provide a reproduction?

    I'm out of computer now, so I can't. It seems to be related to proc macro use. I can try to cook a test case for it.

  6. tesuji commented on Oct 22, 2020

    @tesuji
  7. added
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Oct 22, 2020
  8. mati865 commented on Oct 22, 2020

    @mati865
    Member

    It most recently worked on: rustc 1.48.0-beta.4 (fb94aa5 2020-10-20)

    It did not really work but didn't produce the error since +crt-static was no-op for linux-gnu.
    Since #77386 +crt-static now properly links statically.

    I think I can add workaround for it.

  9. mati865 commented on Oct 22, 2020

    @mati865
    Member

    It works with explicit target:

    $ RUSTFLAGS='-C target-feature=+crt-static' cargo b
    error: cannot produce proc-macro for `ctor v0.1.16 (/tmp/rust-ctor/ctor)` as the target `x86_64-unknown-linux-gnu` does not support these crate types
    
    $ RUSTFLAGS='-C target-feature=+crt-static' cargo b --target x86_64-unknown-linux-gnu
       Compiling libc v0.2.79
       Compiling proc-macro2 v0.4.30
       Compiling unicode-xid v0.1.0
       Compiling proc-macro2 v1.0.23
       Compiling syn v0.15.44
       Compiling unicode-xid v0.2.0
       Compiling syn v1.0.46
       Compiling lazy_static v1.4.0
       Compiling quote v0.6.13
       Compiling quote v1.0.7
       Compiling libc-print v0.1.14
       Compiling dlopen_derive v0.1.4
       Compiling dlopen v0.1.8
       Compiling ctor v0.1.16 (/tmp/rust-ctor/ctor)
       Compiling tests v0.1.0 (/tmp/rust-ctor/tests)
        Finished dev [unoptimized + debuginfo] target(s) in 7.14s
    

    cc @petrochenkov I assume it's expected that #69519 helped only the case with explicit (aka cross-compiled) target?

  10. petrochenkov commented on Oct 22, 2020

    @petrochenkov
    Contributor

    @mati865
    #69519 introduced different defaults for crt-static for executables (yes) and proc-macros (no) (should apply to all dylibs really).
    If -C target-feature=+crt-static is specified explicitly, then the compiler respects it and overrides the defaults, that's the compiler's job.

    Then cargo comes into play. AFAIK, it applies RUSTFLAGS only to target if --target specified explicitly, and to both target and host otherwise. (I remember people complaining about this inconsistency.)
    So it doesn't pass -C target-feature=+crt-static when compiling proc macro dependencies (which is correct in this case).
    I think this is a problem that should be solved at the cargo's abstraction level, in general. Cargo should provide a way to set compiler options per-crate-type and per-build-target (per-crate), and may provide its own defaults (e.g. not pass +crt-static to proc macro crates).

  11. otavio commented on Oct 23, 2020

    @otavio
    ContributorAuthor

    My biggest concern here is this looks like a regression from the user point of view; what can we currently do to workaround it until it is handled on the cargo's abtraction level, as suggested by @petrochenkov?

  12. 7 remaining items

  13. added this to the 1.48.0 milestone on Nov 6, 2020
  14. added
    relnotesMarks issues that should be documented in the release notes of the next release.
    on Nov 6, 2020
  15. Mark-Simulacrum commented on Nov 6, 2020

    @Mark-Simulacrum
    Member

    cc @XAMPPRocky for the relnotes label

  16. mati865 commented on Nov 6, 2020

    @mati865
    Member

    The regression seems to be because we're now trying to respect the new flag, which is then causing breakage.

    @Mark-Simulacrum to be more clear, -C target-feature=+crt-static is not a new flag. It existed for a long long time but *-linux-gnu targets were ignoring it until recently.

  17. joshtriplett commented on Nov 15, 2020

    @joshtriplett
    Member

    I do think we need a better solution for building statically in general.

    Passing an explicit --target is a workaround. We should have better handling for host vs target, as @petrochenkov suggested.

  18. changed the title [-]dynlib stopped building on nightly[/-] [+]"cannot produce proc-macro for `crate` as the target `x86_64-unknown-linux-gnu` does not support these crate types" with +crt-static[/+] on Nov 15, 2020
  19. Mark-Simulacrum commented on Jan 21, 2021

    @Mark-Simulacrum
    Member

    I don't believe we're intending to fix this.

  20. Aloso commented on Apr 10, 2023

    @Aloso
    Contributor

    I ran into this recently. Is there a way to provide a better error message? It wasn't obvious to me that I have to pass --target x86_64-unknown-linux-gnu when I want to statically link libc.

  21. added a commit that references this issue on Jul 23, 2023
  22. Rudxain commented on Jun 17, 2024

    @Rudxain
    Contributor

    Now that GH supports "Closing Reasons" this should be "Closed as Not Planned"

  23. added a commit that references this issue on Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libs-api[DEPRECATED; DO NOT USE]regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.relnotesMarks issues that should be documented in the release notes of the next release.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions