Skip to content

--crate-type cdylib causes errors looking for rlib dependencies #10356

Closed
@seanmonstar

Description

@seanmonstar

Problem

When running cargo rustc --crate-type cdylib -Z unstable-options, I see errors that dependencies were expected to be available in rlib format. If I put the crate-type in the Cargo.toml, I don't see these errors.

Output:

 ~/code/test.rs $ cargo rustc --crate-type cdylib -Z unstable-options
   Compiling scratchpad v0.0.0 (/home/sean/code/test.rs)
error: crate `http` required to be available in rlib format, but was not found in this form

Steps

Here's a minimal repro:

  1. Make a new crate, using any simple dependency. http = "*" works.
  2. In lib.rs, add pub extern "C" fn yeet() { println!("{:?}", http::StatusCode::OK) }.
  3. Run cargo rustc --crate-type cdylib -Z unstable-options.

I originally discovered this by trying to convert hyper to use it:

  1. Removing the [lib] and crate-type = ["cdylib", "staticlib", "lib"] lines.
  2. Run cargo rustc --crate-type cdylib -Z unstable-options.

Possible Solution(s)

No response

Notes

  • If I keep the line in Cargo.toml, then hyper builds properly.
  • When making a minimal repro, I noticed that it works without a dependency, and it also works with a dependency that isn't used. You must use the dependency in the file.

Version

cargo 1.60.0-nightly (25fcb13 2022-02-01)
release: 1.60.0-nightly
commit-hash: 25fcb135d02ea897ce894b67ae021f48107d522b
commit-date: 2022-02-01
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Ubuntu 16.04 (xenial) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions