Skip to content

Commit a5bf383

Browse files
authored
feat(stubs): Proper phpdoc-style comments in stubs #369 (#676)
1 parent fd0de48 commit a5bf383

File tree

3 files changed

+624
-81
lines changed

3 files changed

+624
-81
lines changed

crates/cli/src/ext.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::PathBuf;
22

33
use anyhow::{Context, Result};
44
use ext_php_rs::describe::Description;
5-
use libloading::os::unix::{Library, Symbol};
5+
use libloading::os::unix::{Library, RTLD_LAZY, RTLD_LOCAL, Symbol};
66

77
#[allow(improper_ctypes_definitions)]
88
pub struct Ext {
@@ -17,7 +17,16 @@ pub struct Ext {
1717
impl Ext {
1818
/// Loads an extension.
1919
pub fn load(ext_path: PathBuf) -> Result<Self> {
20-
let ext_lib = unsafe { Library::new(ext_path) }
20+
// On macOS, add RTLD_FIRST for two-level namespace which properly defers
21+
// resolution of symbols not needed for stub generation.
22+
#[cfg(target_os = "macos")]
23+
let ext_lib =
24+
unsafe { Library::open(Some(ext_path), RTLD_LAZY | RTLD_LOCAL | libc::RTLD_FIRST) }
25+
.with_context(|| "Failed to load extension library")?;
26+
27+
// On other Unix platforms, RTLD_LAZY | RTLD_LOCAL is sufficient
28+
#[cfg(not(target_os = "macos"))]
29+
let ext_lib = unsafe { Library::open(Some(ext_path), RTLD_LAZY | RTLD_LOCAL) }
2130
.with_context(|| "Failed to load extension library")?;
2231

2332
let describe_fn = unsafe {
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
---
22
source: crates/cli/tests/stubs_snapshot.rs
3-
assertion_line: 69
3+
assertion_line: 74
44
expression: stubs
55
---
66
<?php
77

88
// Stubs for ext-php-rs
99

1010
namespace {
11+
const CONST_NAME = 100;
12+
13+
const HELLO_WORLD = 100;
14+
1115
class TestClass {
1216
const NEW_CONSTANT_NAME = 5;
1317

@@ -17,22 +21,43 @@ namespace {
1721

1822
public $b;
1923

24+
/**
25+
* @param int $a
26+
* @param int $b
27+
*/
2028
public function __construct(int $a, int $b) {}
2129

30+
/**
31+
* @return \TestClass
32+
*/
2233
public function builderPattern(): \TestClass {}
2334

35+
/**
36+
* @param int $a
37+
* @param int $test
38+
* @return void
39+
*/
2440
public function testCamelCase(int $a = 5, int $test = 100): void {}
2541

42+
/**
43+
* @return int
44+
*/
2645
public static function x(): int {}
2746
}
2847

29-
const CONST_NAME = 100;
30-
31-
const HELLO_WORLD = 100;
32-
48+
/**
49+
* @param object $z
50+
* @return int
51+
*/
3352
function get_zval_convert(object $z): int {}
3453

54+
/**
55+
* @return string
56+
*/
3557
function hello_world(): string {}
3658

59+
/**
60+
* @return \TestClass
61+
*/
3762
function new_class(): \TestClass {}
3863
}

0 commit comments

Comments
 (0)