Skip to content

Commit 6df362b

Browse files
Added CLI crate for stubs, installation and removal (#107)
* started work on stub generator * Worked on stub CLI tool * Unused import * Account for namespaces in function and class names * Add support for docblocks on structs * Push Rust comments to stubs * Add indentation to stub generation * Add CLI application to install and generate stubs This time CLI application is defined on user side, called with `cargo run -- ..args..` * Export anyhow result * Add constants to stub file * Removed stub symbols No longer required as we are now building while also linking to PHP. Keeping the stubs causes the stubs to override the real symbols in the extension. * Fix stubs for real this time Removed stub symbols as they were being included in the extension dylib, fix by loading the PHP executable as a dylib, loading the required symbols globally. * Maybe actually fix stubs this time * Forgot to remove PHP binary loading * let's give this another go... cargo subcommand Now called via `cargo php <install,stubs>`. * Added `remove` command * Tidied up cargo-php, commented, set up CI * Fix return types with non-ident types * define namespace ordering * Fix tests, replace `Self` when in outer context * Moved allowed bindings into separate file * Update guide with CLI instructions
1 parent bedade8 commit 6df362b

File tree

30 files changed

+2083
-248
lines changed

30 files changed

+2083
-248
lines changed

.github/actions/zts/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ ENV PATH=/cargo/bin:/rust/bin:$PATH
1212

1313
RUN (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly --no-modify-path) && rustup default nightly
1414

15-
ENTRYPOINT [ "/cargo/bin/cargo", "build", "--release" ]
15+
ENTRYPOINT [ "/cargo/bin/cargo", "build", "--all", "--release" ]

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
env:
4747
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
4848
EXT_PHP_RS_TEST:
49-
run: cargo build --release --all-features
49+
run: cargo build --release --all-features --all
5050
- name: Test guide examples
5151
env:
5252
CARGO_PKG_NAME: mdbook-tests
@@ -59,7 +59,7 @@ jobs:
5959
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
6060
with:
6161
command: test
62-
args: --release
62+
args: --release --all
6363
build-zts:
6464
name: Build with ZTS
6565
runs-on: ubuntu-latest
@@ -103,7 +103,7 @@ jobs:
103103
LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.llvm }}/lib
104104
with:
105105
command: clippy
106-
args: -- -D warnings
106+
args: --all -- -D warnings
107107
- name: Build with docs stub
108108
env:
109109
DOCS_RS:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
22
Cargo.lock
33
/.vscode
4-
expand.rs
4+
/.idea
5+
expand.rs

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ closure = []
2727
[workspace]
2828
members = [
2929
"crates/macros",
30+
"crates/cli"
3031
]
3132

3233
[package.metadata.docs.rs]

allowed_bindings.rs

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
// This is a cheeky hack - since we need the list of allowed bindings in both
2+
// the build script and in the CLI crate (in differnet formats), we define the
3+
// `allowed_bindings.rs` file, which calls a macro called `bind` that doesn't
4+
// exist in the bindings file. Which ever script include!s the bindings must
5+
// define the `bind` macro. This allows us to have the list in string format
6+
// inside the build script and in macro format inside the CLI crate.
7+
8+
bind! {
9+
HashTable,
10+
_Bucket,
11+
_call_user_function_impl,
12+
_efree,
13+
_emalloc,
14+
_zend_executor_globals,
15+
_zend_expected_type,
16+
_zend_expected_type_Z_EXPECTED_ARRAY,
17+
_zend_expected_type_Z_EXPECTED_BOOL,
18+
_zend_expected_type_Z_EXPECTED_DOUBLE,
19+
_zend_expected_type_Z_EXPECTED_LONG,
20+
_zend_expected_type_Z_EXPECTED_OBJECT,
21+
_zend_expected_type_Z_EXPECTED_RESOURCE,
22+
_zend_expected_type_Z_EXPECTED_STRING,
23+
_zend_new_array,
24+
_zval_struct__bindgen_ty_1,
25+
_zval_struct__bindgen_ty_2,
26+
ext_php_rs_executor_globals,
27+
ext_php_rs_php_build_id,
28+
ext_php_rs_zend_object_alloc,
29+
ext_php_rs_zend_object_release,
30+
ext_php_rs_zend_string_init,
31+
ext_php_rs_zend_string_release,
32+
object_properties_init,
33+
php_info_print_table_end,
34+
php_info_print_table_header,
35+
php_info_print_table_row,
36+
php_info_print_table_start,
37+
std_object_handlers,
38+
zend_array_destroy,
39+
zend_array_dup,
40+
zend_call_known_function,
41+
zend_ce_argument_count_error,
42+
zend_ce_arithmetic_error,
43+
zend_ce_compile_error,
44+
zend_ce_division_by_zero_error,
45+
zend_ce_error_exception,
46+
zend_ce_exception,
47+
zend_ce_parse_error,
48+
zend_ce_throwable,
49+
zend_ce_type_error,
50+
zend_ce_unhandled_match_error,
51+
zend_ce_value_error,
52+
zend_class_entry,
53+
zend_declare_class_constant,
54+
zend_declare_property,
55+
zend_do_implement_interface,
56+
zend_execute_data,
57+
zend_function_entry,
58+
zend_hash_clean,
59+
zend_hash_index_del,
60+
zend_hash_index_find,
61+
zend_hash_index_update,
62+
zend_hash_next_index_insert,
63+
zend_hash_str_del,
64+
zend_hash_str_find,
65+
zend_hash_str_update,
66+
zend_internal_arg_info,
67+
zend_is_callable,
68+
zend_long,
69+
zend_lookup_class_ex,
70+
zend_module_entry,
71+
zend_object,
72+
zend_object_handlers,
73+
zend_object_std_init,
74+
zend_objects_clone_members,
75+
zend_register_bool_constant,
76+
zend_register_double_constant,
77+
zend_register_internal_class_ex,
78+
zend_register_long_constant,
79+
zend_register_string_constant,
80+
zend_resource,
81+
zend_string,
82+
zend_string_init_interned,
83+
zend_throw_exception_ex,
84+
zend_type,
85+
zend_value,
86+
zend_wrong_parameters_count_error,
87+
zval,
88+
CONST_CS,
89+
CONST_DEPRECATED,
90+
CONST_NO_FILE_CACHE,
91+
CONST_PERSISTENT,
92+
HT_MIN_SIZE,
93+
IS_ARRAY,
94+
IS_ARRAY_EX,
95+
IS_CALLABLE,
96+
IS_CONSTANT_AST,
97+
IS_CONSTANT_AST_EX,
98+
IS_DOUBLE,
99+
IS_FALSE,
100+
IS_INTERNED_STRING_EX,
101+
IS_LONG,
102+
IS_MIXED,
103+
IS_NULL,
104+
IS_OBJECT,
105+
IS_OBJECT_EX,
106+
IS_REFERENCE,
107+
IS_REFERENCE_EX,
108+
IS_RESOURCE,
109+
IS_RESOURCE_EX,
110+
IS_STRING,
111+
IS_STRING_EX,
112+
IS_TRUE,
113+
IS_TYPE_COLLECTABLE,
114+
IS_TYPE_REFCOUNTED,
115+
IS_UNDEF,
116+
IS_VOID,
117+
IS_PTR,
118+
MAY_BE_ANY,
119+
MAY_BE_BOOL,
120+
USING_ZTS,
121+
ZEND_ACC_ABSTRACT,
122+
ZEND_ACC_ANON_CLASS,
123+
ZEND_ACC_CALL_VIA_TRAMPOLINE,
124+
ZEND_ACC_CHANGED,
125+
ZEND_ACC_CLOSURE,
126+
ZEND_ACC_CONSTANTS_UPDATED,
127+
ZEND_ACC_CTOR,
128+
ZEND_ACC_DEPRECATED,
129+
ZEND_ACC_DONE_PASS_TWO,
130+
ZEND_ACC_EARLY_BINDING,
131+
ZEND_ACC_FAKE_CLOSURE,
132+
ZEND_ACC_FINAL,
133+
ZEND_ACC_GENERATOR,
134+
ZEND_ACC_HAS_FINALLY_BLOCK,
135+
ZEND_ACC_HAS_RETURN_TYPE,
136+
ZEND_ACC_HAS_TYPE_HINTS,
137+
ZEND_ACC_HAS_UNLINKED_USES,
138+
ZEND_ACC_HEAP_RT_CACHE,
139+
ZEND_ACC_IMMUTABLE,
140+
ZEND_ACC_IMPLICIT_ABSTRACT_CLASS,
141+
ZEND_ACC_INTERFACE,
142+
ZEND_ACC_LINKED,
143+
ZEND_ACC_NEARLY_LINKED,
144+
ZEND_ACC_NEVER_CACHE,
145+
ZEND_ACC_NO_DYNAMIC_PROPERTIES,
146+
ZEND_ACC_PRELOADED,
147+
ZEND_ACC_PRIVATE,
148+
ZEND_ACC_PROMOTED,
149+
ZEND_ACC_PROPERTY_TYPES_RESOLVED,
150+
ZEND_ACC_PROTECTED,
151+
ZEND_ACC_PUBLIC,
152+
ZEND_ACC_RESOLVED_INTERFACES,
153+
ZEND_ACC_RESOLVED_PARENT,
154+
ZEND_ACC_RETURN_REFERENCE,
155+
ZEND_ACC_REUSE_GET_ITERATOR,
156+
ZEND_ACC_STATIC,
157+
ZEND_ACC_STRICT_TYPES,
158+
ZEND_ACC_TOP_LEVEL,
159+
ZEND_ACC_TRAIT,
160+
ZEND_ACC_TRAIT_CLONE,
161+
ZEND_ACC_UNRESOLVED_VARIANCE,
162+
ZEND_ACC_USES_THIS,
163+
ZEND_ACC_USE_GUARDS,
164+
ZEND_ACC_VARIADIC,
165+
ZEND_DEBUG,
166+
ZEND_HAS_STATIC_IN_METHODS,
167+
ZEND_ISEMPTY,
168+
ZEND_MM_ALIGNMENT,
169+
ZEND_MM_ALIGNMENT_MASK,
170+
ZEND_MODULE_API_NO,
171+
ZEND_PROPERTY_EXISTS,
172+
ZEND_PROPERTY_ISSET,
173+
Z_TYPE_FLAGS_SHIFT,
174+
_IS_BOOL,
175+
_ZEND_IS_VARIADIC_BIT,
176+
_ZEND_SEND_MODE_SHIFT,
177+
_ZEND_TYPE_NULLABLE_BIT,
178+
ts_rsrc_id,
179+
_ZEND_TYPE_NAME_BIT,
180+
zval_ptr_dtor,
181+
zend_refcounted_h,
182+
zend_is_true,
183+
zend_object_std_dtor,
184+
zend_std_read_property,
185+
zend_std_write_property,
186+
zend_std_get_properties,
187+
zend_std_has_property,
188+
zend_objects_new,
189+
zend_standard_class_def,
190+
zend_class_serialize_deny,
191+
zend_class_unserialize_deny,
192+
zend_objects_store_del,
193+
gc_possible_root
194+
}

0 commit comments

Comments
 (0)