prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
582 stars 61 forks source link

Compilation error with Tiberius and workspace setup #392

Open zifeo opened 1 year ago

zifeo commented 1 year ago

I am getting a compilation error with Tiberius when using quaint in a workspace. Outside workspace, it works well without issue. The fix might be obvious, but I am having a bad time to isolate correctly the error.

   Compiling tiberius v0.9.5
error[E0428]: the name `create_tls_stream` is defined multiple times
  --> /Users/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/tiberius-0.9.5/src/client/tls_stream.rs:39:1
   |
31 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
32 | |     config: &Config,
33 | |     stream: S,
34 | | ) -> crate::Result<TlsStream<S>> {
35 | |     native_tls_stream::create_tls_stream(config, stream).await
36 | | }
   | |_- previous definition of the value `create_tls_stream` here
...
39 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
40 | |     config: &Config,
41 | |     stream: S,
42 | | ) -> crate::Result<TlsStream<S>> {
43 | |     opentls_tls_stream::create_tls_stream(config, stream).await
44 | | }
   | |_^ `create_tls_stream` redefined here
   |
   = note: `create_tls_stream` must be defined only once in the value namespace of this module

error[E0252]: the name `TlsStream` is defined multiple times
  --> /Users/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/tiberius-0.9.5/src/client/tls_stream.rs:20:16
   |
14 | pub(crate) use native_tls_stream::TlsStream;
   |                ---------------------------- previous import of the type `TlsStream` here
...
20 | pub(crate) use opentls_tls_stream::TlsStream;
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `TlsStream` reimported here
   |
   = note: `TlsStream` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
   |
20 | pub(crate) use opentls_tls_stream::TlsStream as OtherTlsStream;
   |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0308]: mismatched types
  --> /Users/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/tiberius-0.9.5/src/client/tls_stream.rs:43:5
   |
43 |     opentls_tls_stream::create_tls_stream(config, stream).await
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `async_native_tls::TlsStream`, found struct `opentls::async_io::TlsStream`
   |
   = note: expected enum `std::result::Result<async_native_tls::TlsStream<S>, _>`
              found enum `std::result::Result<opentls::async_io::TlsStream<S>, _>`

Can be reproduced with:

# test/Cargo.toml
[package]
name = "test"
version = "0.1.0"
edition = "2021"

[dependencies.quaint]
git = "https://github.com/prisma/quaint"
features = [
    "postgresql",
    "mysql",
    "mssql",
    "sqlite",
    "json",
    "uuid",
    "chrono",
    "bigdecimal"
]
// test/src/main.rs
fn main() {
    println!("Hello, world!");
}
# Cargo.toml
[workspace]
members = [
    "test"
]
zifeo commented 1 year ago

@cprieto Would you have an idea? I am really having a hard-time figuring this out.

Brendonovich commented 1 year ago

I encountered the same problem with Prisma Client Rust, and put the fix in the documentation. Then problem is that you're using a virtual workspace, so by default version 1 of the Cargo feature resolver is being used, but tiberius requires using version 2 of the feature resolver, so add resolver = "2" after members in your root Cargo.toml