Re: Specifying the location of the Cargo.lock file
⚓ Rust 📅 2025-04-25 👤 surdeus 👁️ 17Can you avoid placing Cargo.lock inside the source tree for packages that don't ship with one?
In response to the thread in Specifying the location of the Cargo.lock file I can offer a solution. Define your SOURCE_DIR and BUILD_DIR as appropriate and run the following:
mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR"
ln -s "$SOURCE_DIR" $(basename "$SOURCE_DIR")
printf "[workspace]\nmembers = [ \"%s\" ]\n" $(basename $SOURCE_DIR) > "Cargo.toml"
cargo build
The above makes the build directory into a workspace; to account for the fact that the source and build directories may not be hierarchically inside one another, we use a symlink to fool cargo into completing the build anyway.
2 posts - 2 participants
🏷️ rust_feed