-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathxx-cargo
executable file
·110 lines (95 loc) · 2.69 KB
/
xx-cargo
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
#!/usr/bin/env sh
set -e
execSilent() {
if ! cmdout=$("$@" 2>&1); then
echo "$cmdout" >&2
exit 1
fi
}
if [ -z "$XX_CARGO_NOLOCK" ]; then
# readlink -f in ash can not resolve symlinks from deep workdir
cd / >/dev/null
if [ -L /var/lock ] && [ ! -e "$(readlink -f /var/lock)" ]; then
mkdir -p "$(readlink -f /var/lock)"
elif [ ! -d /var/lock ]; then
mkdir -p /var/lock
fi
cd - >/dev/null
lock="/var/lock/xx-cargo"
exec 9>$lock
flock -x 9
export XX_CARGO_NOLOCK=1
fi
if [ -n "$XX_DEBUG_CARGO" ]; then
set -x
fi
setuponly=
printtarget=
n=$#
for a in "$@"; do
if [ $# = $n ]; then set --; fi
case "$a" in
"--setup-target-triple")
setuponly=1
;;
"--print-target-triple")
printtarget=1
;;
*)
set -- "$@" "$a"
;;
esac
done
done_file="/.xx-cargo.$(xx-info arch)"
if [ -z "$RISCV64_TARGET_ARCH" ]; then
export RISCV64_TARGET_ARCH=riscv64gc
fi
if [ -z "$ARM_TARGET_ARCH" ]; then
export ARM_TARGET_ARCH=armv7
fi
rustup=
if which rustup >/dev/null 2>&1; then
rustup=1
fi
vendor=$XX_VENDOR
if [ -n "$rustup" ] || [ ! -f /etc/alpine-release ]; then
export XX_VENDOR="unknown"
fi
if [ ! -f "$done_file" ]; then
xx-clang --setup-target-triple
if [ ! -d "$(rustc --print sysroot)/lib/rustlib/$(xx-info)" ]; then
if [ -n "$rustup" ]; then
execSilent rustup target add "$(xx-info)"
elif [ -f /etc/alpine-release ]; then
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apk add rust-stdlib
else
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apt-get install -y libstd-rust-dev
fi
fi
touch "$done_file"
fi
export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=$(xx-info)-clang"
if [ -n "$XX_RUSTFLAGS" ]; then
export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUSTFLAGS=$XX_RUSTFLAGS"
fi
export "CC_$(xx-info | tr - _)=$(xx-info)-clang"
if which "qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)" >/dev/null 2>&1; then
export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUNNER=qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)"
if [ -f /etc/alpine-release ]; then
export "QEMU_LD_PREFIX=/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info)/"
else
export "QEMU_LD_PREFIX=/lib/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' XX_VENDOR='' xx-info)/"
fi
fi
if command -v "$(xx-info)-pkg-config" >/dev/null 2>/dev/null; then
export "PKG_CONFIG=$(xx-info)-pkg-config"
fi
if [ -n "$printtarget" ]; then
xx-info
exit 0
fi
if [ -z "$setuponly" ]; then
exec cargo "$@" --target="$(xx-info)"
fi