sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Unable to install `sea-orm-cli` with `runtime-tokio-rustls`

Open thegenem0 opened this issue 7 months ago • 6 comments

Description

Unable to install sea-orm-cli with the following flags:

  • runtime-tokio-rustls
  • cli
  • codegen

Steps to Reproduce

Running:

cargo install sea-orm-cli --no-default-features --features "cli,codegen,runtime-tokio-rustls"

yields:

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `async_std`
 --> /home/.../sea-orm-cli-1.1.10/src/bin/sea.rs:3:3
  |
3 | #[async_std::main]
  |   ^^^^^^^^^ use of unresolved module or unlinked crate `async_std`

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `async_std`
 --> /home/.../sea-orm-cli-1.1.10/src/bin/main.rs:1:3
  |
1 | #[async_std::main]
  |   ^^^^^^^^^ use of unresolved module or unlinked crate `async_std`

error[E0752]: `main` function is not allowed to be `async`
 --> /home/.../sea-orm-cli-1.1.10/src/bin/main.rs:2:1
  |
2 | async fn main() {
  | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

error[E0752]: `main` function is not allowed to be `async`
 --> /home/.../sea-orm-cli-1.1.10/src/bin/sea.rs:4:1
  |
4 | async fn main() {
  | ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

Running:

cargo install sea-orm-cli --no-default-features --features "cli,codegen,runtime-tokio-rustls,async-std"

yields:

error[E0433]: failed to resolve: could not find `task` in `async_std`
   --> /home/.../sea-orm-cli-1.1.10/src/bin/main.rs:1:1
    |
1   | #[async_std::main]
    | ^^^^^^^^^^^^^^^^^^ could not find `task` in `async_std`
    |
note: found an item that was configured out
   --> /home/.../async-std-1.13.1/src/lib.rs:300:13
    |
300 |     pub mod task;
    |             ^^^^
note: the item is gated behind the `alloc` feature
   --> /home/.../async-std-1.13.1/src/lib.rs:299:1
    |
299 | / cfg_alloc! {
300 | |     pub mod task;
301 | |     pub mod future;
302 | |     pub mod stream;
303 | | }
    | |_^
    = note: this error originates in the attribute macro `async_std::main` which comes from the expansion of the macro `cfg_alloc` (in Nightly builds, run with -Z macro-backtrace for more info)

The workaround is to explicitly pass async-std features:

cargo install sea-orm-cli --no-default-features --features "cli,codegen,runtime-tokio-rustls,async-std/default,async-std/attributes"

This use-case doesn't seem to be documented, and might not be the intended way to be used, so raising for a potential fix / if someone else faces this problem.

OS: NixOS Rust: rustc 1.86.0 (05f9846f8 2025-03-31) Cargo: cargo 1.86.0 (adf9b6ad1 2025-02-28)

thegenem0 avatar May 01 '25 14:05 thegenem0

Why did u need --no-default-features flag? What did u want to achieve here? It's absolutely edge case and shouldn't be documented.

lamualfa avatar May 19 '25 02:05 lamualfa

My apologies, I don't seem to have mentioned, that this arises when there's no system OpenSSL available.

Without --no-default-features, and no openssl and pkg-config available, the install fails with an error, similar to this:

warning: openssl-sys@{version}: Could not find directory of OpenSSL installation, and this `-sys` crate cannot proceed without this 
knowledge.
If OpenSSL is installed and this crate had trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the compilation process.
See stderr section below for further information.
error: failed to run custom build command for `openssl-sys v{version}`

If using sea-orm-cli is supported using rustls, the deafault features shouldn't force a dependency on a system OpenSSL, especially when the runtime-tokio-rustls feature is explicitly enabled.

thegenem0 avatar May 19 '25 10:05 thegenem0

@thegenem0 sea-orm-cli wasn't supposed to be on your rust app. it must installed globally as a standalone binary. so make sure to run the cargo install sea-orm-cli anywhere other than folder with Cargo.toml inside.

but if you need to reuse any public functions from sea-orm-cli library in your rust app, make sure to install all dependent macros like async-std used by the sea-orm-cli binary.

lamualfa avatar May 19 '25 13:05 lamualfa

@lamualfa The concept of "install globally" is a bit ambiguous. There are cases/environments where something like OpenSSL is just not available to link against.

In my specific case, using NixOS, it is available, but I'm using devenv, and I prefer not linking against the system OpenSSL if I can avoid it. This makes reproducibility much better, as there are less assumptions about whether building it on a different system will fail because there's no installed OpenSSL or it's an incompatible version, etc.

I usually just opt to use rustls (unless OpenSSL is a weird requirement of some other lib), which cargo builds and makes available for linking against if the feature flags are set up correctly.

A great example of this is using something like tokio with rustls as the TLS lib, it does not care about your specific OpenSSL install, as it's not linking against it at all. (I'm aware tokio is a lib and sea-orm-cli is not, but the logic still applies)

Because of this, when runtime-tokio-rustls is enabled, cargo correctly pulls down rustls, builds it and would attempt to link against this, but there's an explicit dependency on runtime-async-std-native-tls in the default feature group which makes this fail. sea-orm-cli doesn't make you explicitly pick one of the 4 options, it just defaults to this. Maybe it should, the same way as sea-orm does?

This needs to be disabled to prevent sea-orm-cli from attempting to link against it, which then brings the second issue. Because async-std's features are enabled in runtime-async-std-native-tls (probably in the actual sqlx lib), when that is disabled, and the async-std feature is enabled, it (incorrectly) only requires async-std/default and does not require async-std/attributes, which results in missing symbols during compilation.

this macro from async-std fails, as it needs the appropriate attributes, which are not installed by default.

This may very well be a config issue in the underlying sqlx lib, as async-std's attributes are not enabled as a dep but are enabled as a dev-dep

Could look into it a bit more in-depth, but a maintainer might just look at this and make a quickfix much faster than I could get to it

thegenem0 avatar May 19 '25 14:05 thegenem0

I also experienced this issue - I don't have openssl on my system and installing with runtime-tokio-rustls failed exactly as described.

Thanks to @thegenem0 I was able to install sea-orm-cli by using the same features.

Meanwhile, consuming the sea-orm crate with the runtime-tokio-rustls feature does work:

sea-orm = { version = "1.1.10", features = ["sqlx-sqlite", "macros", "runtime-tokio-rustls"] }

jasonpeacock avatar May 22 '25 17:05 jasonpeacock

sea-orm-cli wasn't supposed to be on your rust app.

Well, that is not true. Check the discussion to understand why. https://github.com/SeaQL/sea-orm/discussions/1889

xamgore avatar May 25 '25 21:05 xamgore