-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_binary
executable file
·77 lines (63 loc) · 1.9 KB
/
build_binary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# This build file will build using custom remote dependency forks unless
# specified local options are available, in which case the local is used.
# Exit immediately upon error.
set -e
# Read the local overrides for custom remote dependencies.
if [ ! -f ".env.build" ]; then
echo "Error: .env.build file not found"
exit 1
fi
set -a
source .env.build
set +a
# Set a build flag, cleared however this script exits.
function reset {
export BUILD_SCRIPT_USED=0
}
trap reset EXIT
export BUILD_SCRIPT_USED=1
# Ensure the .cargo directory exists.
mkdir -p ".cargo"
# Generate a patch file for any local overrides.
rm -f ".cargo/config.toml"
CONFIG_TOML_CONTENT=""
while IFS= read -r MAPPING; do
[ -z "$MAPPING" ] && continue
# Split the mapping into crate name, local path, and remote Git URL
IFS=';' read -ra DEP_INFO <<< "$MAPPING"
CRATE_NAME="${DEP_INFO[0]}"
LOCAL_PATH="${DEP_INFO[1]}"
REMOTE_GIT_URL="${DEP_INFO[2]}"
# The local dependency is present; use it.
if [ -d "$LOCAL_PATH" ]; then
echo "-> using local $CRATE_NAME at $LOCAL_PATH ..."
# Validate that we are working with a relative path.
if [[ "$LOCAL_PATH" = /* ]]; then
echo "Error: Absolute paths are not allowed."
exit 1
fi
if [[ "$LOCAL_PATH" = ~* ]]; then
echo "Error: Paths starting with '~' are not allowed."
exit 1
fi
# Build our dynamic patch file.
CONFIG_TOML_CONTENT+="
[patch.\"$REMOTE_GIT_URL\"]
$CRATE_NAME = { path = \"$LOCAL_PATH\" }
"
# The local dependency is not present; use the updated remote.
else
echo "-> local $CRATE_NAME not found: using updated remote ..."
cargo clean -p "$CRATE_NAME"
cargo update -p "$CRATE_NAME"
fi
done <<< "$OVERRIDES"
# Write the new patch file.
if [ -n "$CONFIG_TOML_CONTENT" ]; then
echo "$CONFIG_TOML_CONTENT" > ".cargo/config.toml"
fi
# Check the tests.
cargo build --tests
# Perform the build.
cargo build "$@"