Skip to content

Commit

Permalink
feat(bifrost): add nightly build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 30, 2023
1 parent e2ade15 commit e54fb30
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
45 changes: 42 additions & 3 deletions bifrost/bifrost
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ main() {
ensure curl -L https://raw.githubusercontent.com/Jon-Becker/heimdall-rs/main/bifrost/install | bash
exit 0
;;
-v|--version) shift; TARGET_VERSION=$1 ;;
-v|--version) shift;
TARGET_VERSION=$1
shift
;;
-B|--binary|--bin) shift; USE_BINARY=true ;;
+nightly) shift; NIGHTLY_CHANNEL=true ;;
-h|--help)
Expand Down Expand Up @@ -66,8 +69,21 @@ main() {
cd "heimdall-rs"
ensure git fetch origin

# if we are nightly, use `main` branch
if [ -n "$NIGHTLY_CHANNEL" ]; then
ensure git checkout main > /dev/null 2>&1

# get the latest short commit hash
TARGET_VERSION=$(git rev-parse --short HEAD)

# get the latest tag
tag=$(git describe --tags `git rev-list --tags --max-count=1`)

# build nightly version
nightly_version="$tag+nightly.$TARGET_VERSION"
echo "bifrost: installing version $nightly_version."
# if they specified a version, checkout that tag or branch
if [ -n "$TARGET_VERSION" ]; then
elif [ -n "$TARGET_VERSION" ]; then
echo "bifrost: installing version $TARGET_VERSION."

ensure git checkout $TARGET_VERSION > /dev/null 2>&1
Expand All @@ -84,6 +100,12 @@ main() {

# if the user wants to use the precompiled binary, download it
if [ -n "$USE_BINARY" ]; then
# nightly binaries are not available
if [ -n "$NIGHTLY_CHANNEL" ]; then
echo "bifrost: nightly binaries are not available."
exit 1
fi

# cd into the binary directory
ensure cd $BIFROST_BIN_DIR
echo "bifrost: fetching binary."
Expand All @@ -109,6 +131,13 @@ main() {
# remove periods from version and cast as int
VERSION=$(echo $VERSION | sed -E 's/\.//g')

# if nightly, we need to update cargo.toml versions (hacky lol)
if [ -n "$NIGHTLY_CHANNEL" ]; then
find . -name 'Cargo.toml' -type f | while read -r file; do
set_version "$file" "$nightly_version"
done
fi

# if VERSION > 0.6.0 (60), use the new build system
if [ $VERSION -ge 60 ]; then
RUSTFLAGS="-C target-cpu=native -C codegen-units=1" CARGO_PROFILE_RELEASE_LTO=true ensure cargo install --path ./cli --bins --locked --force --root $BIFROST_PATH
Expand Down Expand Up @@ -155,7 +184,7 @@ Bifrost is the version manager for Heimdall.
Install and manage specific versions of Heimdall and it's packages.
USAGE:
bifrost <OPTIONS>
bifrost [FLAGS] <OPTIONS>
OPTIONS:
-h, --help Print help information
Expand All @@ -164,6 +193,9 @@ OPTIONS:
-v, --version Install a specific version
-l, --list List all available versions
FLAGS:
+nightly Install the latest nightly build
EOF
}

Expand All @@ -185,5 +217,12 @@ requires_cmd() {
fi
}

# set the version of $1 to $2
set_version() {
local file=$1
local version=$2
sed -i "" "s/^version.*/version = \"${version}\"/" $file
}

# run main
main "$@" || exit 1
4 changes: 4 additions & 0 deletions common/src/utils/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub struct Version {
pub fn current_version() -> Version {
// get the current version from the cargo package
let version_string = env!("CARGO_PKG_VERSION");

// remove +<channel>... from the version string
let version_string = version_string.split('+').collect::<Vec<&str>>()[0];

let version_parts: Vec<&str> = version_string.split('.').collect();

Version {
Expand Down

0 comments on commit e54fb30

Please sign in to comment.