Greetings, I am working on a plugin to create Rust...
# general
d
Greetings, I am working on a plugin to create Rust extensions for Python. I am running into the following error when I try to run
./pants test ::
Copy code
10:24:19.53 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at <https://github.com/pantsbuild/pants/issues>.
10:24:19.53 [INFO] Filesystem changed during run: retrying `@rule(pants.backend.python.goals.pytest_runner.run_python_test)` in 500ms...
10:24:20.04 [ERROR] panic at 'called `Result::unwrap()` on an `Err` value: "Field `argv` was not convertible to type alloc::vec::Vec<alloc::string::String>: PyErr { ptype: <class \'TypeError\'>, pvalue: Some(\'Expected type that converts to PyString but received BinaryPath\'), ptraceback: None }"', src/nodes.rs:305
w
the panic is not great, but the error message shows what went wrong:
Copy code
Field `argv` was not convertible to type: Expected type that converts to PyString but received BinaryPath
in one of the types that you are constructing, you’re passing a
BinaryPath
to something that expects a
String
…the
argv
argument in fact
awesome to hear that you’re working on a plugin! let us know if you have any other questions
👍 2
d
Thanks, I was able to resolve that problem. I am using
Get(Process...
to build using cargo. I specified
Cargo.toml
as a target source, but I'm getting
Copy code
stderr:
Copy code
error: could not find `Cargo.toml` in `/tmp/process-executionIVcwpV` or any parent directory`
w
and you captured
Cargo.toml
in the
input_digest
to the
Process
?
if you haven’t seen it already, https://www.pantsbuild.org/docs/rules-api-process#process explains the sandboxing a bit
but all inputs to processes need to be captured using the filesystem APIs: https://www.pantsbuild.org/docs/rules-api-file-system
d
Ah, okay. I'll give that a try
c
Is there a way to get additional binaries available in PATH during execution? For the Rust plugin, Cargo depends on
cc
w
there is, yea. apologies: i’ll expand the docs in this area.
c
nvm we just added
env
to the
Process
used a
BinaryPath
to find the binary we needed, then added
env={'PATH': cc.first_path.path}
w
when creating a
Process
, you can set its `env`: but to actually get the environment (which is filtered out to encourage sandboxing), you need to request it via the engine, so that when the environment changes, the the relevant
@rules
are invalidated
ah, ok. yea, that’s even better!
c
yeah, I figured that would be better 🙂
it would be really nice to have a plugin example for compiling code
1
f
the experimental Go plugin probably does not make a good example but it does (poorly) demonstrate how to compile first-party Go code
it downloads the Go toolchain as an external tool accessed via a
Digest
and brings it into the input root when needed
c
cool, where's that available?
@witty-crayon-22786 is there docs for pulling in subsets of the environment? We may end up needing
LD_LIBRARY_PATH
and other C magic paths
w
yep, sorry: started writing that. will get a draft done in a second.
i just added this section to explain the types: https://www.pantsbuild.org/docs/rules-api-process#environment-variables … i’m about to add some examples
ok, just updated that link with examples: can refresh the page
c
is there a way to rename a file within a
Digest
?
ok I think we figured that out, get the DigestContents of the file, then create a new Digest with FileContents
w
eh, yea… that will work. sorry, that’s awkward. you can also invoke
bash
to do it. but it’s a gap in https://www.pantsbuild.org/docs/rules-api-file-system that renaming files it hard.
f
cool, where’s that available?
it is in the source tree already. https://github.com/pantsbuild/pants/tree/main/src/python/pants/backend/go
the in-progress experimental java support may also be of use (but is still in active development): https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/java/compile/javac.py