https://pantsbuild.org/ logo
l

loud-coat-45270

09/07/2022, 8:30 PM
Hey all! I was wondering how to accomplish something like bazel's new_local_repository in pants -- in particular: • I have some system libraries that were built/installed without pants • I want to tell pants that they exist, so that a pants target can depend on them How would I do this in pants? Or is there an alternative way to accomplish the same thing?
h

happy-kitchen-89482

09/08/2022, 6:09 PM
@witty-crayon-22786 any ideas here?
@loud-coat-45270 are these python libraries? native system libraries?
Trying to figure out what it would mean for a target to depend on them
w

witty-crayon-22786

09/08/2022, 6:14 PM
we don’t have a facility for declaring explicit dependencies on files outside of the repo, although more of that will come soon. for now, you would essentially need to expose those system libraries to your build using environment variables, such as: https://www.pantsbuild.org/docs/reference-subprocess-environment … despite the name of that option, it is essentially only exposed to the building of 3rdparty python dependencies
that currently means though that those values will not be deeply fingerprinted, so you would want to e.g. include a version string there as well. we’re hoping to schedule some work around https://github.com/pantsbuild/pants/issues/12203 to support adding more structure to these types of variables, so that they can be deeply fingerprinted.
l

loud-coat-45270

09/08/2022, 6:41 PM
Thanks @happy-kitchen-89482 @witty-crayon-22786! What if the external files are protobuf definitions (
.proto
files)?
I was hoping to import them in another in-repo proto file (that i am building with the
protobuf_sources()
rule)
I was playing around the tutorials for custom plugins: • Following https://www.pantsbuild.org/docs/plugins-codegen, I think I have a rule that extracts the files I care about • It returns a
GeneratedSources()
with the
.proto
files I need • I have a subclass of
GenerateSourcesRequest
with
output_field = ProtobufSourceField
• If I run
pants export-codegen //:my_target
, I get the
.proto
files inside
dist/codegen
• However, I'm not exactly sure how to hook this up to my
protobuf_sources()
target. I tried passing
//:my_target
as a dependency (no effect) and as a source (threw an error)
w

witty-crayon-22786

09/08/2022, 6:52 PM
mmm. there is support for doing that via a git submodule (by marking it as a subproject_root), but as it stands, the
BUILD
files for the
protobuf_sources
would already need to live in the repo that you git-submoduled.
you shouldn’t need to create a new plugin though… what was the plugin going to be doing?
l

loud-coat-45270

09/08/2022, 6:56 PM
Can you resend the link for
subproject_root
? I think it's broken
w

witty-crayon-22786

09/08/2022, 7:07 PM
l

loud-coat-45270

09/08/2022, 7:53 PM
I think there are some quirks with this project that are going to make the submodule approach difficult
To give you some more details: • The project that produces the protos is using bazel. We have a py_library target where the proto definitions are data, and we can build a wheel that contains python source code, some c/c++ binaries, and the proto definitions • If this wheel was pure python, then I think I could just add the file to my pants repo and reference it in my
requirements.txt
? I'm just not sure how to tell pants about the non-python files, which should be extractable from the wheel (since it is just a zip file after all)
3 Views