Skip to content

Conversation

@meowtec
Copy link
Contributor

@meowtec meowtec commented Nov 22, 2023

This should fix the Error: could not load cache BUG.

If there are already generated build files in the project directory, then if you execute the command cmake path/project in $OUT_DIR/build, cmake will not generate new build files in the $OUT_DIR/build directory.

So -B . is needed. https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-B

Example:

cd /path/to/project
cmake .         
# output `Build files have been written to: /path/to/project`
cd /path/to/build && cmake /path/to/project
# we expect the build files will be generated at current dir (/path/to/build)
# but unfortunately get `Build files have been written to: /path/to/project`
cd /path/to/build && cmake /path/to/project -B .  
# output `Build files have been written to: /path/to/build`, that is right!

Infomation:

cmake --version
cmake version 3.27.7

CMake suite maintained and supported by Kitware (kitware.com/cmake).

@tgross35 tgross35 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 19, 2024
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the problem is that when you configure a probject with cmake-rs and then try to build/reconfigure via the cmake binary directly, it doesn't work?

This fix makes sense, but I think we should use an absolute path to avoid any possible problems related to the location of .. So two requested changes:

  1. Set -B right after here, so we set both the CWD and the -B flag

    cmd.arg(&self.path).current_dir(&build);

  2. A few lines up, change let build = dst.join("build"); to:

    let build_dir = dst.join("build");
    let build_dir = build_dir.canonicalize().unwrap_or_else(|| build_dir.clone);

    This is preexisting but makes sure we are avoiding relative links. (also make the var name more clear)

(sorry for the delay here, this crate doesn't have a lot of maintenance)

@tgross35
Copy link
Contributor

I wound up doing the second bit in #250, so all that's needed is for this to be updated to use build_dir rather than ..

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tgross35 tgross35 enabled auto-merge (squash) August 15, 2025 09:39
@tgross35 tgross35 merged commit b59be3b into rust-lang:master Aug 15, 2025
28 checks passed
@github-actions github-actions bot mentioned this pull request Dec 10, 2025
ChrisDenton pushed a commit that referenced this pull request Dec 12, 2025
## 🤖 New release

* `cmake`: 0.1.54 -> 0.1.55 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.1.55](v0.1.54...v0.1.55)
- 2025-12-11

### Other

- Remove the `\\?\` prefix from paths
([#259](#259))
- Add Visual Studio 2026 support
([#255](#255))
- Make sure that cmake generate build files in current dir
([#194](#194))
- Set the MSRV to 1.65 and test this in CI
- Canonicalize the build directory
- Use `eprintln` instead to print the command running next
([#191](#191))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants