diff --git a/.github/workflows/r_nightly.yml b/.github/workflows/r_nightly.yml index 6becf880615..a4a167ea1cd 100644 --- a/.github/workflows/r_nightly.yml +++ b/.github/workflows/r_nightly.yml @@ -179,6 +179,7 @@ jobs: prune repo/libarrow/r-libarrow-linux-x86_64-* || : prune repo/libarrow/r-libarrow-windows-x86_64-rtools40-* || : prune repo/libarrow/r-libarrow-windows-x86_64-rtools45-* || : + prune repo/libarrow/r-libarrow-windows-aarch64-rtools45-* || : - name: Update Repository Index shell: Rscript {0} run: | diff --git a/ci/scripts/r_windows_build.sh b/ci/scripts/r_windows_build.sh index ebecb7d3f33..746831257df 100755 --- a/ci/scripts/r_windows_build.sh +++ b/ci/scripts/r_windows_build.sh @@ -32,8 +32,27 @@ ARROW_HOME="$(cd "${ARROW_HOME}" && pwd)" export ARROW_HOME : "${RTOOLS_VERSION:=45}" -: "${RTOOLS_HOME:=/c/rtools${RTOOLS_VERSION}}" -TOOLCHAIN="${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix" +# x86_64 or aarch64 +: "${RTOOLS_ARCH:=x86_64}" +case "${RTOOLS_ARCH}" in + x86_64) + : "${RTOOLS_HOME:=/c/rtools${RTOOLS_VERSION}}" + LIB_SUBDIR="x64-ucrt" + ;; + aarch64) + : "${RTOOLS_HOME:=/c/rtools${RTOOLS_VERSION}-aarch64}" + LIB_SUBDIR="aarch64-ucrt" + # The aarch64 toolchain is LLVM. Without this CMake tries gcc first and + # could find one for another architecture elsewhere on PATH. + export CC="${CC:-clang}" + export CXX="${CXX:-clang++}" + ;; + *) + echo "Unknown RTOOLS_ARCH: ${RTOOLS_ARCH}" >&2 + exit 1 + ;; +esac +TOOLCHAIN="${RTOOLS_HOME}/${RTOOLS_ARCH}-w64-mingw32.static.posix" export PATH="${TOOLCHAIN}/bin:${RTOOLS_HOME}/usr/bin:${PATH}" # CMake is a native Windows program, so give it Windows-style paths @@ -44,8 +63,8 @@ INSTALL_DIR="${BUILD_DIR}/install" INSTALL_DIR_WIN="$(cygpath -am "${INSTALL_DIR}")" printenv -gcc --version -g++ --version +"${CC:-gcc}" --version +"${CXX:-g++}" --version cmake --version make --version | head -n 1 ls "${TOOLCHAIN}/lib" @@ -126,18 +145,19 @@ popd ccache --show-stats || echo "ccache not found" VERSION="$(grep Version "${ARROW_HOME}/r/DESCRIPTION" | cut -d " " -f 2)" -DST_DIR="r-libarrow-windows-x86_64-rtools${RTOOLS_VERSION}-${VERSION}" +DST_DIR="r-libarrow-windows-${RTOOLS_ARCH}-rtools${RTOOLS_VERSION}-${VERSION}" # Make the zip layout r/configure.win expects: include/ and lib/x64-ucrt/ +# (lib/aarch64-ucrt/ for aarch64) pushd "${BUILD_DIR}" rm -rf "${DST_DIR}" -mkdir -p "${DST_DIR}/lib/x64-ucrt" +mkdir -p "${DST_DIR}/lib/${LIB_SUBDIR}" cp -r install/include "${DST_DIR}/include" -cp install/lib/*.a "${DST_DIR}/lib/x64-ucrt/" +cp install/lib/*.a "${DST_DIR}/lib/${LIB_SUBDIR}/" # Rtools libraries in PKG_LIBS in r/configure.win; keep in sync for lib in z zstd lz4 bz2 crypto ssl curl; do - cp "${TOOLCHAIN}/lib/lib${lib}.a" "${DST_DIR}/lib/x64-ucrt/" + cp "${TOOLCHAIN}/lib/lib${lib}.a" "${DST_DIR}/lib/${LIB_SUBDIR}/" done # cURL's link dependencies vary by Rtools version, so read them from @@ -159,7 +179,7 @@ while read -r flag; do curl | z | zstd | ssl | crypto) ;; # already copied above *) if [ -f "${TOOLCHAIN}/lib/lib${lib}.a" ]; then - cp "${TOOLCHAIN}/lib/lib${lib}.a" "${DST_DIR}/lib/x64-ucrt/" + cp "${TOOLCHAIN}/lib/lib${lib}.a" "${DST_DIR}/lib/${LIB_SUBDIR}/" fi ;; esac @@ -175,9 +195,9 @@ case " ${CURL_LIBS} " in exit 1 ;; esac -echo "${CURL_LIBS}${CURL_SYS_LIBS}" >"${DST_DIR}/lib/x64-ucrt/libcurl.libs" -cat "${DST_DIR}/lib/x64-ucrt/libcurl.libs" -ls -la "${DST_DIR}/lib/x64-ucrt" +echo "${CURL_LIBS}${CURL_SYS_LIBS}" >"${DST_DIR}/lib/${LIB_SUBDIR}/libcurl.libs" +cat "${DST_DIR}/lib/${LIB_SUBDIR}/libcurl.libs" +ls -la "${DST_DIR}/lib/${LIB_SUBDIR}" # Create build artifact zip -r "${DST_DIR}.zip" "${DST_DIR}" diff --git a/dev/tasks/macros.jinja b/dev/tasks/macros.jinja index db775b6e262..56539094796 100644 --- a/dev/tasks/macros.jinja +++ b/dev/tasks/macros.jinja @@ -229,11 +229,11 @@ env: shell: bash run: mkdir repo {% if get_win %} - {% for rtools in ["40", "45"] %} - - name: Get windows Rtools{{ rtools }} binary + {% for binary in ["x86_64-rtools40", "x86_64-rtools45", "aarch64-rtools45"] %} + - name: Get windows {{ binary }} binary uses: actions/download-artifact@v4 with: - name: r-libarrow-windows-x86_64-rtools{{ rtools }} + name: r-libarrow-windows-{{ binary }} path: repo/libarrow {% endfor %} {% endif %} diff --git a/dev/tasks/r/github.packages.yml b/dev/tasks/r/github.packages.yml index 499ad7f0620..b73485bdd0b 100644 --- a/dev/tasks/r/github.packages.yml +++ b/dev/tasks/r/github.packages.yml @@ -171,20 +171,22 @@ jobs: {{ '${{ env.PKG_FILE }}' }}.sha512 windows-cpp: - name: C++ Binary Windows RTools {{ '${{ matrix.config.rtools }}' }} + name: C++ Binary Windows {{ '${{ matrix.config.arch }}' }} RTools {{ '${{ matrix.config.rtools }}' }} needs: source - runs-on: windows-latest + runs-on: {{ '${{ matrix.config.runs_on }}' }} strategy: fail-fast: false matrix: config: # R is not used, but setup-r picks Rtools from r-version: R 4.1 was # the last R to use Rtools40. The Rtools40 binary is for R < 4.4. - - { rtools: 40, r: "4.1", script: r_windows_build_rtools40.sh } - - { rtools: 45, r: "4.5", script: r_windows_build.sh } + # On windows-11-arm setup-r installs the aarch64 Rtools45. + - { rtools: 40, arch: x86_64, r: "4.1", script: r_windows_build_rtools40.sh, runs_on: windows-latest } + - { rtools: 45, arch: x86_64, r: "4.5", script: r_windows_build.sh, runs_on: windows-latest } + - { rtools: 45, arch: aarch64, r: "4.5", script: r_windows_build.sh, runs_on: windows-11-arm } env: - PKG_ID: r-libarrow-windows-x86_64-rtools{{ '${{ matrix.config.rtools }}' }} - PKG_FILE: r-libarrow-windows-x86_64-rtools{{ '${{ matrix.config.rtools }}' }}-{{ '${{ needs.source.outputs.pkg_version }}' }}.zip + PKG_ID: r-libarrow-windows-{{ '${{ matrix.config.arch }}' }}-rtools{{ '${{ matrix.config.rtools }}' }} + PKG_FILE: r-libarrow-windows-{{ '${{ matrix.config.arch }}' }}-rtools{{ '${{ matrix.config.rtools }}' }}-{{ '${{ needs.source.outputs.pkg_version }}' }}.zip steps: - run: git config --global core.autocrlf false {{ macros.github_checkout_arrow()|indent }} @@ -202,6 +204,7 @@ jobs: env: ARROW_HOME: "arrow" MINGW_ARCH: "ucrt64" + RTOOLS_ARCH: {{ '${{ matrix.config.arch }}' }} {{ macros.github_set_sccache_envvars()|indent(8) }} run: arrow/ci/scripts/{{ '${{ matrix.config.script }}' }} - name: Create Checksum @@ -234,6 +237,9 @@ jobs: # Tests the Rtools40 libarrow binary, which R < 4.4 downloads. The # R package built here is not uploaded. - { platform: { runs_on: 'windows-latest', name: "Windows"}, r_version: "4.3" } + # Tests the aarch64 libarrow binary. The R package built here is not + # uploaded. + - { platform: { runs_on: 'windows-11-arm', name: "Windows aarch64"}, r_version: "release" } steps: - uses: r-lib/actions/setup-r@v2 with: @@ -314,7 +320,7 @@ jobs: cat(cmd, file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE) - name: Upload binary artifact - if: matrix.r_version != '4.3' + if: matrix.r_version != '4.3' && matrix.platform.name != 'Windows aarch64' uses: actions/upload-artifact@v4 with: name: r-pkg{{ '${{ steps.build.outputs.path }}' }} diff --git a/dev/tasks/tasks.yml b/dev/tasks/tasks.yml index dc20595b5de..1eeae9f5ec8 100644 --- a/dev/tasks/tasks.yml +++ b/dev/tasks/tasks.yml @@ -243,6 +243,7 @@ tasks: artifacts: - r-libarrow-windows-x86_64-rtools40-{no_rc_r_version}\.zip - r-libarrow-windows-x86_64-rtools45-{no_rc_r_version}\.zip + - r-libarrow-windows-aarch64-rtools45-{no_rc_r_version}\.zip - r-libarrow-linux-x86_64-{no_rc_r_version}\.zip - r-libarrow-linux-arm64-{no_rc_r_version}\.zip - r-libarrow-darwin-arm64-{no_rc_r_version}\.zip diff --git a/r/configure.win b/r/configure.win index 23869ed5e4d..3cc1d0fb381 100755 --- a/r/configure.win +++ b/r/configure.win @@ -87,7 +87,13 @@ function configure_binaries() { # (GH-55165). UTF8PROC_SNAPPY_LIBS="-lutf8proc -lsnappy" RE2_LIBS="-lre2" - CURL_LIBS_FILE="${RWINLIB#../}/lib/x64-ucrt/libcurl.libs" + # The zip's lib dir is lib/x64-ucrt, or lib/aarch64-ucrt in the aarch64 zip. + # It isn't built from $(R_ARCH) because that is empty in aarch64 R. + case "$("${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e 'cat(R.version$arch)')" in + aarch64) RWINLIB_ARCH_DIR="aarch64-ucrt" ;; + *) RWINLIB_ARCH_DIR="x64-ucrt" ;; + esac + CURL_LIBS_FILE="${RWINLIB#../}/lib/${RWINLIB_ARCH_DIR}/libcurl.libs" if [ -f "${CURL_LIBS_FILE}" ]; then UTF8PROC_SNAPPY_LIBS="" RE2_LIBS="" @@ -100,11 +106,11 @@ function configure_binaries() { -DARROW_R_WITH_DATASET -DARROW_R_WITH_JSON \ -DARROW_R_WITH_S3 -DARROW_R_WITH_GCS" # -DARROW_R_WITH_AZURE 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 -L${RWINLIB}/lib/${RWINLIB_ARCH_DIR} " PKG_LIBS="$PKG_LIBS -larrow_dataset -larrow_acero -lparquet -larrow_compute -larrow_s3 \ -larrow_gcs \$(if \$(wildcard \ ${RWINLIB}/lib\$(subst gcc,,\$(COMPILED_BY))\$(R_ARCH)/libarrow_gcs_bundled_dependencies.a \ - ${RWINLIB}/lib\$(R_ARCH)\$(CRT)/libarrow_gcs_bundled_dependencies.a),-larrow_gcs_bundled_dependencies) -larrow \ + ${RWINLIB}/lib/${RWINLIB_ARCH_DIR}/libarrow_gcs_bundled_dependencies.a),-larrow_gcs_bundled_dependencies) -larrow \ -larrow_bundled_dependencies \ ${UTF8PROC_SNAPPY_LIBS} -lz -lzstd -llz4 -lbz2 -lole32 \ ${MIMALLOC_LIBS} ${OPENSSL_LIBS} ${RE2_LIBS} ${AWS_LIBS} ${GCS_LIBS}" # ${AZURE_LIBS} diff --git a/r/tools/nixlibs.R b/r/tools/nixlibs.R index 9c217d5839a..e7692c86279 100644 --- a/r/tools/nixlibs.R +++ b/r/tools/nixlibs.R @@ -200,14 +200,20 @@ download_binary <- function(lib) { # * "darwin-x86_64" # These string values, along with `NULL`, are the potential return values of # this function. On Windows, LIBARROW_BINARY is ignored and the binary is -# chosen by R version: "windows-x86_64-rtools40" or "windows-x86_64-rtools45". +# chosen by architecture and R version: "windows-aarch64-rtools45", +# "windows-x86_64-rtools40" or "windows-x86_64-rtools45". identify_binary <- function( lib = Sys.getenv("LIBARROW_BINARY"), info = distro(), - r_version = getRversion() + r_version = getRversion(), + # The architecture R was built for, as in configure.win, not the machine's + arch = tolower(R.version$arch) ) { if (on_windows) { if (VERSION_22_OR_LATER) { + if (normalise_arch(arch) == "arm64") { + return("windows-aarch64-rtools45") + } # The binary built with Rtools45 can't be linked by Rtools43 or earlier, # which R < 4.4 uses, so those get the one built with Rtools40. if (package_version(r_version) < "4.4") { diff --git a/r/tools/test-nixlibs.R b/r/tools/test-nixlibs.R index 5de1d2015fb..472104db0e9 100644 --- a/r/tools/test-nixlibs.R +++ b/r/tools/test-nixlibs.R @@ -496,3 +496,25 @@ test_that("identify_binary() picks the Windows binary by R version", { expect_identical(identify_binary(r_version = "4.4.0"), "windows-x86_64-rtools45") expect_identical(identify_binary(r_version = "4.6.0"), "windows-x86_64-rtools45") }) + +test_that("identify_binary() picks the Windows binary by architecture", { + local_binding("on_windows", TRUE) + local_binding("VERSION_22_OR_LATER", TRUE) + + expect_identical( + identify_binary(r_version = "4.5.3", arch = "aarch64"), + "windows-aarch64-rtools45" + ) + expect_identical( + identify_binary(r_version = "4.5.3", arch = "arm64"), + "windows-aarch64-rtools45" + ) + expect_identical( + identify_binary(r_version = "4.5.3", arch = "x86_64"), + "windows-x86_64-rtools45" + ) + expect_identical( + identify_binary(r_version = "4.3.3", arch = "x86_64"), + "windows-x86_64-rtools40" + ) +})