Skip to content

Commit e6596a3

Browse files
authored
Allow setting CARGO_TARGET_DIR (#309)
This ended up being a little more complicated than I wanted because it allows for CARGO_TARGET_DIR to be both a relative and absolute path. It should work anywhere with bash installed.
1 parent ecb2dd1 commit e6596a3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

build.bash

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
#!/usr/bin/env bash
2-
(cd blacksmith && cargo build)
2+
set -euo pipefail
33

4-
./blacksmith/target/debug/mdbook-blacksmith "$@"
4+
TARGET=${CARGO_TARGET_DIR:-target}
5+
# https://stackoverflow.com/a/3572105
6+
realpath() {
7+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
8+
}
9+
10+
cd blacksmith
11+
cargo build
12+
BLACKSMITH="$(realpath "$TARGET/debug/mdbook-blacksmith")"
13+
cd "$OLDPWD"
14+
"$BLACKSMITH" "$@"

0 commit comments

Comments
 (0)