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

utoipa-swagger-ui: compilation error with rust-embed::compression feature enabled #1151

Open
sergiimk opened this issue Oct 19, 2024 · 6 comments
Labels
investigate Futher investigation needed before other action

Comments

@sergiimk
Copy link

sergiimk commented Oct 19, 2024

I have a project that is already using rust-embed crate to embed some web content. The dependency is declared as:

rust-embed = { version = "8", features = [
    "interpolate-folder-path",
    "compression",
] }

When I link utoipa-swagger-ui it fails to compile:

Compiling utoipa-swagger-ui v8.0.1
error: `folder` must be a relative path under `compression` feature.
 --> /home/sergiimk/blah/.target/debug/build/utoipa-swagger-ui-1d8195b4e224114b/out/embed.rs:4:1
  |
4 | / #[folder = r"/home/sergiimk/blah/.target/debug/build/utoipa-swagger-ui-1d8195b4e224114b...
5 | | struct SwaggerUiDist;
  | |_____________________^

Disabling compression feature fixes it, but given how large Swagger UI and my other content is compression would be nice to keep.

@juhaku
Copy link
Owner

juhaku commented Oct 20, 2024

This needs some troubleshooting to see whether there is something that can be done.

@juhaku juhaku added the investigate Futher investigation needed before other action label Oct 20, 2024
@JMLX42
Copy link
Contributor

JMLX42 commented Nov 7, 2024

IMO related to #1051

The Swagger UI is ~75% lighter when compressed. IMHO it would be a good idea to support a compressed feature in utoipa-swagger-ui.

If that's ok with you @juhaku I'll open a PR for it.

@juhaku
Copy link
Owner

juhaku commented Nov 7, 2024

@JMLX42 Yeah, it is okay for me. I guess it would be good to have it behind compressed feature flag which can be enabled by default but alternatively disabled if one choose to do so for some reason.

@JMLX42
Copy link
Contributor

JMLX42 commented Nov 8, 2024

It turns out:

  • rust-embed needs a relative path when building with the compression feature
  • it's rather difficult - maybe impossible - to get that relative path right

@JMLX42
Copy link
Contributor

JMLX42 commented Nov 8, 2024

it's rather difficult - maybe impossible - to get that relative path right

rust-embed expects the path to be relative to the location of the utoipa-swagger-ui crate itself. Which - IMO - does not make sense.

So for my test I set utoipa-swagger-ui.path in Cargo.toml:

utoipa-swagger-ui = { path = "../../../../../github.com/JMLX42/utoipa/utoipa-swagger-ui", version = "8.0.1", optional = true, features = [
    "actix-web",
    "vendored",
    "compressed",
] }
error: #[derive(RustEmbed)] folder '/home/jmlx/Projects/github.com/JMLX42/utoipa/utoipa-swagger-ui/./swagger-ui-5.17.14/dist/' does not exist. cwd: '/home/jmlx/Projects/github.com/JMLX42/utoipa/utoipa-swagger-ui'
 --> /home/jmlx/Projects/path/to/my/project/target/debug/build/utoipa-swagger-ui-0e79372353f0618e/out/embed.rs:4:1
  |
4 | / #[folder = r"./swagger-ui-5.17.14/dist/"]
5 | | struct SwaggerUiDist;
  | |_____________________^

@realradical
Copy link
Contributor

realradical commented Nov 21, 2024

i am getting a similar error when building with Bazel, cargo works fine

--> bazel-out/darwin_arm64-fastbuild/bin/external/crate_index__utoipa-swagger-ui-8.0.3/bs.out_dir/embed.rs:4:1
|
4 | / #[folder = r"/private/var/tmp/bazel_jacobshao/7e2bd1580ebb9b9ceb487e72e4c28f00/sandbox/darwin-sandbox/150/execroot/main/bazel-out/darwi...
5 | | struct SwaggerUiDist;
| |
__________________^

error[E0599]: no function or associated item named get found for struct SwaggerUiDist in the current scope
--> external/crate_index__utoipa-swagger-ui-8.0.3/src/lib.rs:1358:40
|
1358 | if let Some(file) = SwaggerUiDist::get(file_path) {
| ^^^ function or associated item not found in SwaggerUiDist
|
::: bazel-out/darwin_arm64-fastbuild/bin/external/crate_index__utoipa-swagger-ui-8.0.3/_bs.out_dir/embed.rs:5:1
|
5 | struct SwaggerUiDist;
| -------------------- function or associated item get not found for this struct
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item get, perhaps you need to implement one of them:
candidate #1: Embed
candidate #2: `SliceIndex```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Futher investigation needed before other action
Projects
Status: No status
Development

No branches or pull requests

4 participants