@@ -87,15 +87,47 @@ function mq_client(array $opts = []) {
8787}
8888
8989function 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
101133function 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+ }
0 commit comments