-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·193 lines (169 loc) · 5.84 KB
/
configure
File metadata and controls
executable file
·193 lines (169 loc) · 5.84 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
export PATH="$PATH:$HOME/.cargo/bin"
NOT_CRAN=${NOT_CRAN:-"false"}
LIBPRQLR_BUILD=${LIBPRQLR_BUILD:-""}
# Detect if this is on R-universe.
MY_UNIVERSE=${MY_UNIVERSE:-""}
LIBNAME="libprqlr.a"
LIBPRQLR_DEFAULT_PATH="$(pwd)/tools/${LIBNAME}"
LIBPRQLR_PATH=${LIBPRQLR_PATH:-${LIBPRQLR_DEFAULT_PATH}}
check_cargo() {
if [ ! "$(command -v cargo)" ]; then
cat <<EOF
------------------------- [RUST NOT FOUND] -------------------------
The 'cargo' command was not found on the PATH. Please install rustc
from: https://www.rust-lang.org/tools/install
Alternatively, you may install cargo from your OS package manager:
- Debian/Ubuntu: apt-get install cargo
- Fedora/CentOS: dnf install cargo
- macOS: brew install rustc
--------------------------------------------------------------------
EOF
exit 1
else
cat <<EOF
--------------------------- [RUST FOUND] ---------------------------
$(cargo -V)
$(rustc -vV)
--------------------------------------------------------------------
EOF
fi
}
check_rustup() {
if [ "$(command -v rustup)" ]; then
cat <<EOF
-------------------------- [RUSTUP FOUND] --------------------------
$(rustup show)
--------------------------------------------------------------------
EOF
else
cat <<EOF
------------------------ [RUSTUP NOT FOUND] ------------------------
The 'rustup' command was not found on the PATH.
--------------------------------------------------------------------
EOF
fi
}
check_emscripten() {
if [ "$(uname)" = "Emscripten" ]; then
export TARGET="wasm32-unknown-emscripten"
fi
}
check_bin_lib() {
if [ "${NOT_CRAN}" = "true" ] && [ -z "${LIBPRQLR_BUILD}" ]; then
LIBPRQLR_BUILD="false"
fi
# On R-universe, we try to download the pre-built binary from GitHub releases.
if [ -n "${MY_UNIVERSE}" ] && [ -z "${LIBPRQLR_BUILD}" ]; then
cat <<EOF
--------------------- [SETTING FOR R-UNIVERSE] ---------------------
It seems that this is on R-universe <${MY_UNIVERSE}>.
Trying to download pre-built binary.
--------------------------------------------------------------------
EOF
LIBPRQLR_BUILD="false"
fi
if [ "${LIBPRQLR_BUILD}" = "false" ]; then
if [ -f "tools/lib-sums.tsv" ] && [ ! -f "${LIBPRQLR_PATH}" ]; then
cat <<EOF
---------------- [TRY TO DOWNLOAD PRE-BUILT BINARY] ----------------
The library was not found at <${LIBPRQLR_PATH}>.
Trying to download pre-built binary from the Internet...
--------------------------------------------------------------------
EOF
"${R_HOME}/bin${R_ARCH_BIN}/Rscript" "tools/prep-lib.R" && echo "Done!" ||
echo "Failed to download pre-built binary."
fi
if [ -f "${LIBPRQLR_PATH}" ] && [ "${LIBPRQLR_PATH}" != "${LIBPRQLR_DEFAULT_PATH}" ]; then
cat <<EOF
------------------------- [COPYING BINARY] -------------------------
Copying <${LIBPRQLR_PATH}> to <${LIBPRQLR_DEFAULT_PATH}>.
--------------------------------------------------------------------
EOF
mkdir -p "$(dirname "${LIBPRQLR_DEFAULT_PATH}")"
cp "${LIBPRQLR_PATH}" "${LIBPRQLR_DEFAULT_PATH}" && echo "Done!" || echo "Failed to copy binary."
fi
if [ -f "${LIBPRQLR_DEFAULT_PATH}" ]; then
cat <<EOF
---------------------- [LIBRARY BINARY FOUND] ----------------------
The library was found at <${LIBPRQLR_DEFAULT_PATH}>. No need to build it.
Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo "Not found")
--------------------------------------------------------------------
EOF
export TARGET=""
generate_makevars
fi
cat <<EOF
-------------------- [LIBRARY BINARY NOT FOUND] --------------------
The library was not found at <${LIBPRQLR_PATH}>.
Falling back to building from source.
--------------------------------------------------------------------
EOF
fi
}
detect_target_option() {
for option in "$@"; do
case "${option}" in
--host=*)
specified_target="$(echo "${option}" | sed -e 's/--host=//' | sed -E 's/([0-9]+\.)*[0-9]+$//')"
cat <<EOF
------------------------ [DETECTED TARGET] ------------------------
The target was specified as <${specified_target}> via the '--host' option.
-------------------------------------------------------------------
EOF
export TARGET="${specified_target}"
;;
*) ;;
esac
shift
done
}
check_msrv() {
rustc_version="$(rustc -V | grep -o '[0-9]\+\(\.[0-9]\+\)\+')"
package_rust_version="$(
cargo metadata --manifest-path src/rust/Cargo.toml --no-deps --format-version 1 |
grep -o '"rust_version"\s*:\s*"[0-9]\+\(\.[0-9]\+\)\+"' |
grep -o '[0-9]\+\(\.[0-9]\+\)\+'
)"
lower_version="$(echo "${rustc_version} ${package_rust_version}" | tr ' ' '\n' | sort -V | head -n1)"
if [ "${rustc_version}" != "${package_rust_version}" ] && [ "${rustc_version}" = "${lower_version}" ]; then
cat <<EOF
------------------- [NOT SUPPORTED RUST VERSION] -------------------
The MSRV of this package is '${package_rust_version}',
so this installation may fail with the current rustc version '${rustc_version}'.
If this happens, please install the newer version of rustc
from: https://www.rust-lang.org/tools/install
--------------------------------------------------------------------
EOF
else
cat <<EOF
----------------- [MINIMUM SUPPORTED RUST VERSION] -----------------
The MSRV of this package is '${package_rust_version}'.
--------------------------------------------------------------------
EOF
fi
}
generate_makevars() {
for suffix in "" ".win"; do
makefile="src/Makevars${suffix}"
sed \
-e "s|@TARGET@|${TARGET}|" \
-e "s|@PROFILE@|${PROFILE}|" \
"$makefile.in" >"$makefile"
done
exit 0
}
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
if [ "${DEBUG}" = "true" ]; then
PROFILE=dev
else
PROFILE=release
fi
detect_target_option "$@"
check_bin_lib
check_rustup
check_cargo
check_msrv
check_emscripten
TARGET="${TARGET:-$(rustc -vV | grep host | cut -d' ' -f2)}"
generate_makevars