Fix: cmake clean issue (lib.rs.cc not found after cleaning the build directory) #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1
This issue can be triggered by the
cmake clean
target after a successful build. Any other build attempt after that will trigger the reported error. It doesn't matter if the build tool is GNU Make or Ninja. For instance:Another available workaround is running
cargo clean
before building. It fully removes the target/ directory.The problem is that the
cmake clean
target removes theOUTPUT
files generated byadd_custom_command()
, but cargo doesn't know how to regenerate them when the target directory is already populated by the lastcargo
execution.The
COMMENT
message added toadd_custom_command()
proves that cmake tries to run cargo whenever the${BLOBSTORE_BRIDGE_CPP}
file is missing. The message is printed no matter if the build fails.My first attempt to fix this issue was adding
BYPRODUCTS ${CARGO_TARGET_DIR}
toadd_custom_command()
, which works fine if the CMake generator is GNU Make, but fails for Ninja. The alternative is to set theADDITIONAL_CLEAN_FILES
property on the main target, which emulates thecargo clean
effects.