-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·98 lines (79 loc) · 2.25 KB
/
build
File metadata and controls
executable file
·98 lines (79 loc) · 2.25 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
#!/usr/bin/env bash
set -e
name="git-b"
version=""
skip_linux=false
usage() {
cat <<EOF
Usage: $0 <version> [--skip-linux]
Build release binaries and tarballs for GitHub / Homebrew.
Options:
--skip-linux Skip the x86_64-unknown-linux-gnu build (no cross-linker required)
EOF
exit "${1:-0}"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-linux)
skip_linux=true
shift
;;
-h | --help)
usage 0
;;
-*)
echo "error: unknown option: $1" >&2
usage 1
;;
*)
if [[ -n "$version" ]]; then
echo "error: unexpected argument: $1" >&2
usage 1
fi
version="$1"
shift
;;
esac
done
if [[ -z "$version" ]]; then
echo "error: version required" >&2
usage 1
fi
mac_intel="x86_64-apple-darwin"
mac_silicon="aarch64-apple-darwin"
linux_intel="x86_64-unknown-linux-gnu"
mac_intel_tar="$name-v$version-$mac_intel.tar.gz"
mac_silicon_tar="$name-v$version-$mac_silicon.tar.gz"
linux_intel_tar="$name-v$version-$linux_intel.tar.gz"
package_tarball() {
local target="$1"
local tarball="$2"
local staging
staging=$(mktemp -d)
mkdir -p "$staging/share/man/man1"
cp "target/$target/release/$name" "$staging/"
cp "man/git-b.1" "$staging/share/man/man1/"
tar -czvf "$tarball" -C "$staging" .
rm -rf "$staging"
}
# Release build runs build.rs, which writes man/git-b.1
cargo build --target=$mac_intel --release
cargo build --target=$mac_silicon --release
if [[ "$skip_linux" == false ]]; then
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc \
cargo build --target=$linux_intel --release
fi
if [[ ! -f man/git-b.1 ]]; then
echo "error: man/git-b.1 not found (expected from build.rs)" >&2
exit 1
fi
package_tarball "$mac_silicon" "$mac_silicon_tar"
silicon_sha=$(shasum -a 256 "$mac_silicon_tar" | cut -d ' ' -f 1)
package_tarball "$mac_intel" "$mac_intel_tar"
intel_sha=$(shasum -a 256 "$mac_intel_tar" | cut -d ' ' -f 1)
if [[ "$skip_linux" == false ]]; then
package_tarball "$linux_intel" "$linux_intel_tar"
fi
sed -i '' -e "s|X86_64_SHA =.*|X86_64_SHA = '$intel_sha'|" Formula/git-b.rb
sed -i '' -e "s|AARCH64_SHA =.*|AARCH64_SHA = '$silicon_sha'|" Formula/git-b.rb
sed -i '' -e "s|VERSION =.*|VERSION = '$version'|" Formula/git-b.rb