vv9k / podman-api-rs

Rust interface to Podman (libpod).
MIT License
84 stars 12 forks source link

Macro errors while using podman-api crate in Bazel with rules_rust #156

Open all2jeff opened 1 year ago

all2jeff commented 1 year ago

I've been trying to use the podman-api crate in a Bazel workspace by using rules_rust but lots of building errors occurred by just importing it. I have created a repo to recreate the problem in a vscode dev container.

The errors seem to be related to how variables are been captured for formatting within macros like impl_opts_builder and impl_opts_required_builder. For example:

error: there is no argument named `params`
  --> external/crate_index__podman-api-0.10.0/src/opts/containers.rs:11:1
   |
11 | / impl_opts_builder!(url =>
12 | |     /// Adjust the list of returned containers with this options.
13 | |     ContainerList
14 | | );
   | |_^
   |
   = note: did you intend to capture a variable `params` from the surrounding scope?
   = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
   = note: this error originates in the macro `$crate::impl_url_serialize` which comes from the expansion of the macro `impl_opts_builder` (in Nightly builds, run with -Z macro-backtrace for more info)
error: there is no argument named `params`
  --> external/crate_index__podman-api-0.10.0/src/opts/images.rs:11:1
   |
11 | / impl_opts_required_builder!(url =>
12 | |     /// Adjust how an image is built.
13 | |     ImageBuild,
14 | |     ///
...  |
17 | |     path => "path"
18 | | );
   | |_^
   |
   = note: did you intend to capture a variable `params` from the surrounding scope?
   = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
   = note: this error originates in the macro `$crate::impl_url_serialize` which comes from the expansion of the macro `impl_opts_required_builder` (in Nightly builds, run with -Z macro-backtrace for more info)

Do you guys happen to know anything about what is going wrong here?

vv9k commented 1 year ago

Sorry for late response, I had very little time recently.

I've looked into the issue but I'm unsure how to test if the fix works as I'm not entirely sure how to specify the dependency by git commit (it's seems to be impossible with bazel). I'm not really accustomed with bazel so the test will probably have to wait until next version of podman-api is released.

EDIT: The changes were made in containers-api crate here

all2jeff commented 1 year ago

Thank you for your fix @vv9k! As you said, there seems to be no direct way to overwrite the dependency of a dependency from bazel rules. However, I managed to find a way to do it. And I'm happy to see that your fix worked. :)

Meanwhile, I'm looking forward to the next release for both crates 😃