-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start preparing richer install & build experience for rama-cli
- Loading branch information
Showing
8 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#!/bin/bash | ||
|
||
: ${root=$(pwd)} | ||
: ${tag=latest} | ||
: ${os=linux} | ||
: ${name=rama} | ||
|
||
# Function to print colored text based on log level | ||
log() { | ||
local level=$1 | ||
local message=$2 | ||
local NC='\033[0m' # Reset to default color | ||
|
||
case "$level" in | ||
"info") | ||
echo -e "\033[0;32m[INFO] $message${NC}" # Green for INFO | ||
;; | ||
"warning") | ||
echo -e "\033[0;33m[WARNING] $message${NC}" # Yellow for WARNING | ||
;; | ||
"error") | ||
echo -e "\033[0;31m[ERROR] $message${NC}" # Red for ERROR | ||
;; | ||
*) | ||
echo "$message" # Default to printing message without color for other levels | ||
;; | ||
esac | ||
} | ||
|
||
[ ! -d target ] && mkdir target | ||
|
||
# Build support paltform target | ||
# 1. Linux | ||
linux_target=( | ||
"x86_64-unknown-linux-gnu:mimalloc" | ||
"aarch64-unknown-linux-gnu:mimalloc" | ||
"armv7-unknown-linux-gnueabihf:jemalloc" | ||
"arm-unknown-linux-gnueabi:jemalloc" | ||
"i686-unknown-linux-gnu:jemalloc" | ||
) | ||
|
||
# 2. MacOS | ||
macos_target=( | ||
"x86_64-apple-darwin" | ||
"aarch64-apple-darwin" | ||
) | ||
|
||
# 3. Windows | ||
windows_target=( | ||
"x86_64-pc-windows-gnu" | ||
"i686-pc-windows-gnu" | ||
) | ||
|
||
# Check linux rustup target installed | ||
check_linux_rustup_target_installed() { | ||
for target in ${linux_target[@]}; do | ||
target=$(echo $target | cut -d':' -f1) | ||
installed=$(rustup target list | grep "${target} (installed)") | ||
if [ -z "$installed" ]; then | ||
log "info" "Installing ${target}..." | ||
rustup target add ${target} | ||
fi | ||
done | ||
} | ||
|
||
# Check macos rustup target installed | ||
check_macos_rustup_target_installed() { | ||
for target in ${macos_target[@]}; do | ||
installed=$(rustup target list | grep "${target} (installed)") | ||
if [ -z "$installed" ]; then | ||
log "info" "Installing ${target}..." | ||
rustup target add ${target} | ||
fi | ||
done | ||
} | ||
|
||
# Check windows rustup target installed | ||
check_windows_rustup_target_installed() { | ||
for target in ${windows_target[@]}; do | ||
installed=$(rustup target list | grep "${target} (installed)") | ||
if [ -z "$installed" ]; then | ||
log "info" "Installing ${target}..." | ||
rustup target add ${target} | ||
fi | ||
done | ||
} | ||
|
||
# Build linux target | ||
build_linux_target() { | ||
for target in "${linux_target[@]}"; do | ||
build_target=$(echo $target | cut -d':' -f1) | ||
feature=$(echo $target | cut -d':' -f2) | ||
log "info" "Building ${target}..." | ||
if cargo zigbuild --release -p rama-cli --target "${build_target}" --features "${feature}"; then | ||
compress_and_move $build_target | ||
log "info" "Build ${target} done" | ||
else | ||
log "error" "Build ${target} failed" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Build macos target | ||
build_macos_target() { | ||
for target in "${macos_target[@]}"; do | ||
log "info" "Building ${target}..." | ||
if CARGO_PROFILE_RELEASE_STRIP=none cargo zigbuild --release -p rama-cli --target "${target}"; then | ||
compress_and_move $target | ||
log "info" "Build ${target} done" | ||
else | ||
log "error" "Build ${target} failed" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Build windows target | ||
build_windows_target() { | ||
for target in "${windows_target[@]}"; do | ||
log "info" "Building ${target}..." | ||
if cargo build --release -p rama-cli --target "${target}"; then | ||
compress_and_move $target | ||
log "info" "Build ${target} done" | ||
else | ||
log "error" "Build ${target} failed" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# upx and move target | ||
compress_and_move() { | ||
build_target=$1 | ||
target_dir="target/${build_target}/release" | ||
bin_name=$name | ||
if [[ $build_target == *windows* ]]; then | ||
bin_name="${name}.exe" | ||
fi | ||
upx "${target_dir}/${bin_name}" | ||
chmod +x "${target_dir}/${bin_name}" | ||
cd "${target_dir}" | ||
tar czvf $name-$tag-${build_target}.tar.gz $bin_name | ||
shasum -a 256 $name-$tag-${build_target}.tar.gz >$name-$tag-${build_target}.tar.gz.sha256 | ||
mv $name-$tag-${build_target}.tar.gz $root/target/ | ||
mv $name-$tag-${build_target}.tar.gz.sha256 $root/target/ | ||
cd - | ||
} | ||
|
||
# Execute | ||
if [ "$os" == "linux" ]; then | ||
log "info" "Building linux target..." | ||
check_linux_rustup_target_installed | ||
build_linux_target | ||
elif [ "$os" == "macos" ]; then | ||
log "info" "Building macos target..." | ||
check_macos_rustup_target_installed | ||
build_macos_target | ||
elif [ "$os" == "windows" ]; then | ||
log "info" "Building windows target..." | ||
check_windows_rustup_target_installed | ||
build_windows_target | ||
else | ||
log "error" "Unsupported os: ${os}" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# Fetch the latest release information | ||
tag=$(jq -r 'map(select(.prerelease)) | first | .tag_name' <<< $(curl --silent https://api.github.com/repos/plabayo/rama/releases)) | ||
version=${tag#v} | ||
|
||
# Get system architecture and OS | ||
ARCH=$(uname -m) | ||
OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
|
||
# Select the appropriate filename based on the system architecture and OS | ||
case "$ARCH-$OS" in | ||
"aarch64-darwin") FILENAME="rama-aarch64-apple-darwin.tar.gz" ;; | ||
"arm64-darwin") FILENAME="rama-aarch64-apple-darwin.tar.gz" ;; | ||
# "aarch64-linux") FILENAME="rama-aarch64-unknown-linux-musl.tar.gz" ;; | ||
# "arm-linux") FILENAME="rama-arm-unknown-linux-musleabihf.tar.gz" ;; | ||
# "armv7l-linux") FILENAME="rama-armv7-unknown-linux-musleabihf.tar.gz" ;; | ||
# "i686-windows") FILENAME="rama-i686-pc-windows-gnu.tar.gz" ;; | ||
# "i686-linux") FILENAME="rama-i686-unknown-linux-musl.tar.gz" ;; | ||
"x86_64-darwin") FILENAME="rama-x86_64-apple-darwin.tar.gz" ;; | ||
# "x86_64-windows") FILENAME="rama-x86_64-pc-windows-gnu.tar.gz" ;; | ||
# "x86_64-linux") FILENAME="rama-x86_64-unknown-linux-musl.tar.gz" ;; | ||
*) echo "Unknown system architecture: $ARCH-$OS"; exit 1 ;; | ||
esac | ||
|
||
# Construct the download URL | ||
download_url="https://github.com/plabayo/rama/releases/download/$tag/$FILENAME" | ||
|
||
echo "Download URL: $download_url" | ||
|
||
if [ -z "$download_url" ]; then | ||
echo "Could not find a suitable package for your system architecture." | ||
exit 1 | ||
fi | ||
|
||
# Download the binary package | ||
curl -L -o $FILENAME $download_url | ||
|
||
echo "Download complete: $FILENAME" | ||
|
||
# Extract the binary package | ||
tar -xzf $FILENAME | ||
rm -rf $FILENAME | ||
|
||
echo "Extraction complete: $FILENAME" | ||
|
||
# Move the extracted files to the installation path | ||
# Assuming the binary file is named `rama` | ||
sudo mv rama /usr/local/bin/rama | ||
echo "Installation complete: /usr/local/bin/rama" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters