|
1 | 1 | #![warn(rust_2018_idioms, clippy::dbg_macro, clippy::print_stdout)] |
2 | | - |
3 | | -/*! |
4 | | -## Rust ❤️ PHP |
5 | | -
|
6 | | -A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible. |
7 | | -
|
8 | | -## Usage |
9 | | -
|
10 | | -1. Make sure `libclang` and `php` is installed. |
11 | | -
|
12 | | -```bash |
13 | | -# If you are using debian like linux system: |
14 | | -sudo apt install libclang-10-dev php-cli |
15 | | -``` |
16 | | -
|
17 | | -2. Create you cargo project, suppose your application is called myapp. |
18 | | -
|
19 | | -```bash |
20 | | -cargo new myapp |
21 | | -``` |
22 | | -
|
23 | | -3. Add the dependencies and metadata to you Cargo project. |
24 | | -
|
25 | | -```toml |
26 | | -[lib] |
27 | | -crate-type = ["cdylib"] |
28 | | -
|
29 | | -[dependencies] |
30 | | -phper = "0.3" |
31 | | -``` |
32 | | -
|
33 | | -4. Add these code to `main.rs`. |
34 | | -
|
35 | | -```no_run |
36 | | -use phper::cmd::make; |
37 | | -
|
38 | | -fn main() { |
39 | | - make(); |
40 | | -} |
41 | | -``` |
42 | | -
|
43 | | -5. Write you owned extension logic in `lib.rs`. |
44 | | -
|
45 | | -```no_run |
46 | | -use phper::{php_get_module, modules::Module}; |
47 | | -
|
48 | | -#[php_get_module] |
49 | | -pub fn get_module() -> Module { |
50 | | - let mut module = Module::new( |
51 | | - env!("CARGO_PKG_NAME"), |
52 | | - env!("CARGO_PKG_VERSION"), |
53 | | - env!("CARGO_PKG_AUTHORS"), |
54 | | - ); |
55 | | -
|
56 | | - // ... |
57 | | -
|
58 | | - module |
59 | | -} |
60 | | -``` |
61 | | -
|
62 | | -6. Build and install, if your php isn't installed globally, you should specify the path of `php-config`. |
63 | | -
|
64 | | -```bash |
65 | | -# Specify if php isn't installed globally. |
66 | | -export PHP_CONFIG = <Your path of php-config> |
67 | | -
|
68 | | -# Build libmyapp.so. |
69 | | -cargo build --release |
70 | | -
|
71 | | -# Install to php extension path, if you install php globally, you should use sudo. |
72 | | -cargo run --release -- install |
73 | | -``` |
74 | | -
|
75 | | -7. Edit your `php.ini`, add the below line. |
76 | | -
|
77 | | -```ini |
78 | | -extension = myapp |
79 | | -``` |
80 | | -
|
81 | | -8. Enjoy. |
82 | | -
|
83 | | -## examples |
84 | | -
|
85 | | -See [examples](https://github.com/jmjoy/phper/tree/master/examples). |
86 | | -
|
87 | | -## License |
88 | | -
|
89 | | -[Unlicense](https://github.com/jmjoy/phper/blob/master/LICENSE). |
90 | | -*/ |
| 2 | +#![doc = include_str!("../README.md")] |
91 | 3 |
|
92 | 4 | #[macro_use] |
93 | 5 | mod macros; |
|
0 commit comments