rules_ruby icon indicating copy to clipboard operation
rules_ruby copied to clipboard

Use `genrule` output directory as `srcs` for `ruby_library`

Open shs96c opened this issue 5 years ago • 6 comments

When using a genrule to generate ruby sources, it's helpful to output a directory and then use that for the sources of a ruby_library

For example:

genrule(
  name = "gen-src-dir",
  outs = ["some-directory"],
  cmd = "mkdir -p $@ && touch $@/foo.rb $@/bar.rb"
)

ruby_library(
  name = "my-lib",
  srcs = [":gen-src-dir"],
)

Note that because these are generated files, it's hard to know what prefix to place in the include attribute, so ideally, that would allow itself to be relative to the output directory the genrule created.

shs96c avatar Oct 01 '20 23:10 shs96c

Can you elaborate on why you'd want to use the output of a genrule as a ruby library? What's the use case here?

kigster avatar Nov 12 '20 21:11 kigster

In the Selenium project, we generate support classes for handling the Chrome Debugging Protocol by transforming “pdl” files to ruby (and, indeed, other languages) Although we’ve not migrated the ruby build to bazel yet, our hand-rolled build system looks similar:

https://github.com/SeleniumHQ/selenium/blob/trunk/rb/build.desc#L336 is depended on by https://github.com/SeleniumHQ/selenium/blob/trunk/rb/build.desc#L291

In the more general case, this is useful for any time a code generator could be hooked into the build (think protobuf, APIs generated by OpenSwagger, parsers generated with Rangel, etc)

On 12 Nov 2020, at 21:01, Konstantin Gredeskoul [email protected] wrote:

 Can you elaborate on why you'd want to use the output of a genrule as a ruby library? What's the use case here?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

shs96c avatar Nov 13 '20 07:11 shs96c

Is there any more information I could add to this to help explain the use case better?

shs96c avatar Mar 02 '21 15:03 shs96c

I would ask this question on the Bazel/Ruby Slack channel: https://bazelbuild.slack.com/archives/CN4HMSK9Q

kigster avatar Mar 03 '21 02:03 kigster

I wonder if you can generate a Ruby library from those files, and then use that as a dependency?

kigster avatar Mar 03 '21 02:03 kigster

That's exactly what I'm trying to do :)

shs96c avatar Apr 11 '21 12:04 shs96c