tonic icon indicating copy to clipboard operation
tonic copied to clipboard

out_dir configuration generally prevents compilation

Open EdmundsEcho opened this issue 3 years ago • 0 comments

Bug Report

In my exposure to the documentation, stackoverflow, github issues etc, with several of the related dependencies, some would explain-away what they observed as "some funky stuff" going on. I suspect this has to do with the fast pass of updates, outdated docs and examples, and the many layers of binaries involved. So when I saw the behavior I'm about to describe, I realized that just maybe this might help explain what seems "funky" and otherwise difficult to explain.

I had to be detailed in the retelling of the events to observe what was going on with proc, prost and the project. The moving parts are the running of the build script from within nvim, manually calling compile and otherwise using cargo watch. All play into a different outcome! aka "funky" :))

I posted here and conclude for now that it can be remedied by tonic_build b/c the /out artifacts remain constant (empty) with both proc and prost (that is expected given the configuration), in both the working and failed states. The /out for the project and where I specify it to go "off and on" with the tonic_build setting (a wrapper, so I could be wrong; but thus far my conclusion).

Version

jobstatus-tonic v0.1.0 (/Users/edmund/Programming-Local/etl/jobstatus-tonic)
└── tonic v0.7.2
└── tonic-build v0.7.2

Platform

MacOS 12.4 M1 Pro

Description

  1. Set the env $OUT_DIR=src/grpc
  2. Set the tonic_build::configure().out_dir("src/grpc")
  3. Delete project's target dir (force everything to recompile)
  4. Delete the contents of src/grpc (so, now have an empty src/grpc)
  5. run cargo build
  6. => can't read... (see below)
  7. Remove the configuration setting
  8. run cargo build
  9. fails...

Fire-up cargo watch -x 'run --bin project-server' running in the background.

  1. build.rs with .out_dir("src/grpc")
  2. clear/delete all of the compiled code (/target and src/grpc)
  3. => cant' read... (see below)
    • note: the prost, proc and project builds are present, all with empty out dir
  4. remove the .out_dir entry... save
  5. => Success!
  • the prost and proc out dirs remain empty;
  • not so for the project-tonic/out and src/grpc (they have the expected .rs artifacts)
  1. add the .out_dir entry
  2. Clear only the out dirs (project and src/grpc)
  3. => Fail
  • the src/grpc receives the artifacts, not so for project-tonic/out
  1. Remove the .out_dir entry
  2. => Success!
  3. Add the .out_dir entry
  4. => Success!
  5. Change a source file such as src/server.rs
  6. => Success!
  7. Change a proto file
  8. => Success!
    • src/grpc artifacts are updated as expected, not so for project-tonic/out

Turn off cargo watch. Compile => Fail (I kept the prior artifacts).

To clarify, when I say "success", it both compiles and "behaves" as expected (responds to a test request).

So, in the end, using the out_dir setting never results in a successful compilation. I can "work around it" using watch and toggling the use of the out_dir config.

However, that results in "unstable" behavior because it works using watch, but fails once I run compile (even incremental, not a full reset).

Finally, the ability to use OUT_DIR generally works, but is "frustrated" by setting the value using tonic_build

My nvim setup does run the build.rs on save, likely using the env $OUT_DIR setting (set in the nvim env to match).

The error (for the most part)

error: couldn't read /Users/edmund/Programming-Local/etl/project-tonic/target/debug/build/project-tonic-6f9afd54cb14f6a1/out/root.rs: No such file or directory (os error 2)
  --> src/server.rs:10:5
   |
10 |     tonic::include_proto!("root");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `project-tonic` due to previous error
[Finished running. Exit status: 101]

Let me know if there is any other information I can provide.

EdmundsEcho avatar May 31 '22 16:05 EdmundsEcho