Skip to content

Commit b3dfec1

Browse files
committed
✨ feat(bifrost): add bifrost update script
1 parent 80b04a2 commit b3dfec1

1 file changed

Lines changed: 106 additions & 2 deletions

File tree

bifrost/bifrost

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,109 @@ main() {
1515
case $1 in
1616
--) shift; break;;
1717

18+
-u|--upgrade|--update)
19+
echo "bifrost: removing old binaries"
20+
21+
rm -rf "$BIFROST_PATH"
22+
23+
ensure curl -L https://raw.githubusercontent.com/Jon-Becker/heimdall-rs/main/bifrost/install | bash
24+
exit 0
25+
;;
1826
-v|--version) shift; TARGET_VERSION=$1;;
27+
-b|--bench)
28+
echo "bifrost: fetching..."
29+
30+
# remove the current heimdall installation if it exists
31+
ensure rm -f "$BIFROST_BIN_DIR/heimdall"
32+
33+
# make the build path if it doesn't exist
34+
BUILD_PATH="${BIFROST_PATH}/build"
35+
if [ ! -d $BUILD_PATH ]; then
36+
ensure mkdir -p $BUILD_PATH
37+
fi
38+
39+
# remove the source directory if it exists
40+
ensure rm -rf "$BUILD_PATH/heimdall-rs"
41+
42+
cd $BUILD_PATH
43+
44+
ensure git clone "https://github.com/Jon-Becker/heimdall-rs" > /dev/null 2>&1
45+
46+
cd "heimdall-rs"
47+
48+
ensure git fetch origin > /dev/null 2>&1
49+
50+
# if they specified a version, use that
51+
if [ -n "$TARGET_VERSION" ]; then
52+
ensure git checkout $TARGET_VERSION > /dev/null 2>&1
53+
else
54+
55+
# checkout the latest tag
56+
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
57+
ensure git checkout $tag -b latest > /dev/null 2>&1
58+
fi
59+
60+
echo "bifrost: compiling..."
61+
ensure cd $BUILD_PATH/heimdall-rs/heimdall
62+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall > /dev/null 2>&1
63+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall-config > /dev/null 2>&1
64+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall-common > /dev/null 2>&1
65+
echo "bifrost: running tests..."
66+
67+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall -- benchmark_ | grep -E "±|benchmark_([a-zA-Z_])*:" >> stdout
68+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall-config -- benchmark_ | grep -E "±|benchmark_([a-zA-Z_])*:" >> stdout
69+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall-common -- benchmark_ | grep -E "±|benchmark_([a-zA-Z_])*:" >> stdout
70+
clear
71+
echo "bifrost: benchmark results:\n"
72+
cat stdout
73+
rm stdout
74+
exit 0
75+
;;
76+
-t|--test)
77+
echo "bifrost: fetching..."
78+
79+
# remove the current heimdall installation if it exists
80+
ensure rm -f "$BIFROST_BIN_DIR/heimdall"
81+
82+
# make the build path if it doesn't exist
83+
BUILD_PATH="${BIFROST_PATH}/build"
84+
if [ ! -d $BUILD_PATH ]; then
85+
ensure mkdir -p $BUILD_PATH
86+
fi
87+
88+
# remove the source directory if it exists
89+
ensure rm -rf "$BUILD_PATH/heimdall-rs"
90+
91+
cd $BUILD_PATH
92+
93+
ensure git clone "https://github.com/Jon-Becker/heimdall-rs" > /dev/null 2>&1
94+
95+
cd "heimdall-rs"
96+
97+
ensure git fetch origin > /dev/null 2>&1
98+
99+
# if they specified a version, use that
100+
if [ -n "$TARGET_VERSION" ]; then
101+
ensure git checkout $TARGET_VERSION > /dev/null 2>&1
102+
else
103+
104+
# checkout the latest tag
105+
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
106+
ensure git checkout $tag -b latest > /dev/null 2>&1
107+
fi
108+
109+
echo "bifrost: compiling..."
110+
ensure cd $BUILD_PATH/heimdall-rs/heimdall
111+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall > /dev/null 2>&1
112+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall-config > /dev/null 2>&1
113+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo build --release --package heimdall-common > /dev/null 2>&1
114+
echo "bifrost: running tests..."
115+
116+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall -- test_ --nocapture
117+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall-config -- test_ --nocapture
118+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true cargo test --release --package heimdall-common -- test_ --nocapture
119+
exit 0
120+
;;
19121
-h|--help)
20122
usage
21123
exit 0
@@ -67,7 +169,7 @@ main() {
67169
fi
68170

69171
# build the binaries
70-
RUSTFLAGS="-C target-cpu=native" ensure cargo install --path ./heimdall --bins --locked --force --root $BIFROST_PATH
172+
RUSTFLAGS="-C target-cpu=native" CARGO_PROFILE_RELEASE_LTO=true ensure cargo install --path ./heimdall --bins --locked --force --root $BIFROST_PATH
71173

72174
echo "bifrost: Installation complete."
73175
}
@@ -97,9 +199,11 @@ USAGE:
97199
98200
OPTIONS:
99201
-h, --help Print help information
202+
-u, --update Update bifrost to the latest version
100203
-v, --version Install a specific version
101204
-l, --list List all available versions
102-
205+
-b, --bench Install and run benchmarks
206+
-t, --test Install and run tests
103207
104208
EOF
105209
}

0 commit comments

Comments
 (0)