Skip to content

Commit

Permalink
rust build support: Find Cargo.lock file upwards in tree
Browse files Browse the repository at this point in the history
Cargo, the build tool for the rust ecosystem, provides a feature named
"workspaces". In workspaces, multiple library- and binary-crates can be
bundled together in one repository/project.

The workspace functionality also provides functionality where
dependencies are built once for several crates in the workspace. Thus
the "Cargo.lock" file (as well as the ./target folder where the final
binary lives) are placed in the top-level directory of the repository,
while the `cargo build` command may be called somewhere in the working
tree.

Because of this we need to make sure that we find the `Cargo.lock` file
by not only searching the current directory but also the directories
above the `${sourceRoot}`.

This change introduces a little helper to walk up the file tree and
check for a file, starting with the current directory.
  • Loading branch information
matthiasbeyer committed Oct 14, 2017
1 parent 7c45662 commit 06279b4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkgs/build-support/rust/fetch-cargo-deps
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ EOF
export CARGO_HOME=$out
cd $src

if [[ ! -f Cargo.lock ]]; then
find_upwards() {
[[ "$(realpath "$1")" == "/" ]] && return 1
if [ -f "$1/$2" ]; then
echo "$1/$2"
else
find_upwards "../$1" "$2"
fi
}

cargo_lock=$(find_upwards . "Cargo.lock")

if [[ -z "$cargo_lock" ]]; then
echo
echo "ERROR: The Cargo.lock file doesn't exist"
echo
Expand Down

0 comments on commit 06279b4

Please sign in to comment.