Skip to content

Commit 031485f

Browse files
authored
fix: arrow-ext installation through pie (#2273)
* fix: arrow-ext installation through pie * fix: makefile.frag
1 parent a1ec3ee commit 031485f

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Build the actual extension via Cargo (Rust) and replace the dummy .so
2+
# This runs after PHP's build system compiles the dummy arrow.c
3+
4+
ARROW_CARGO_DIR = $(srcdir)/..
5+
6+
all: cargo_build_arrow
7+
8+
.PHONY: cargo_build_arrow
9+
cargo_build_arrow: $(phplibdir)/arrow.so
10+
cd "$(ARROW_CARGO_DIR)" && PHP_CONFIG="$$(which php-config)" PHP="$$(which php)" cargo build --release
11+
@if [ "$$(uname)" = "Darwin" ]; then \
12+
cp "$(ARROW_CARGO_DIR)/target/release/libarrow.dylib" "$(phplibdir)/arrow.so"; \
13+
else \
14+
cp "$(ARROW_CARGO_DIR)/target/release/libarrow.so" "$(phplibdir)/arrow.so"; \
15+
fi
16+
@echo "Replaced dummy arrow.so with Rust-built extension"
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dnl config.m4 for extension arrow (Rust-based via ext-php-rs)
2-
dnl This is a best-effort PIE compatibility shim delegating to cargo
32

43
PHP_ARG_ENABLE([arrow],
54
[whether to enable arrow support],
@@ -8,41 +7,37 @@ PHP_ARG_ENABLE([arrow],
87

98
if test "$PHP_ARROW" != "no"; then
109
AC_MSG_CHECKING([for cargo (Rust build tool)])
11-
AC_PATH_PROG(CARGO, cargo, no)
12-
if test "$CARGO" = "no"; then
10+
AC_PATH_PROG(CARGO, cargo)
11+
if test -z "$CARGO"; then
12+
RUSTUP_CARGO=$(rustup which cargo 2>/dev/null)
13+
if test -n "$RUSTUP_CARGO"; then
14+
CARGO=$RUSTUP_CARGO
15+
fi
16+
fi
17+
if test -z "$CARGO"; then
1318
AC_MSG_ERROR([cargo is required to build the arrow extension. Install Rust from https://rustup.rs/])
1419
fi
1520
AC_MSG_RESULT([$CARGO])
1621

17-
dnl Build via cargo in the parent directory (where Cargo.toml lives)
18-
EXT_DIR=$(pwd)
19-
ARROW_SRC_DIR=$(dirname "$EXT_DIR")
20-
21-
AC_MSG_NOTICE([Building arrow extension via cargo...])
22-
(cd "$ARROW_SRC_DIR" && $CARGO build --release) || AC_MSG_ERROR([cargo build failed])
23-
24-
dnl Detect the built library
25-
case $host_os in
26-
darwin*)
27-
ARROW_LIB="$ARROW_SRC_DIR/target/release/libarrow.dylib"
28-
;;
29-
*)
30-
ARROW_LIB="$ARROW_SRC_DIR/target/release/libarrow.so"
31-
;;
32-
esac
33-
34-
if test ! -f "$ARROW_LIB"; then
35-
AC_MSG_ERROR([Built library not found at $ARROW_LIB])
22+
AC_MSG_CHECKING([for rustc (Rust compiler)])
23+
AC_PATH_PROG(RUSTC, rustc)
24+
if test -z "$RUSTC"; then
25+
RUSTUP_RUSTC=$(rustup which rustc 2>/dev/null)
26+
if test -n "$RUSTUP_RUSTC"; then
27+
RUSTC=$RUSTUP_RUSTC
28+
fi
3629
fi
37-
38-
dnl Copy built library to expected location
39-
mkdir -p "$EXT_DIR/modules"
40-
cp "$ARROW_LIB" "$EXT_DIR/modules/arrow.so"
30+
if test -z "$RUSTC"; then
31+
AC_MSG_ERROR([rustc is required to build the arrow extension. Install Rust from https://rustup.rs/])
32+
fi
33+
AC_MSG_RESULT([$RUSTC])
4134

4235
dnl Create a dummy C file so phpize/configure infrastructure does not complain
43-
if test ! -f "$EXT_DIR/arrow.c"; then
44-
echo "/* Dummy - actual extension built by Rust/cargo */" > "$EXT_DIR/arrow.c"
36+
ARROW_EXT_DIR=$(pwd)
37+
if test ! -f "$ARROW_EXT_DIR/arrow.c"; then
38+
echo "/* Dummy - actual extension built by Rust/cargo */" > "$ARROW_EXT_DIR/arrow.c"
4539
fi
4640

4741
PHP_NEW_EXTENSION(arrow, arrow.c, $ext_shared)
42+
PHP_ADD_MAKEFILE_FRAGMENT
4843
fi

0 commit comments

Comments
 (0)