Skip to content

Commit

Permalink
GH-40248: [R] fallback to the correct libtool when we find a GNU one (#…
Browse files Browse the repository at this point in the history
…40259)

### Rationale for this change

On the CRAN build machines the GNU libtool is on the path in front of the macOS libtool. Though these are named the same thing, they are actually very different and don't actually appear to be substitutes

I checked on a non-developer's machine to see if `/usr/bin/libtool` exists, and it did. So I believe we _should_ be ok with this even if xcode / command line tools haven't been installed.

One note: it's possible that we could get the GNU libtool in link mode to work with the right incantation (something like `libtool --mode=link --tag=CXX ${cmake_compiler} -o ...` but when I tried this I kept getting symbol not found errors. Ultimately, I think any mac that we are on will have the apple-provided libtool, so decided to go the route of finding it. 

### What changes are included in this PR?

When we detect we are on a GNU libtool, we look to `/usr/bin/libtool` instead.

### Are these changes tested?

Yes. See a broken config failing at #40259 (comment) and then the next one passes

### Are there any user-facing changes?

We will remain on CRAN

**This PR contains a "Critical Fix".**
* GitHub Issue: #40248

Lead-authored-by: Jonathan Keane <jkeane@gmail.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
  • Loading branch information
2 people authored and raulcd committed Mar 13, 2024
1 parent 6921d54 commit cb35c53
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cpp/cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,27 @@ function(arrow_create_merged_static_lib output_target)
endforeach()

if(APPLE)
set(BUNDLE_COMMAND "libtool" "-no_warning_for_no_symbols" "-static" "-o"
# The apple-distributed libtool is what we want for bundling, but there is
# a GNU libtool that has a namecollision (and happens to be bundled with R, too).
# We are not compatible with GNU libtool, so we need to avoid it.

# check in the obvious places first to find Apple's libtool
# HINTS is used before system paths and before PATHS, so we use that
# even though hard coded paths should go in PATHS
# TODO: use a VALIDATOR when we require cmake >= 3.25
find_program(LIBTOOL_MACOS libtool HINTS /usr/bin
/Library/Developer/CommandLineTools/usr/bin)

# confirm that the libtool we found is not GNU libtool
execute_process(COMMAND ${LIBTOOL_MACOS} -V
OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
message(FATAL_ERROR "libtool found appears to be the incompatible GNU libtool: ${LIBTOOL_MACOS}"
)
endif()

set(BUNDLE_COMMAND ${LIBTOOL_MACOS} "-no_warning_for_no_symbols" "-static" "-o"
${output_lib_path} ${all_library_paths})
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU|Intel|IntelLLVM)$")
set(ar_script_path ${CMAKE_BINARY_DIR}/${ARG_NAME}.ar)
Expand Down
12 changes: 12 additions & 0 deletions dev/tasks/r/github.macos-linux.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ jobs:
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
# CRAN builders have the entire bin here added to the path. This sometimes
# includes things like GNU libtool which name-collide with what we expect
- name: Add R.framework/Resources/bin to the path
if: contains(matrix.os, 'macOS')
run: echo "/Library/Frameworks/R.framework/Resources/bin" >> $GITHUB_PATH
- name : Check whether libtool in R is used
if: contains(matrix.os, 'macOS')
run: |
if [ "$(which libtool)" != "/Library/Frameworks/R.framework/Resources/bin/libtool" ]; then
echo "libtool provided by R isn't found: $(which libtool)"
exit 1
fi
- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
Expand Down

0 comments on commit cb35c53

Please sign in to comment.