Skip to content

Commit 9a01330

Browse files
committed
fix: lib detection in tests
1 parent 61efb45 commit 9a01330

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

php/tests/tests/Pest.php

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,47 @@ function mq_client(array $opts = []) {
8787
}
8888

8989
function getPhpAndExtPath() {
90-
$ext = realpath(__DIR__ . '/../../../target/debug/librabbit_rs.' . (
91-
PHP_OS_FAMILY === 'Darwin' ? 'dylib' : (str_starts_with(strtolower(PHP_OS), 'win') ? 'dll' : 'so')
92-
));
90+
$root = realpath(__DIR__ . '/../../..');
91+
if ($root === false) {
92+
throw new RuntimeException('Unable to resolve repository root.');
93+
}
94+
9395
$php = trim(shell_exec('which php'));
96+
$suffix = PHP_OS_FAMILY === 'Darwin'
97+
? 'dylib'
98+
: (str_starts_with(strtolower(PHP_OS), 'win') ? 'dll' : 'so');
9499

95-
return [
96-
'php' => $php,
97-
'ext' => $ext,
98-
];
100+
$candidates = [];
101+
102+
$libPathEnv = getenv('LIB_PATH');
103+
if ($libPathEnv !== false && $libPathEnv !== '') {
104+
$candidates[] = $libPathEnv;
105+
}
106+
107+
$cargoTarget = getenv('CARGO_TARGET_DIR');
108+
if ($cargoTarget !== false && $cargoTarget !== '') {
109+
$cargoTarget = rtrim($cargoTarget, DIRECTORY_SEPARATOR);
110+
$candidates[] = $cargoTarget . '/debug/librabbit_rs.' . $suffix;
111+
$candidates[] = $cargoTarget . '/release/librabbit_rs.' . $suffix;
112+
}
113+
114+
$candidates[] = $root . '/target/debug/librabbit_rs.' . $suffix;
115+
$candidates[] = $root . '/target/release/librabbit_rs.' . $suffix;
116+
117+
$ciRelease = glob($root . '/target/ci/*/release/librabbit_rs.' . $suffix) ?: [];
118+
$ciDebug = glob($root . '/target/ci/*/debug/librabbit_rs.' . $suffix) ?: [];
119+
$candidates = array_merge($candidates, $ciRelease, $ciDebug);
120+
121+
foreach ($candidates as $candidate) {
122+
if ($candidate && is_file($candidate)) {
123+
return [
124+
'php' => $php,
125+
'ext' => realpath($candidate) ?: $candidate,
126+
];
127+
}
128+
}
129+
130+
throw new RuntimeException('RabbitRs extension not found. Run "cargo build" first.');
99131
}
100132

101133
function sc_expect_success(callable $fn) {
@@ -119,4 +151,4 @@ function sc_publish_many(PhpChannel $ch, string $q, int $n, string $prefix = 'm'
119151
for ($i = 0; $i < $n; $i++) {
120152
expect($ch->basicPublish('', $q, new AmqpMessage($prefix.$i)))->toBeTrue();
121153
}
122-
}
154+
}

scripts/common.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ common::resolve_extension() {
135135
local debug_candidate="$root/target/debug/librabbit_rs.${ext}"
136136
local release_candidate="$root/target/release/librabbit_rs.${ext}"
137137

138+
if [[ -n "${CARGO_TARGET_DIR:-}" ]]; then
139+
local cargo_dir="${CARGO_TARGET_DIR%/}"
140+
local cargo_debug="$cargo_dir/debug/librabbit_rs.${ext}"
141+
local cargo_release="$cargo_dir/release/librabbit_rs.${ext}"
142+
143+
if [[ -f "$cargo_debug" ]]; then
144+
echo "$cargo_debug"
145+
return 0
146+
fi
147+
if [[ -f "$cargo_release" ]]; then
148+
echo "$cargo_release"
149+
return 0
150+
fi
151+
fi
152+
138153
if [[ -f "$debug_candidate" ]]; then
139154
echo "$debug_candidate"
140155
return 0

0 commit comments

Comments
 (0)