-
Notifications
You must be signed in to change notification settings - Fork 29
/
xx-apk
executable file
·145 lines (130 loc) · 2.94 KB
/
xx-apk
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env sh
set -e
if [ -z "$XX_APK_NOLOCK" ]; then
lock="/var/lock/xx-apk"
exec 9>$lock
flock -x 9
export XX_APK_NOLOCK=1
fi
if [ -n "$XX_DEBUG_APK" ]; then
set -x
fi
unset XX_VENDOR # vendor for installing packages is always alpine
for l in $(xx-info env); do
export "${l?}"
done
if [ "${TARGETOS}" != "linux" ]; then
echo >&2 "skipping packages installation on ${XX_OS}"
exit 0
fi
# these are not supported yet
case "${TARGETARCH}" in
mips*)
echo >&2 "skipping packages installation on ${XX_ARCH}"
exit 0
;;
*) ;;
esac
setup() {
if ! xx-info is-cross; then
return
fi
done_file="/${XX_TRIPLE}/.xx-setup"
if [ -f "$done_file" ]; then
return
fi
apk_dir="/${XX_TRIPLE}/etc/apk"
mkdir -p "$apk_dir"
cp /etc/apk/repositories "$apk_dir/"
# riscv only supported in edge atm
if [ "$TARGETARCH" = "riscv64" ]; then
echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" >"$apk_dir/repositories"
echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >>"$apk_dir/repositories"
fi
mkdir "$apk_dir/keys"
mkdir "$apk_dir/protected_paths.d"
echo "$XX_PKG_ARCH" >"$apk_dir/arch"
apk add --no-cache --initdb -p "/${XX_TRIPLE}" --allow-untrusted alpine-keys
if [ -d "/etc/apk/cache" ]; then
mkdir -p "/etc/apk/cache/_$XX_PKG_ARCH"
ln -s "/etc/apk/cache/_$XX_PKG_ARCH" "$apk_dir/cache"
fi
touch "$done_file"
}
clean() {
if ! xx-info is-cross; then
return
fi
# safety first
if [ -z "${XX_TRIPLE}" ]; then
echo >&2 "invalid triple root $XX_TRIPLE"
exit 1
fi
rm -rf "/${XX_TRIPLE:?}"
}
cmd() {
setup
root="/"
if xx-info is-cross; then
root="/${XX_TRIPLE}"
fi
n=$#
iscompilerrt=
isrustlib=
for a in "$@"; do
if [ $# = $n ]; then set --; fi
case "$a" in
"xx-c-essentials")
set -- "$@" musl-dev gcc
;;
"xx-cxx-essentials")
set -- "$@" g++
;;
"compiler-rt" | "compiler-rt-static")
iscompilerrt="$a"
set -- "$@" "$a"
;;
"rust-stdlib")
set -- "$@" rust-stdlib
isrustlib=1
;;
*)
set -- "$@" "$a"
;;
esac
done
if [ "$#" != "0" ]; then
set -- "--root" "$root" "$@"
echo "+ apk " "$@"
fi
apk "$@"
if xx-info is-cross; then
if [ -z "$XX_APK_KEEP_BINARIES" ]; then
rm -rf "/${XX_TRIPLE:?}/usr/bin/*"
fi
if [ -n "$iscompilerrt" ]; then
for f in $(apk --root "$root" info -qL "$iscompilerrt" | grep 'clang_rt.'); do
ff="/${f}"
if [ ! -f "${ff}" ]; then
mkdir -p "$(dirname "${ff}")"
ln -s "/$(xx-info)/${f}" "${ff}"
fi
done
fi
# rust stdlib is accessed from the real root
if [ -n "$isrustlib" ] && [ -d "$root/usr/lib/rustlib/$(xx-info)" ]; then
ln -s "$root/usr/lib/rustlib/$(xx-info)" "/usr/lib/rustlib/$(xx-info)" || true
fi
fi
}
case "$1" in
"setup")
setup
;;
"clean")
clean
;;
*)
cmd "$@"
;;
esac