Skip to content

Commit 4503fb0

Browse files
assignUserjonkeanekou
authored andcommitted
apacheGH-37923: [R] Move macOS build system to nixlibs.R (apache#37684)
This PR modifies the build system of the R package to no longer rely on auto/homebrew. Instead this PR adds the infrastructure and code paths to use the same type of pre-compiled libarrow binaries as we use for Linux. The main difference is the use of the binaries even on CRAN (as we previously also used binaries in form of brew bottles). The addition of the new artifacts to tasks.yml should ensure that they get uploaded to the nightly repo as well as to the artifactory during the release (@ kou please confirm). A summary of the changes in this PR: - update `r/configure` and `r/tools/nixlibs.R` to enable the source build on macOS and usage of precompiled binaries using the existing mechanism to test compile a program to detect the exisitng openssl version - added tests for the changes in nixlibs.R - update the binary allow-list - Add the build jobs for libarrow binaries for arm64 and x86_64 macos with openssl 1.1 and 3.0 to the `r-binary-packages` job - Use the binaries to build the nightly packages - bump snappy version to 1.1.10 (and patch it on 10.13) due to build issues with the current version. This also touches on a number of issues in regards to a sanitizer issue we have had for a long time: apache#32562 apache#31766 - Disable the centos binary test step: apache#37922 Follow up issues: - apache#37921 - apache#37941 - apache#37945 * Closes: apache#37923 Lead-authored-by: Jacob Wujciak-Jens <[email protected]> Co-authored-by: Jonathan Keane <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Dewey Dunnington <[email protected]>
1 parent 5c3b3d4 commit 4503fb0

13 files changed

+268
-97
lines changed

cpp/Brewfile

+6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ brew "aws-sdk-cpp"
1919
brew "bash"
2020
brew "boost"
2121
brew "brotli"
22+
brew "bzip2"
2223
brew "c-ares"
24+
brew "curl"
2325
brew "ccache"
2426
brew "cmake"
2527
brew "flatbuffers"
@@ -29,14 +31,18 @@ brew "googletest"
2931
brew "grpc"
3032
brew "llvm@14"
3133
brew "lz4"
34+
brew "mimalloc"
3235
brew "ninja"
3336
brew "node"
3437
brew "openssl@3"
38+
brew "pkg-config"
3539
brew "protobuf"
3640
brew "python"
3741
brew "rapidjson"
42+
brew "re2"
3843
brew "snappy"
3944
brew "thrift"
45+
brew "utf8proc"
4046
brew "wget"
4147
brew "xsimd"
4248
brew "zstd"

cpp/cmake_modules/SetupCxxFlags.cmake

+11-4
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,18 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STRE
456456
# Don't complain about optimization passes that were not possible
457457
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-pass-failed")
458458

459-
# Avoid clang / libc++ error about C++17 aligned allocation on macOS.
460-
# See https://chromium.googlesource.com/chromium/src/+/eee44569858fc650b635779c4e34be5cb0c73186%5E%21/#F0
461-
# for details.
462459
if(APPLE)
463-
set(CXX_ONLY_FLAGS "${CXX_ONLY_FLAGS} -fno-aligned-new")
460+
# Avoid clang / libc++ error about C++17 aligned allocation on macOS.
461+
# See https://chromium.googlesource.com/chromium/src/+/eee44569858fc650b635779c4e34be5cb0c73186%5E%21/#F0
462+
# for details.
463+
string(APPEND CXX_ONLY_FLAGS " -fno-aligned-new")
464+
465+
if(CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 20)
466+
# Avoid C++17 std::get 'not available' issue on macOS 10.13
467+
# This will be required until atleast R 4.4 is released and
468+
# CRAN (hopefully) stops checking on 10.13
469+
string(APPEND CXX_ONLY_FLAGS " -D_LIBCPP_DISABLE_AVAILABILITY")
470+
endif()
464471
endif()
465472
endif()
466473

cpp/cmake_modules/ThirdpartyToolchain.cmake

+21
Original file line numberDiff line numberDiff line change
@@ -1308,13 +1308,34 @@ macro(build_snappy)
13081308
set(SNAPPY_CMAKE_ARGS
13091309
${EP_COMMON_CMAKE_ARGS} -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF
13101310
"-DCMAKE_INSTALL_PREFIX=${SNAPPY_PREFIX}")
1311+
# Snappy unconditionaly enables Werror when building with clang this can lead
1312+
# to build failues by way of new compiler warnings. This adds a flag to disable
1313+
# Werror to the very end of the invocation to override the snappy internal setting.
1314+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1315+
foreach(CONFIG DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
1316+
list(APPEND
1317+
SNAPPY_CMAKE_ARGS
1318+
"-DCMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}=${EP_CXX_FLAGS_${CONFIG}} -Wno-error"
1319+
)
1320+
endforeach()
1321+
endif()
1322+
1323+
if(APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 20)
1324+
# On macOS 10.13 we need to explicitly add <functional> to avoid a missing include error
1325+
# This can be removed once CRAN no longer checks on macOS 10.13
1326+
find_program(PATCH patch REQUIRED)
1327+
set(SNAPPY_PATCH_COMMAND ${PATCH} -p1 -i ${CMAKE_CURRENT_LIST_DIR}/snappy.diff)
1328+
else()
1329+
set(SNAPPY_PATCH_COMMAND)
1330+
endif()
13111331

13121332
externalproject_add(snappy_ep
13131333
${EP_COMMON_OPTIONS}
13141334
BUILD_IN_SOURCE 1
13151335
INSTALL_DIR ${SNAPPY_PREFIX}
13161336
URL ${SNAPPY_SOURCE_URL}
13171337
URL_HASH "SHA256=${ARROW_SNAPPY_BUILD_SHA256_CHECKSUM}"
1338+
PATCH_COMMAND ${SNAPPY_PATCH_COMMAND}
13181339
CMAKE_ARGS ${SNAPPY_CMAKE_ARGS}
13191340
BUILD_BYPRODUCTS "${SNAPPY_STATIC_LIB}")
13201341

cpp/cmake_modules/snappy.diff

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/snappy.cc b/snappy.cc
2+
index d414718..5b0d0d6 100644
3+
--- a/snappy.cc
4+
+++ b/snappy.cc
5+
@@ -83,6 +83,7 @@
6+
#include <string>
7+
#include <utility>
8+
#include <vector>
9+
+#include <functional>
10+
11+
namespace snappy {
12+

cpp/thirdparty/versions.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ ARROW_RAPIDJSON_BUILD_VERSION=232389d4f1012dddec4ef84861face2d2ba85709
101101
ARROW_RAPIDJSON_BUILD_SHA256_CHECKSUM=b9290a9a6d444c8e049bd589ab804e0ccf2b05dc5984a19ed5ae75d090064806
102102
ARROW_RE2_BUILD_VERSION=2022-06-01
103103
ARROW_RE2_BUILD_SHA256_CHECKSUM=f89c61410a072e5cbcf8c27e3a778da7d6fd2f2b5b1445cd4f4508bee946ab0f
104-
# 1.1.9 is patched to implement https://github.com/google/snappy/pull/148 if this is bumped, remove the patch
105-
ARROW_SNAPPY_BUILD_VERSION=1.1.9
106-
ARROW_SNAPPY_BUILD_SHA256_CHECKSUM=75c1fbb3d618dd3a0483bff0e26d0a92b495bbe5059c8b4f1c962b478b6e06e7
104+
ARROW_SNAPPY_BUILD_VERSION=1.1.10
105+
ARROW_SNAPPY_BUILD_SHA256_CHECKSUM=49d831bffcc5f3d01482340fe5af59852ca2fe76c3e05df0e67203ebbe0f1d90
107106
ARROW_SUBSTRAIT_BUILD_VERSION=v0.27.0
108107
ARROW_SUBSTRAIT_BUILD_SHA256_CHECKSUM=4ed375f69d972a57fdc5ec406c17003a111831d8640d3f1733eccd4b3ff45628
109108
ARROW_S2N_TLS_BUILD_VERSION=v1.3.35

dev/release/rat_exclude_files.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cpp/build-support/iwyu/*
2424
cpp/cmake_modules/FindPythonLibsNew.cmake
2525
cpp/cmake_modules/SnappyCMakeLists.txt
2626
cpp/cmake_modules/SnappyConfig.h
27+
cpp/cmake_modules/snappy.diff
2728
cpp/examples/parquet/parquet-arrow/cmake_modules/FindArrow.cmake
2829
cpp/src/parquet/.parquetcppversion
2930
cpp/src/generated/parquet_constants.cpp

dev/tasks/macros.jinja

+13-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ on:
307307
stopifnot(packageVersion("arrow") == {{ '"${{needs.source.outputs.pkg_version}}"' }})
308308
{% endmacro %}
309309

310-
{%- macro github_setup_local_r_repo(get_nix, get_win) -%}
310+
{%- macro github_setup_local_r_repo(get_nix, get_win, get_mac=False) -%}
311+
# TODO: improve arg handling
311312
- name: Setup local repo
312313
shell: bash
313314
run: mkdir repo
@@ -327,6 +328,17 @@ on:
327328
path: repo/libarrow/bin/linux-openssl-{{ openssl_version }}
328329
{% endfor %}
329330
{% endif %}
331+
{% if get_mac %}
332+
{% for openssl_version in ["1.1", "3.0"] %}
333+
{% for arch in ["x86_64", "arm64"] %}
334+
- name: Get macOS {{ arch }} OpenSSL {{ openssl_version }} binary
335+
uses: actions/download-artifact@v3
336+
with:
337+
name: r-lib__libarrow__bin__darwin-{{arch}}-openssl-{{ openssl_version }}
338+
path: repo/libarrow/bin/darwin-{{ arch }}-openssl-{{ openssl_version }}
339+
{% endfor %}
340+
{% endfor %}
341+
{% endif %}
330342
- name: Get src pkg
331343
uses: actions/download-artifact@v3
332344
with:

dev/tasks/r/github.packages.yml

+71-12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,59 @@ jobs:
5656
name: r-pkg__src__contrib
5757
path: arrow/r/arrow_*.tar.gz
5858

59+
macos-cpp:
60+
name: C++ Binary macOS OpenSSL {{ '${{ matrix.openssl }}' }} {{ '${{ matrix.platform.arch }}' }}
61+
62+
runs-on: {{ '${{ matrix.platform.runs_on }}' }}
63+
64+
needs: source
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
platform:
69+
- { runs_on: ["self-hosted", "macos-10.13"], arch: "x86_64" }
70+
71+
- { runs_on: ["self-hosted", "macOS", "arm64", "devops-managed"], arch: "arm64" }
72+
openssl: ['3.0', '1.1']
73+
74+
steps:
75+
{{ macros.github_checkout_arrow(action_v="3")|indent }}
76+
{{ macros.github_change_r_pkg_version(is_fork, '${{ needs.source.outputs.pkg_version }}')|indent }}
77+
- name: Install Deps
78+
if: {{ "${{ !contains(matrix.platform.runs_on, 'macos-10.13') }}" }}
79+
run: |
80+
brew install sccache ninja
81+
brew install openssl@{{ '${{ matrix.openssl }}' }}
82+
- name: Build libarrow
83+
shell: bash
84+
env:
85+
{{ macros.github_set_sccache_envvars()|indent(8) }}
86+
MACOSX_DEPLOYMENT_TARGET: "10.13"
87+
ARROW_S3: ON
88+
ARROW_GCS: ON
89+
ARROW_DEPENDENCY_SOURCE: BUNDLED
90+
CMAKE_GENERATOR: Ninja
91+
LIBARROW_MINIMAL: false
92+
run: |
93+
sccache --start-server
94+
export EXTRA_CMAKE_FLAGS="-DOPENSSL_ROOT_DIR=$(brew --prefix openssl@{{ '${{ matrix.openssl }}' }})"
95+
cd arrow
96+
r/inst/build_arrow_static.sh
97+
- name: Bundle libarrow
98+
shell: bash
99+
env:
100+
PKG_FILE: arrow-{{ '${{ needs.source.outputs.pkg_version }}' }}.zip
101+
VERSION: {{ '${{ needs.source.outputs.pkg_version }}' }}
102+
run: |
103+
cd arrow/r/libarrow/dist
104+
zip -r $PKG_FILE lib/ include/
105+
106+
- name: Upload binary artifact
107+
uses: actions/upload-artifact@v3
108+
with:
109+
name: r-lib__libarrow__bin__darwin-{{ '${{ matrix.platform.arch }}' }}-openssl-{{ '${{ matrix.openssl }}' }}
110+
path: arrow/r/libarrow/dist/arrow-*.zip
111+
59112
linux-cpp:
60113
name: C++ Binary Linux OpenSSL {{ '${{ matrix.openssl }}' }}
61114
runs-on: ubuntu-latest
@@ -135,7 +188,7 @@ jobs:
135188
path: build/arrow-*.zip
136189

137190
r-packages:
138-
needs: [source, windows-cpp]
191+
needs: [source, windows-cpp, macos-cpp]
139192
name: {{ '${{ matrix.platform.name }} ${{ matrix.r_version.r }}' }}
140193
runs-on: {{ '${{ matrix.platform.runs_on }}' }}
141194
strategy:
@@ -167,7 +220,7 @@ jobs:
167220
168221
rig system setup-user-lib
169222
rig system add-pak
170-
{{ macros.github_setup_local_r_repo(false, true)|indent }}
223+
{{ macros.github_setup_local_r_repo(false, true, true)|indent }}
171224
- name: Prepare Dependency Installation
172225

173226
shell: bash
@@ -178,18 +231,19 @@ jobs:
178231
with:
179232
working-directory: 'arrow'
180233
extra-packages: cpp11
181-
- name: Install sccache
182-
if: startsWith(matrix.platform, 'macos')
183-
run: brew install sccache
234+
- name: Set CRAN like openssl
235+
if: contains(matrix.platform.runs_on, 'arm64')
236+
run: |
237+
# The arm64 runners contain openssl 1.1.1t in this path that is always included first so we need to override the
238+
# default setting of the brew --prefix as root dir to avoid version conflicts.
239+
echo "OPENSSL_ROOT_DIR=/opt/R/arm64" >> $GITHUB_ENV
184240
- name: Build Binary
185241
id: build
186242
shell: Rscript {0}
187243
env:
188-
NOT_CRAN: "true" # actions/setup-r sets this implicitly
244+
NOT_CRAN: "false" # actions/setup-r sets this implicitly
189245
ARROW_R_DEV: "true"
190-
FORCE_AUTOBREW: "true" # this is ignored on windows
191-
# sccache for macos
192-
{{ macros.github_set_sccache_envvars()|indent(8) }}
246+
LIBARROW_BINARY: "true" # has to be set as long as allowlist not updated
193247
run: |
194248
on_windows <- tolower(Sys.info()[["sysname"]]) == "windows"
195249
@@ -213,8 +267,10 @@ jobs:
213267
INSTALL_opts = INSTALL_opts
214268
)
215269
270+
216271
# Test
217272
library(arrow)
273+
arrow_info()
218274
read_parquet(system.file("v0.7.1.parquet", package = "arrow"))
219275
220276
# encode contrib.url for artifact name
@@ -233,7 +289,6 @@ jobs:
233289
with:
234290
name: r-pkg{{ '${{ steps.build.outputs.path }}' }}
235291
path: arrow_*
236-
237292
test-linux-binary:
238293
needs: [source, linux-cpp]
239294
name: Test binary {{ '${{ matrix.config.image }}' }}
@@ -291,7 +346,10 @@ jobs:
291346
with:
292347
name: r-pkg_centos7
293348
path: arrow_*
349+
294350
test-centos-binary:
351+
# arrow binary package not on ppm currently see #37922
352+
if: false
295353
needs: test-linux-binary
296354
runs-on: ubuntu-latest
297355
container: "rstudio/r-base:4.2-centos7"
@@ -317,7 +375,8 @@ jobs:
317375
read_parquet(system.file("v0.7.1.parquet", package = "arrow"))
318376
print(arrow_info())
319377
320-
test-source:
378+
#TODO test macos source build?
379+
test-linux-source:
321380
needs: source
322381
name: Test linux source build
323382
runs-on: ubuntu-latest
@@ -367,7 +426,7 @@ jobs:
367426
368427
upload-binaries:
369428
# Only upload binaries if all tests pass.
370-
needs: [r-packages, test-source, test-linux-binary, test-centos-binary]
429+
needs: [r-packages, test-linux-source, test-linux-binary]
371430
name: Upload artifacts
372431
runs-on: ubuntu-latest
373432
steps:

dev/tasks/tasks.yml

+4
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,10 @@ tasks:
994994
- r-lib__libarrow__bin__linux-openssl-1.0__arrow-{no_rc_r_version}\.zip
995995
- r-lib__libarrow__bin__linux-openssl-1.1__arrow-{no_rc_r_version}\.zip
996996
- r-lib__libarrow__bin__linux-openssl-3.0__arrow-{no_rc_r_version}\.zip
997+
- r-lib__libarrow__bin__darwin-arm64-openssl-1.1__arrow-{no_rc_r_version}\.zip
998+
- r-lib__libarrow__bin__darwin-arm64-openssl-3.0__arrow-{no_rc_r_version}\.zip
999+
- r-lib__libarrow__bin__darwin-x86_64-openssl-1.1__arrow-{no_rc_r_version}\.zip
1000+
- r-lib__libarrow__bin__darwin-x86_64-openssl-3.0__arrow-{no_rc_r_version}\.zip
9971001
- r-pkg__bin__windows__contrib__4.1__arrow_{no_rc_r_version}\.zip
9981002
- r-pkg__bin__windows__contrib__4.2__arrow_{no_rc_r_version}\.zip
9991003
- r-pkg__bin__macosx__contrib__4.1__arrow_{no_rc_r_version}\.tgz

0 commit comments

Comments
 (0)