rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

error when building `utoipa-swagger-ui` with crate_universe

Open oconnor663 opened this issue 1 year ago • 2 comments

Here's a GitHub gist you can clone to repro the issue I'm seeing: https://gist.github.com/oconnor663/deaad1cacdcbf98e8e21f73b163827b5. The minimal MODULE.bazel file looks like this:

module(
    name = "repro",
    version = "0.1.0",
)
bazel_dep(name = "rules_rust", version = "0.55.6")
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.spec(package = "utoipa-swagger-ui", version = "8.0.3")
crate.from_specs()
use_repo(crate, "crates")

The trivial rust_binary target that depends on that crate is:

package(default_visibility = ["//visibility:public"])

load("@rules_rust//rust:defs.bzl", "rust_binary")

rust_binary(
    name = "bin",
    srcs = ["repro.rs"],
    deps = [
        "@crates//:utoipa-swagger-ui",
    ],
)

If I build that, I get this error ("folder ... does not exist"):

$ git clone https://gist.github.com/deaad1cacdcbf98e8e21f73b163827b5.git repro
...
$ cd repro
$ bazel build :bin
INFO: Analyzed target //:bin (0 packages loaded, 0 targets configured).
ERROR: /private/var/tmp/_bazel_jacko/92410d0e3373f265902564b48493ac12/external/rules_rust~~crate~crates__utoipa-swagger-ui-8.0.3/BUILD.bazel:18
:13: Compiling Rust rlib utoipa_swagger_ui v8.0.3 (6 files) failed: (Exit 1): process_wrapper failed: error executing Rustc command (from targe
t @@rules_rust~~crate~crates__utoipa-swagger-ui-8.0.3//:utoipa_swagger_ui) bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_r
ust~/util/process_wrapper/process_wrapper --env-file ... (remaining 79 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error: #[derive(RustEmbed)] folder '/private/var/tmp/_bazel_jacko/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/127/execroot/_main/ba
zel-out/darwin_arm64-fastbuild/bin/external/rules_rust~~crate~crates__utoipa-swagger-ui-8.0.3/_bs.out_dir/swagger-ui-5.17.14/dist/' does not ex
ist. cwd: '/private/var/tmp/_bazel_jacko/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/130/execroot/_main'

(Another error follows that that's pretty clearly downstream of this file-does-not-exist problem.)

utoipa-swagger-ui isn't my crate, but I think the basic issue is that its build.rs is generating some code that embeds a path into its target/ dir. I'm guessing that plays poorly with the way Bazel/rules_rust/crate_universe compiles crates under different sandbox dirs, but I'm not really sure. Is there a way for me to specify this dependency that will build? Apologies if this isn't really a rules_rust issue.

oconnor663 avatar Dec 13 '24 19:12 oconnor663

Just cross-linking the issue to the project tracker: https://github.com/juhaku/utoipa/issues/1151

aignas avatar Apr 14 '25 06:04 aignas

In theory the line https://github.com/juhaku/utoipa/blob/2e19e9a5951a4191b3e607ee42f99bf5618c9a20/utoipa-swagger-ui/src/lib.rs#L156 should include the embed.rs file, but it is not working, I think, because the compilation command is not including it.

So the build process is as follows:

  • Upon build.rs execution, it will download the swagger assets
  • Then it will generate the embed.rs file that will point to those assets.
  • Then during building of lib.rs, rustc should parse the include statement
  • The embed.rs file (if it is where rustc expects those things to be) will be detected as a file from the same module and we will everything correctly.

I see that build.rs can use vendored paths, but I am not sure yet how to push that through to rules_rust.

aignas avatar Apr 14 '25 21:04 aignas