-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcargo-musl-wrapper
More file actions
executable file
·124 lines (97 loc) · 3.53 KB
/
cargo-musl-wrapper
File metadata and controls
executable file
·124 lines (97 loc) · 3.53 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
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env sh
# This file is part of bindgen-wrapper. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/bindgen-wrapper/master/COPYRIGHT. No part of bindgen-wrapper, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2016 The developers of bindgen-wrapper. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/bindgen-wrapper/master/COPYRIGHT.
set -e
set -u
set -f
_program_path_find()
{
if [ "${_program_fattening_program_path+set}" = 'set' ]; then
printf '%s\n' "$_program_fattening_program_path"
elif [ "${0%/*}" = "$0" ]; then
# We've been invoked by the interpreter as, say, bash program
if [ -r "$0" ]; then
pwd -P
# Clutching at straws; probably run via a download, anonymous script, etc, weird execve, etc
else
printf '\n'
fi
else
# We've been invoked with a relative or absolute path (also when invoked via PATH in a shell)
_program_path_find_parentPath()
{
parentPath="${scriptPath%/*}"
if [ -z "$parentPath" ]; then
parentPath='/'
fi
cd "$parentPath" 1>/dev/null
}
# pdksh / mksh have problems with unsetting a variable that was never set...
if [ "${CDPATH+set}" = 'set' ]; then
unset CDPATH
fi
if command -v realpath 1>/dev/null 2>/dev/null; then
(
scriptPath="$(realpath "$0")"
_program_path_find_parentPath
pwd -P
)
elif command -v readlink 1>/dev/null 2>/dev/null; then
(
scriptPath="$0"
while [ -L "$scriptPath" ]
do
_program_path_find_parentPath
scriptPath="$(readlink "$scriptPath")"
done
_program_path_find_parentPath
pwd -P
)
else
# This approach will fail in corner cases where the script itself is a symlink in a path not parallel with the concrete script
(
scriptPath="$0"
_program_path_find_parentPath
pwd -P
)
fi
fi
}
cargo_musl_wrapper_fail()
{
local message="$1"
printf 'cargo-musl-wrapper:FAIL:%s\n' "$message" 1>&2
exit 1
}
cargo_musl_wrapper_ensureRequiredBinariesArePresent()
{
local reason="$1"
shift 1
local binary
local missing=false
for binary in "$@"
do
if ! command -v "$binary" 1>/dev/null 2>/dev/null; then
printf 'cargo-musl-wrapper:%s\n' "The binary '$binary' needs to be in the path" 1>&2
missing=true
fi
done
if $missing; then
cargo_musl_wrapper_fail "Please make sure that the missing binaries are installed because '$reason'"
fi
}
_cargo_musl_wrapper_prepareForMacOSX_brewInstall()
{
cargo_musl_wrapper_ensureRequiredBinariesArePresent brew
local packageName="$1"
if ! brew ls --versions "$packageName" 1>/dev/null 2>/dev/null; then
brew install "$packageName" 1>&2
fi
}
cargo_musl_wrapper_main()
{
_cargo_musl_wrapper_prepareForMacOSX_brewInstall lemonrock/musl-cross/musl-cross
cd "$(_program_path_find)"/../.. 1>/dev/null 2>/dev/null
CROSS_COMPILE=x86_64-linux-musl- cargo "$@" --target x86_64-unknown-linux-musl
}
cargo_musl_wrapper_main "$@"