-
Notifications
You must be signed in to change notification settings - Fork 35
/
configure
executable file
·144 lines (128 loc) · 5.21 KB
/
configure
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
#!/usr/bin/env sh
NOT_CRAN=${NOT_CRAN:-"false"}
LIBR_POLARS_BUILD=${LIBR_POLARS_BUILD:-""}
# Detect if this is on R-universe.
MY_UNIVERSE=${MY_UNIVERSE:-""}
LIBNAME="libr_polars.a"
LIBR_POLARS_DEFAULT_PATH="$(pwd)/tools/${LIBNAME}"
LIBR_POLARS_PATH=${LIBR_POLARS_PATH:-${LIBR_POLARS_DEFAULT_PATH}}
# not used on macOS
ADDITIONAL_PKG_LIBS_FLAG="-lrt"
export PATH="$PATH:$HOME/.cargo/bin"
check_cargo() {
if [ ! "$(command -v cargo)" ]; then
echo ""
echo "------------------------- [RUST NOT FOUND] -------------------------"
echo "The 'cargo' command was not found on the PATH. Please install rustc"
echo "from: https://www.rust-lang.org/tools/install"
echo ""
echo "Alternatively, you may install cargo from your OS package manager:"
echo " - Debian/Ubuntu: apt-get install cargo"
echo " - Fedora/CentOS: dnf install cargo"
echo " - macOS: brew install rustc"
echo "--------------------------------------------------------------------"
echo ""
exit 1
else
echo ""
echo "--------------------------- [RUST FOUND] ---------------------------"
cargo -V
echo ""
rustc -vV
echo "--------------------------------------------------------------------"
echo ""
fi
}
check_bin_lib() {
if [ "${NOT_CRAN}" = "true" ] && [ -z "${LIBR_POLARS_BUILD}" ]; then
LIBR_POLARS_BUILD="false"
fi
# On R-universe, we try to download the pre-built binary from GitHub releases.
if [ -n "${MY_UNIVERSE}" ] && [ -z "${LIBR_POLARS_BUILD}" ]; then
echo ""
echo "--------------------- [SETTING FOR R-UNIVERSE] ---------------------"
echo "It seems that this is on R-universe <${MY_UNIVERSE}>."
echo "Trying to download pre-built binary."
echo "--------------------------------------------------------------------"
echo ""
LIBR_POLARS_BUILD="false"
fi
if [ "${LIBR_POLARS_BUILD}" = "false" ] && [ -f "tools/lib-sums.tsv" ] && [ ! -f "${LIBR_POLARS_PATH}" ]; then
echo ""
echo "---------------- [TRY TO DOWNLOAD PRE-BUILT BINARY] ----------------"
"${R_HOME}/bin${R_ARCH_BIN}/Rscript" "tools/prep-lib.R" || echo "Failed to download pre-built binary."
echo "--------------------------------------------------------------------"
echo ""
fi
if [ "${LIBR_POLARS_BUILD}" = "false" ] && [ -f "${LIBR_POLARS_PATH}" ]; then
echo ""
echo "---------------------- [LIBRARY BINARY FOUND] ----------------------"
echo "The library was found at <${LIBR_POLARS_PATH}>. No need to build it."
echo ""
echo "Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo 'Not found')"
echo "--------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" -e "s|@ADDITIONAL_PKG_LIBS_FLAG@|${ADDITIONAL_PKG_LIBS_FLAG}|" src/Makevars.in >src/Makevars
if [ "${LIBR_POLARS_PATH}" != "${LIBR_POLARS_DEFAULT_PATH}" ]; then
echo ""
echo "------------------------ [COPYING BINARY] ------------------------"
echo "Copying <${LIBR_POLARS_PATH}> to <${LIBR_POLARS_DEFAULT_PATH}>."
mkdir -p "$(dirname "${LIBR_POLARS_DEFAULT_PATH}")"
cp "${LIBR_POLARS_PATH}" "${LIBR_POLARS_DEFAULT_PATH}" || echo "Failed to copy binary."
echo "------------------------------------------------------------------"
echo ""
fi
exit 0
elif [ "${LIBR_POLARS_BUILD}" = "false" ] && [ -f "${LIBR_POLARS_DEFAULT_PATH}" ]; then
echo ""
echo "---------------------- [LIBRARY BINARY FOUND] ----------------------"
echo "The library was not found at <${LIBR_POLARS_PATH}>,"
echo "but was found at <${LIBR_POLARS_DEFAULT_PATH}>."
echo "No need to build it."
echo ""
echo "Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo 'Not found')"
echo "--------------------------------------------------------------------"
echo ""
sed -e "s|@RUST_TARGET@||" -e "s|@ADDITIONAL_PKG_LIBS_FLAG@|${ADDITIONAL_PKG_LIBS_FLAG}|" src/Makevars.in >src/Makevars
exit 0
elif [ "${LIBR_POLARS_BUILD}" = "false" ]; then
echo ""
echo "-------------------- [LIBRARY BINARY NOT FOUND] --------------------"
echo "The library was not found at <${LIBR_POLARS_PATH}>."
echo "Falling back to building from source."
echo "--------------------------------------------------------------------"
echo ""
fi
}
check_darwin() {
if [ "$(uname)" = "Darwin" ]; then
ADDITIONAL_PKG_LIBS_FLAG=""
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]+$//')"
echo ""
echo "------------------------------ [DETECTED TARGET] ------------------------------"
echo "The target was specified as <${specified_target}> via the '--host' option."
echo "-------------------------------------------------------------------------------"
echo ""
export TARGET="${specified_target}"
;;
*) ;;
esac
shift
done
}
detect_target_option "$@"
check_darwin
check_bin_lib
check_cargo
RUST_TARGET="${TARGET:-$(rustc -vV | grep host | cut -d' ' -f2)}"
sed \
-e "s|@RUST_TARGET@|${RUST_TARGET}|" \
-e "s|@ADDITIONAL_PKG_LIBS_FLAG@|${ADDITIONAL_PKG_LIBS_FLAG}|" \
src/Makevars.in >src/Makevars
exit 0