File: configure.win

package info (click to toggle)
apache-arrow 23.0.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 76,220 kB
  • sloc: cpp: 654,608; python: 70,522; ruby: 45,964; ansic: 18,742; sh: 7,365; makefile: 669; javascript: 125; xml: 41
file content (331 lines) | stat: -rwxr-xr-x 12,832 bytes parent folder | download
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

: ${PKG_CONFIG:="pkg-config"}
# Library settings
PKG_CONFIG_NAME="arrow"
PKG_TEST_HEADER="<arrow/api.h>"

VERSION=`grep '^Version' DESCRIPTION | sed s/Version:\ //`

# Development mode, also increases verbosity in the bundled build
ARROW_R_DEV=`echo $ARROW_R_DEV | tr '[:upper:]' '[:lower:]'`
# If present, `pkg-config` will be used to find libarrow on the system,
# unless this is set to false
ARROW_USE_PKG_CONFIG=`echo $ARROW_USE_PKG_CONFIG | tr '[:upper:]' '[:lower:]'`

# generate code
if [ "$ARROW_R_DEV" = "true" ] && [ -f "data-raw/codegen.R" ]; then
  echo "*** Generating code with data-raw/codegen.R"
  "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" data-raw/codegen.R
fi

# Test if pkg-config is available to use
if ${PKG_CONFIG} --version >/dev/null 2>&1; then
  PKG_CONFIG_AVAILABLE="true"
  echo "*** pkg-config found."
else
  echo "*** pkg-config not found."
  PKG_CONFIG_AVAILABLE="false"
  ARROW_USE_PKG_CONFIG="false"
fi


function configure_binaries() {
  # Try to find/download a C++ Arrow binary,
  "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "tools/nixlibs.R" $VERSION
  # If binary not found, script exits nonzero
  if [ $? -ne 0 ]; then
    _LIBARROW_FOUND="false"
    echo "Arrow C++ library was not found"
    # return 0 so set -e doesn't exit the script
    return 0
  fi

  OPENSSL_LIBS="-lcrypto -lcrypt32"
  MIMALLOC_LIBS="-lbcrypt -lpsapi"
  BROTLI_LIBS="-lbrotlienc -lbrotlidec -lbrotlicommon" # Common goes last since dec and enc depend on it
  # We build aws-sdk-cpp bundled now, so the AWS libs are included in arrow_bundled_dependencies
  # but we also need to include these Windows system libraries
  AWS_LIBS="-luserenv -lversion -lws2_32 -lbcrypt -lwininet -lwinhttp -lsecur32 -lshlwapi -lncrypt"
  # pkg-config --libs libcurl
  GCS_LIBS="-lcurl -lnormaliz -lssh2 -lgdi32 -lssl -lcrypto -lcrypt32 -lwldap32 \
            -lz -lws2_32 -lnghttp2 -ldbghelp"

  # Set the right flags to point to and enable arrow/parquet
  if [ -d "windows/r-libarrow-windows-x86_64-$VERSION" ]; then
    RWINLIB="../windows/r-libarrow-windows-x86_64-$VERSION"
  else
    # It's possible that the version of the libarrow binary is not identical to the
    # R version, e.g. if the R build is a patch release, so find what the dir is
    # actually called. If there is more than one version present, use the one
    # with the highest version:
    RWINLIB="../windows/$(ls windows/ | grep ^r-libarrow- | tail -n 1)"
  fi

  # NOTE: If you make changes to the libraries below, you should also change
  # ci/scripts/r_windows_build.sh and ci/scripts/PKGBUILD
  PKG_CFLAGS="-I${RWINLIB}/include -DARROW_STATIC -DARROW_COMPUTE_STATIC -DPARQUET_STATIC \
              -DARROW_DS_STATIC -DARROW_ACERO_STATIC -DARROW_R_WITH_PARQUET \
              -DARROW_R_WITH_COMPUTE -DARROW_R_WITH_ACERO \
              -DARROW_R_WITH_DATASET -DARROW_R_WITH_JSON"
  PKG_LIBS="-L${RWINLIB}/lib"'$(subst gcc,,$(COMPILED_BY))$(R_ARCH) '
  PKG_LIBS="$PKG_LIBS -L${RWINLIB}/lib"'$(R_ARCH)$(CRT) '
  PKG_LIBS="$PKG_LIBS -larrow_dataset -larrow_acero -lparquet -larrow_compute -larrow -larrow_bundled_dependencies \
            -lutf8proc -lsnappy -lz -lzstd -llz4 -lbz2 ${BROTLI_LIBS} -lole32 \
            ${MIMALLOC_LIBS} ${OPENSSL_LIBS}"

  # S3, GCS, and re2 support only for Rtools40 (i.e. R >= 4.0)
  "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e 'R.version$major >= 4' | grep TRUE >/dev/null 2>&1
  if [ $? -eq 0 ]; then
    PKG_CFLAGS="${PKG_CFLAGS} -DARROW_R_WITH_S3 -DARROW_R_WITH_GCS"
    PKG_LIBS="${PKG_LIBS} -lre2 ${AWS_LIBS} ${GCS_LIBS}"
  else
    # It seems that order matters
    PKG_LIBS="${PKG_LIBS} -lws2_32"
  fi

}

# Once libarrow is obtained, this function sets `PKG_LIBS`, `PKG_DIRS`, and `PKG_CFLAGS`
# either from pkg-config or by inferring things about the directory in $1
set_pkg_vars () {
  set_lib_dir_with_pc

  # Check cmake options for enabled features. This uses LIB_DIR that
  # is set by the above set_lib_dir_* call.
  add_feature_flags
  set_pkg_vars_with_pc

  # Set any user-defined CXXFLAGS
  if [ "$ARROW_R_CXXFLAGS" ]; then
    PKG_CFLAGS="$PKG_CFLAGS $ARROW_R_CXXFLAGS"
  fi
}

# If we have pkg-config, it will tell us what libarrow needs
set_lib_dir_with_pc () {
  LIB_DIR="`${PKG_CONFIG} --variable=libdir  ${PKG_CONFIG_NAME}`"
}
set_pkg_vars_with_pc () {
  pkg_config_names="${PKG_CONFIG_NAME} ${PKG_CONFIG_NAMES_FEATURES}"
  PKG_CFLAGS="`${PKG_CONFIG} --cflags  ${pkg_config_names}` $PKG_CFLAGS"
  PKG_CFLAGS="$PKG_CFLAGS $PKG_CFLAGS_FEATURES"
  PKG_LIBS=`${PKG_CONFIG} --libs-only-l --libs-only-other ${pkg_config_names}`
  PKG_LIBS="$PKG_LIBS $PKG_LIBS_FEATURES"
  PKG_DIRS=`${PKG_CONFIG} --libs-only-L  ${pkg_config_names}`
}

add_feature_flags () {
  PKG_CFLAGS_FEATURES=""
  PKG_CONFIG_NAMES_FEATURES=""
  PKG_LIBS_FEATURES=""
  PKG_LIBS_FEATURES_WITHOUT_PC=""

  # Now we need to check what features it was built with and enable
  # the corresponding feature flags in the R bindings (-DARROW_R_WITH_stuff).
  # We do this by inspecting ArrowOptions.cmake, which the libarrow build
  # generates.
  ARROW_OPTS_CMAKE="$LIB_DIR/cmake/Arrow/ArrowOptions.cmake"
  if [ ! -f "${ARROW_OPTS_CMAKE}" ]; then
    echo "*** $ARROW_OPTS_CMAKE not found; some features will not be enabled"
  else
    if arrow_built_with ARROW_PARQUET; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_PARQUET"
      PKG_CONFIG_NAMES_FEATURES="$PKG_CONFIG_NAMES_FEATURES parquet"
      PKG_LIBS_FEATURES_WITHOUT_PC="-lparquet $PKG_LIBS_FEATURES_WITHOUT_PC"
      # NOTE: parquet is assumed to have the same -L flag as arrow
      # so there is no need to add its location to PKG_DIRS
    fi
   if arrow_built_with ARROW_COMPUTE; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_COMPUTE"
      PKG_CONFIG_NAMES_FEATURES="$PKG_CONFIG_NAMES_FEATURES arrow-compute"
      PKG_LIBS_FEATURES_WITHOUT_PC="-larrow_compute $PKG_LIBS_FEATURES_WITHOUT_PC"
      # NOTE: arrow_compute is assumed to have the same -L flag as arrow
      # so there is no need to add its location to PKG_DIRS
    fi
    if arrow_built_with ARROW_DATASET; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_DATASET"
      PKG_CONFIG_NAMES_FEATURES="$PKG_CONFIG_NAMES_FEATURES arrow-dataset"
      PKG_LIBS_FEATURES_WITHOUT_PC="-larrow_dataset $PKG_LIBS_FEATURES_WITHOUT_PC"
      # NOTE: arrow_dataset is assumed to have the same -L flag as arrow
      # so there is no need to add its location to PKG_DIRS
    fi
    if arrow_built_with ARROW_ACERO; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_ACERO"
      PKG_CONFIG_NAMES_FEATURES="$PKG_CONFIG_NAMES_FEATURES arrow-acero"
      PKG_LIBS_FEATURES_WITHOUT_PC="-larrow_acero $PKG_LIBS_FEATURES_WITHOUT_PC"
      # NOTE: arrow_acero is assumed to have the same -L flag as arrow
      # so there is no need to add its location to PKG_DIRS
    fi
    if arrow_built_with ARROW_SUBSTRAIT; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_SUBSTRAIT"
      PKG_CONFIG_NAMES_FEATURES="$PKG_CONFIG_NAMES_FEATURES arrow-substrait"
      PKG_LIBS_FEATURES_WITHOUT_PC="-larrow_substrait $PKG_LIBS_FEATURES_WITHOUT_PC"
      # NOTE: arrow_substrait is assumed to have the same -L flag as arrow
      # so there is no need to add its location to PKG_DIRS
    fi
    if arrow_built_with ARROW_JSON; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_JSON"
    fi
    if arrow_built_with ARROW_S3; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_S3"
    fi
    if arrow_built_with ARROW_GCS; then
      PKG_CFLAGS_FEATURES="$PKG_CFLAGS_FEATURES -DARROW_R_WITH_GCS"
    fi
    if arrow_built_with ARROW_GCS || arrow_built_with ARROW_S3; then
      # If pkg-config is available it will handle this for us automatically
      SSL_LIBS_WITHOUT_PC="-lcurl -lssl -lcrypto"
    fi
  fi
}


arrow_built_with() {
  # Function to check cmake options for features
  grep -i 'set('"$1"' "ON")' $ARROW_OPTS_CMAKE >/dev/null 2>&1
}

function configure_rtools() {
  # Use pkg-config to find arrow from rtools
  _LIBARROW_PREFIX="`${PKG_CONFIG} --variable=prefix ${PKG_CONFIG_NAME}`"
  _LIBARROW_FOUND="true"
  echo "*** Trying Arrow C++ found by pkg-config: $_LIBARROW_PREFIX"

  PC_LIB_VERSION=`${PKG_CONFIG} --modversion ${PKG_CONFIG_NAME}`
  # This is in an R script for convenience and testability.
  # Success means the found C++ library is ok to use.
  # Error means the versions don't line up and we shouldn't use it.
  # More specific messaging to the user is in the R script
  if ! ${R_HOME}/bin/Rscript tools/check-versions.R $VERSION $PC_LIB_VERSION 2> /dev/null; then
    _LIBARROW_FOUND="false"
  fi

  # We should have a valid libarrow build in $_LIBARROW_FOUND
# Now set `PKG_LIBS`, `PKG_DIRS`, and `PKG_CFLAGS` based on that.
if [ "$_LIBARROW_FOUND" == "true" ]; then
  set_pkg_vars ${_LIBARROW_PREFIX}
  # add mingw specific windows flags
  PKG_LIBS="$PKG_LIBS -lws2_32 -lole32 -lwldap32 -lsecur32 -lncrypt -lcrypt32 -lshlwapi"
  # override -fno-exceptions from aws-cpp-sdk pc file
  PKG_CFLAGS="$PKG_CFLAGS -fexceptions"
else
  # To make it easier to debug which code path was taken add a specific
  # message to the log in addition to the 'NOTE'
  echo "*** Failed to find Arrow C++ libraries in rtools"
fi
}

function configure_release() {
  if [ "$ARROW_USE_PKG_CONFIG" != "false" ] && $PKG_CONFIG --exists $PKG_CONFIG_NAME; then
    configure_rtools
  else
    configure_binaries
  fi

  if [ "$_LIBARROW_FOUND" == "false" ]; then
    echo "------------------------- NOTE ---------------------------"
    echo "There was an issue preparing the Arrow C++ libraries."
    echo "See https://arrow.apache.org/docs/r/articles/install.html"
    echo "----------------------------------------------------------"
    exit 1
  fi
}

# Returns 1 if CMAKE options is set "ON", otherwise 0
function cmake_option() {
  ARROW_OPTS_CMAKE="$ARROW_HOME/lib/cmake/Arrow/ArrowOptions.cmake"
  arrow_built_with $1
}

function configure_dev() {
  echo "*** Using locally built Arrow at $ARROW_HOME"
  RWINLIB=$(cygpath $ARROW_HOME)

  export PKG_CONFIG_PATH=$(cygpath $ARROW_HOME)/lib/pkgconfig:$(cygpath $MSYSTEM_PREFIX)/lib
  PKG_CONFIG_PACKAGES="arrow"

  PKG_CFLAGS=""

  if [ $(cmake_option ARROW_PARQUET) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_PARQUET"
    PKG_CONFIG_PACKAGES="$PKG_CONFIG_PACKAGES parquet"
  fi

  if [ $(cmake_option ARROW_COMPUTE) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_COMPUTE"
    PKG_CONFIG_PACKAGES="$PKG_CONFIG_PACKAGES arrow-compute"
  fi

  if [ $(cmake_option ARROW_ACERO) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_ACERO"
    PKG_CONFIG_PACKAGES="$PKG_CONFIG_PACKAGES arrow-acero"
  fi

  if [ $(cmake_option ARROW_DATASET) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_DATASET"
    PKG_CONFIG_PACKAGES="$PKG_CONFIG_PACKAGES arrow-dataset"
  fi

  if [ $(cmake_option ARROW_S3) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_S3"
  fi

  if [ $(cmake_option ARROW_GCS) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_GCS"
  fi

  if [ $(cmake_option ARROW_JSON) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_JSON"
  fi

  if [ $(cmake_option ARROW_SUBSTRAIT) -eq 1 ]; then
    PKG_CFLAGS="$PKG_CFLAGS -DARROW_R_WITH_SUBSTRAIT"
    PKG_CONFIG_PACKAGES="$PKG_CONFIG_PACKAGES arrow-substrait"
  fi

  PKG_CFLAGS="$(pkg-config --cflags $PKG_CONFIG_PACKAGES) $PKG_CFLAGS"
  PKG_LIBS=$(pkg-config --libs $PKG_CONFIG_PACKAGES)
}


if [ ! -z ${ARROW_HOME} ]; then
  # Build Arrow based on local build of libarrow.
  configure_dev
else
  # Build Arrow based on precompiled zip of static libraries.
  configure_release
fi


# Set any user-defined CXXFLAGS
if [ "$ARROW_R_CXXFLAGS" ]; then
  PKG_CFLAGS="$PKG_CFLAGS $ARROW_R_CXXFLAGS"
fi

echo "*** Writing $(pwd)/src/Makevars.win"
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars.win

echo "*** Contents of $(pwd)/src/Makevars.win"
cat src/Makevars.win
echo "*** /End contents"

# Success
exit 0