Skip to content

dylib dependency of proc-macro causes build to fail with opaque error message #16356

@gmorenz

Description

@gmorenz

Problem

If you have a proc-macro depend on a crate with crate-type=["dylib"] building the proc-macro apparently succeeds, but then building the crate which uses it fails with an error message

error[E0463]: can't find crate for `macone`
 --> user/src/main.rs:1:1
  |
1 | macone::macone!();
  | ^^^^^^ can't find crate

This occurs because LD_LIBRARY_PATH is not set when running rustc to build the final crate that uses the proc macro, and as a result it can't find the shared dep. And rustc's error messages here aren't very good.

Steps

git clone https://github.com/gmorenz/shared_proc_macro_dep/
cd shared_proc_macro_dep/user
cargo build

Possible Solution(s)

There are three solutions here:

  1. Error if proc macros depend on dylib's (or probably cdylibs)
  2. Provide LD_LIBRARY_PATH to rustc invocations.
  3. Kick this out to rustc to provide better error messages when building the crate that depends on a proc macro that it fails to load. Which it probably should - but its not in the same position as cargo is to understand why that's failing.

The second option would enable things like this (without hacks): facet-rs/facet#1143

The first is probably less work.

Notes

No response

Version

cargo 1.93.0-nightly (2a7c49606 2025-11-25)
release: 1.93.0-nightly
commit-hash: 2a7c4960677971f88458b0f8b461a866836dff59
commit-date: 2025-11-25
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Arch Linux Rolling Release [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions