Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: cmake clean issue (lib.rs.cc not found after cleaning the build directory) #2

Merged
merged 2 commits into from Jan 16, 2023

Conversation

pedrolcl
Copy link
Contributor

@pedrolcl pedrolcl commented Jan 6, 2023

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:

cd cpp-with-rust
cmake -S . -B build
# (configuration succeeds)
cmake --build build/
# (build succeeds)
cmake --build build/ --target clean
# (clean removes two files)
cmake --build build/
# (build fails!)

Another available workaround is running cargo clean before building. It fully removes the target/ directory.

The problem is that the cmake clean target removes the OUTPUT files generated by add_custom_command(), but cargo doesn't know how to regenerate them when the target directory is already populated by the last cargo execution.

The COMMENT message added to add_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} to add_custom_command(), which works fine if the CMake generator is GNU Make, but fails for Ninja. The alternative is to set the ADDITIONAL_CLEAN_FILES property on the main target, which emulates the cargo clean effects.

@paandahl paandahl merged commit 6f1fe20 into paandahl:main Jan 16, 2023
@pedrolcl pedrolcl deleted the fix-clean-cmake-issue branch January 16, 2023 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not finding lib.rs.cc on macos when running cmake build
2 participants