Search code examples
rustrust-tokiorust-sqlxrust-axum

Why do I get a "only one runtime can be active" error when I've only specified one runtime for sqlx and axum-database-sessions?


From Cargo.toml:

[package]
name = "sitegen"
version = "0.2.0"
edition = "2021"

[dependencies]
axum_database_sessions = { version = "5.0", features = [ "mysql-native"] }
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "mysql"] }
tokio = { version = "1.0", features = ["full"] }

Compile Error:

error: only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] can be enabled
 --> /home/dsrich/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-rt-0.6.2/src/lib.rs:23:1
  |
23 | / compile_error!(
24 | |     "only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
25 | |      'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
26 | |      'runtime-tokio-rustls'] can be enabled"
27 | | );
  | |_^

error: could not compile `sqlx-rt` due to previous error

I am using the latest rust x86-64 on linux, MySQL, and having rustls present in Cargo.toml or not makes no difference. Any suggestions? Just makes no sense to me...

Just trying to compile it to start using it with axum-sessions


Solution

  • The default features of axum_database_session is ["postgres-rustls"] therefore if you want to use *-native you have to disable default features:

    axum_database_sessions = { version = "5.0", default-features = false, features = ["mysql-native"] }
    

    but since you're explicitly including rustls in your dependency on sqlx you probably just want to use mysql-rustls instead, still without the default features because you're using MySQL instead of PostgreSQL:

    axum_database_sessions = { version = "5.0", default-features = false, features = ["mysql-rustls"] }