Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crate not found in integration tests if crate-type = ["cdylib"] #6659

Open
ckaran opened this issue Feb 13, 2019 · 7 comments
Open

Crate not found in integration tests if crate-type = ["cdylib"] #6659

ckaran opened this issue Feb 13, 2019 · 7 comments
Labels
A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) A-documenting-cargo-itself Area: Cargo's documentation S-triage Status: This issue is waiting on initial triage.

Comments

@ckaran
Copy link

ckaran commented Feb 13, 2019

Problem
I am developing code that needs to work with python, which requires me to have a crate type of cdylib. It turns out that when you follow the recommendation to use a tests directory, the code within the directory cannot find the crate, failing with an error like the following:

   Compiling cargo_issue_6659 v0.1.0 (/home/cfkaran2/Desktop/cargo_issue_6659)
     Running `rustc --edition=2018 --crate-name tester tests/tester.rs --color always --emit=dep-info,link -C debuginfo=2 --test -C metadata=0525a91fc572753f -C extra-filename=-0525a91fc572753f --out-dir /home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps -C incremental=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/incremental -L dependency=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps`
     Running `rustc --edition=2018 --crate-name cargo_issue_6659 src/lib.rs --color always --emit=dep-info,link -C debuginfo=2 --test -C metadata=b9fa70b838dfddae -C extra-filename=-b9fa70b838dfddae --out-dir /home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps -C incremental=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/incremental -L dependency=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps`
error[E0463]: can't find crate for `rustc_issue_report_cdylib`
 --> tests/tester.rs:1:1
  |
1 | extern crate rustc_issue_report_cdylib;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `cargo_issue_6659`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name tester tests/tester.rs --color always --emit=dep-info,link -C debuginfo=2 --test -C metadata=0525a91fc572753f -C extra-filename=-0525a91fc572753f --out-dir /home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps -C incremental=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/incremental -L dependency=/home/cfkaran2/Desktop/cargo_issue_6659/target/debug/deps` (exit code: 1)
warning: build failed, waiting for other jobs to finish...
error: build failed

Steps

  1. Checkout the repository at https://github.com/ckaran/cargo_issue_6659.
  2. Follow the instructions in the README.md

Possible Solution(s)

None known.

Notes

$ cargo -V -vvv
cargo 1.32.0 (8610973aa 2019-01-02)
release: 1.32.0
commit-hash: 8610973aaf48615ba7dc9a38a9a2795ba6f36a31
commit-date: 2019-01-02

$ rustc -Vv
rustc 1.32.0 (9fda7c223 2019-01-16)
binary: rustc
commit-hash: 9fda7c2237db910e41d6a712e9a2139b352e558b
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0

$ uname -a
Linux EMANE 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic
@ckaran ckaran added the C-bug Category: bug label Feb 13, 2019
ckaran added a commit to ckaran/cargo_issue_6659 that referenced this issue Feb 13, 2019
This repository contains all information needed to duplicate the bug report for
cargo (issue at rust-lang/cargo#6659).
@ehuss
Copy link
Contributor

ehuss commented Feb 13, 2019

You can add rlib (or lib) to the crate-type list, and it should work. Tests can't link to the cdylib.

BTW, there's a typo in your example, tests/tester.rs should have extern crate cargo_issue_6659;.

@ckaran
Copy link
Author

ckaran commented Feb 13, 2019

Ah, sorry, since there is a chicken & egg problem between creating a repo that has the same name as the issue it's for, I sometimes forget to change the names. Now fixed.

As for setting to an rlib or lib, the problem is that I'm using pyo3, which says that you must set the library type to cdylib, and not having my integration tests work was surprising to me. If it is known that tests can't link to cdylib type libraries, it may be worth updating cargo's (or maybe rustc's) documentation to reflect this fact.

@ehuss ehuss added A-documenting-cargo-itself Area: Cargo's documentation and removed C-bug Category: bug labels Feb 13, 2019
@ehuss
Copy link
Contributor

ehuss commented Feb 13, 2019

Yea, the documentation for crate-types could definitely be improved in general.

Feel free to leave more comments here if you run into any other issues. Otherwise I'll just leave this open as a documentation issue.

@ehuss ehuss added the A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) label Apr 6, 2020
daviddrysdale added a commit to project-oak/oak that referenced this issue Jun 15, 2020
Most of the tests for example Oak Applications just use the external
gRPC service definition for testing, and so can be external integration
tests rather than unit tests.

This does require an "rlib" target for the modules though, because of
rust-lang/cargo#6659

The trusted_information_retrieval example's tests included both unit
tests and integration tests, so is split.  Along the way, make the
floating comparisons in the unit tests a bit more robust.

Fixes #1054.
@vjpr
Copy link

vjpr commented Oct 1, 2021

There are some potential issues with just adding `lib' to get it to work. See: #4881.

egithinji added a commit to tijlleenders/ZinZen-scheduler that referenced this issue Aug 26, 2022
This is related to an issue described here: rust-lang/cargo#6659
Without this change the `tests` directory can't access the scheduler
crate.
@Shatur
Copy link

Shatur commented Oct 18, 2022

You can add rlib (or lib) to the crate-type list, and it should work. Tests can't link to the cdylib.

I'd like to add that this doesn't work with no_std because cdylib target requires a panic_handler, but lib doesn't, and this results in symbol duplication when building tests.

@gzurl
Copy link

gzurl commented May 5, 2023

You can add rlib (or lib) to the crate-type list, and it should work. Tests can't link to the cdylib.

BTW, there's a typo in your example, tests/tester.rs should have extern crate cargo_issue_6659;.

@ehuss, is adding a second crate-type (such as rlib) still the preferred way to solve this?
It works, but it makes cargo build last longer since it has to generate two libraries...

@ehuss
Copy link
Contributor

ehuss commented May 5, 2023

I don't think there is any other way to do it right now.

laurynas-biveinis added a commit to laurynas-biveinis/kirunadb that referenced this issue May 24, 2023
- Move some of the existing tests to tests/db.rs
- Split out an internal "kirunadb_test_helpers" crate for code shared between
  unit and integration tests.
- Make transaction_manager module public, for integration tests, fix the new
  Clippy warnings.
- Add "rlib" crate type for kirunadb so that the integration tests could
  actually import it. This is rust-lang/cargo#6659 and
  it can be removed once that issue is fixed.
@epage epage added the S-triage Status: This issue is waiting on initial triage. label Oct 31, 2023
ServiusHack added a commit to ServiusHack/MStarPlayer-MQTT-Plugin that referenced this issue Nov 22, 2023
As mentioned upstream[^1] the integration tests aren't able to use
cdylib crate types so "lib" was added to the list of crate types.

To not having to repeat the plugin interface types for Rust in the
integration test they were made public in the library.

The integration test needs a running MQTT server to which it will
connect. That way the full functionality (except for mstarConfigure with
its UI) can be tested.

[^1]: rust-lang/cargo#6659 (comment)
ozaner added a commit to ozaner/py03_template that referenced this issue Mar 5, 2024
Adds an entry point on the rust side. Had to change cdylib to rdlib (rust-lang/cargo#6659)
ozaner added a commit to ozaner/py03_template that referenced this issue Mar 22, 2024
Adds an entry point on the rust side. Had to change cdylib to rdlib
(see rust-lang/cargo#6659)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-crate-types Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.) A-documenting-cargo-itself Area: Cargo's documentation S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

6 participants