Include a pex_binary into a pex_binary #21366
mvgijssel
started this conversation in
Tips and Tricks
Replies: 1 comment
-
Thanks for writing this up @mvgijssel ! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes you need to include a
pex_binary
into apex_binary
. For example a client pex binary which starts a docker container with a server pex binary. Or maybe you want to link an archive into thepex_binary
for uploading. Including something built by Pants into another target can sometimes be handy!Unfortunately you can't use the
dependencies
argument directly like:Currently the
dependencies
argument forpex_binary
only supports Python/resource types. Because the output of:server
is not a Python/resource file, the output files of this target will be filtered out quietly.For this to work, it's required that the
:server
target is exposed as a resource. This is possible with the experimental_wrap_as_resources rule! And becauseexperimental_wrap_as_resources
currently only supports files as an input,:server
first needs to be converted to a file somehow. This can be achieved with theadhoc_tool
or theshell_command
rule.A
shell_command
target can be implemented like this:It's basically a noop by executing
exit 0
, but the result is is that theserver.pex
from the:server
target is now converted into a file! This file can be wrapped with theexperimental_wrap_as_resources
rule:And now we have our
:server
target exposed as a resource called:server-resource
! This can be included in a pex_binary using thedependencies
argument:Now when running
pants run //:client
the:server
target will be built and injected into the:client
target 🎉 .An example macro glueing this all together:
This macro can be used in a
BUILD
file as followsReferences
Beta Was this translation helpful? Give feedback.
All reactions