forked from avante-corp/avante.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
111 lines (94 loc) · 2.67 KB
/
Copy pathbuild.sh
File metadata and controls
111 lines (94 loc) · 2.67 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -e
REPO_REMOTE="${1:-origin}"
remote_url=$(git config --get remote.${REPO_REMOTE}.url 2>/dev/null || true)
if [[ "$remote_url" == *"github.com"* ]]; then
tmp="${remote_url#*github.com[:/]}"
tmp="${tmp%.git}"
REPO_OWNER="${tmp%/*}"
REPO_NAME="${tmp#*/}"
else
REPO_OWNER="yetone"
REPO_NAME="avante.nvim"
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Set the target directory to clone the artifact
TARGET_DIR="${SCRIPT_DIR}/lua"
# Get the artifact download URL based on the platform and Lua version
case "$(uname -s)" in
Linux*)
PLATFORM="linux"
CARGO_EXT="so"
LIB_EXT="so"
;;
Darwin*)
PLATFORM="darwin"
CARGO_EXT="dylib"
LIB_EXT="so"
;;
CYGWIN* | MINGW* | MSYS*)
PLATFORM="windows"
CARGO_EXT="dll"
LIB_EXT="dll"
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
# Get the architecture (x86_64 or aarch64)
case "$(uname -m)" in
x86_64)
ARCH="x86_64"
;;
aarch64)
ARCH="aarch64"
;;
arm64)
ARCH="aarch64"
;;
*)
echo "Unsupported architecture"
exit 1
;;
esac
# Set the Lua version (lua54 or luajit)
LUA_VERSION="${LUA_VERSION:-luajit}"
# Set the artifact name pattern
ARTIFACT_NAME_PATTERN="avante_lib-$PLATFORM-$ARCH-$LUA_VERSION"
test_command() {
command -v "$1" >/dev/null 2>&1
}
fetch_remote_tags() {
git ls-remote --tags "$REPO_REMOTE" | cut -f2 | sed 's|refs/tags/||' | while read -r tag; do
if ! git rev-parse "$tag" >/dev/null 2>&1; then
git fetch "$REPO_REMOTE" "refs/tags/$tag:refs/tags/$tag"
fi
done
}
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
fetch_remote_tags
latest_tag="$(git describe --tags --abbrev=0 --match "v*" || true)" # will be empty in clone repos
built_tag="$(cat "${TARGET_DIR}/.tag" 2>/dev/null || true)"
save_tag() {
echo "$latest_tag" > "${TARGET_DIR}/.tag"
}
if [[ "$latest_tag" = "$built_tag" && -n "$latest_tag" ]]; then
echo "Local build is up to date $latest_tag. No download needed."
elif [[ "$latest_tag" != "$built_tag" && -n "$latest_tag" ]]; then
echo "Local build is out of date $built_tag. Downloading latest $latest_tag."
# Get the artifact download URL
ARTIFACT_URL=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$latest_tag" | grep "browser_download_url" | cut -d '"' -f 4 | grep "$ARTIFACT_NAME_PATTERN")
mkdir -p "$TARGET_DIR"
curl -L "$ARTIFACT_URL" | tar -zxv -C "$TARGET_DIR"
save_tag
else
echo "No latest tag found. Building from source."
cargo build --release --features="$LUA_VERSION"
for f in target/release/lib*."$CARGO_EXT"; do
filename=$(basename "$f" | sed 's/^lib//' | sed "s/\.$CARGO_EXT$/.$LIB_EXT/")
cp "$f" "${TARGET_DIR}/${filename}"
done
fi