Skip to content

Commit dc6f817

Browse files
Improve README and Contributing Guide
1 parent 3a6d991 commit dc6f817

File tree

2 files changed

+163
-35
lines changed

2 files changed

+163
-35
lines changed

CONTRIBUTING.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Contributing
2+
3+
We would ❤️ for you to contribute to Appwrite and help make it better! As a contributor, here are the guidelines we would like you to follow:
4+
5+
## Code of Conduct
6+
7+
Help us keep Appwrite open and inclusive. Please read and follow our [Code of Conduct](/CODE_OF_CONDUCT.md).
8+
9+
## Submit a Pull Request 🚀
10+
11+
12+
Branch naming convention is as following
13+
14+
`TYPE-ISSUE_ID-DESCRIPTION`
15+
16+
example:
17+
18+
```
19+
doc-548-submit-a-pull-request-section-to-contribution-guide
20+
```
21+
22+
When `TYPE` can be:
23+
24+
- **feat** - is a new feature
25+
- **doc** - documentation only changes
26+
- **cicd** - changes related to CI/CD system
27+
- **fix** - a bug fix
28+
- **refactor** - code change that neither fixes a bug nor adds a feature
29+
30+
**All PRs must include a commit message with the changes description!**
31+
32+
For the initial start, fork the project and use git clone command to download the repository to your computer. A standard procedure for working on an issue would be to:
33+
34+
1. `git pull`, before creating a new branch, pull the changes from upstream. Your master needs to be up to date.
35+
36+
```
37+
$ git pull
38+
```
39+
40+
2. Create new branch from `master` like: `doc-548-submit-a-pull-request-section-to-contribution-guide`<br/>
41+
42+
```
43+
$ git checkout -b [name_of_your_new_branch]
44+
```
45+
46+
3. Work - commit - repeat ( be sure to be in your branch )
47+
48+
4. Before you push your changes, make sure your code follows the `Rustfmt` coding standards , which is the standard Appwrite follows currently. You can easily do this by running the formatter.
49+
50+
```bash
51+
cargo fmt
52+
```
53+
54+
If the `cargo fmt` command does not work then run the following to install rustfmt:
55+
56+
```bash
57+
rustup component add rustfmt
58+
```
59+
60+
This will give you a list of errors for you to rectify
61+
62+
1. Push changes to GitHub
63+
64+
```
65+
$ git push origin [name_of_your_new_branch]
66+
```
67+
68+
6. Submit your changes for review
69+
If you go to your repository on GitHub, you'll see a `Compare & pull request` button. Click on that button.
70+
7. Start a Pull Request
71+
Now submit the pull request and click on `Create pull request`.
72+
8. Get a code review approval/reject
73+
9. After approval, merge your PR
74+
10. GitHub will automatically delete the branch after the merge is done. (they can still be restored).
75+
76+
77+
## Running Tests
78+
Tests are run with Docker in order to test both alpine builds and GNU linux builds, Docker Compose is also required.
79+
80+
Bring up the testing containers using:
81+
```bash
82+
docker compose up -d --force-recreate --build
83+
```
84+
85+
Then run the tests using
86+
```bash
87+
docker compose exec -T tests_gnu sh -c "cd /src/ && /src/vendor/bin/phpunit"
88+
89+
docker compose exec -T tests_alpine sh -c "cd /src/ && /src/vendor/bin/phpunit"
90+
```
91+
92+
The first command tests GNU based machines and the second one tests alpine, both must pass before the PR is merged.

README.md

+71-35
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,77 @@
1-
# PHP Scrypt
1+
# PHP Scrypt
22

3-
A simple PHP Extension written in Rust to create scrypt password hashes.
3+
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
4+
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
5+
[![Follow Appwrite on StackShare](https://img.shields.io/badge/follow%20on-stackshare-blue?style=flat-square)](https://stackshare.io/appwrite)
6+
[![appwrite.io](https://img.shields.io/badge/appwrite-.io-f02e65?style=flat-square)](https://appwrite.io)
7+
8+
A simple PHP Extension written in Rust to create scrypt password hashes. Supports building on X86-64 and ARM platforms.
49

510
## Installation
6-
Once you have a compiled version, either through a release or building it yourself, you can install the extension by moving it to your PHP extension directory which is usually `/usr/local/lib/php/extensions/`. on Linux and `C:\php\extensions` on Windows.
711

8-
Next you need to add the extension to your php.ini file.
12+
### Compiling Requirements
13+
- Linux, MacOS or Windows-based operating system
14+
- Latest Version of Rust Stable
15+
- PHP 8.0 or newer
16+
- Clang 5.0 or Later
17+
18+
### Notes for Windows compilation
19+
- This extension can only be compiled for PHP installations sourced from https://windows.php.net.
20+
- Rust Nightly is required for Windows compilation.
21+
- This extension requires the `cl.exe` compiler. This is usually bundled with Visual Studio.
22+
- Stub generation does not work on Windows.
23+
24+
### Building The Extension
25+
Clone the repository into your project directory.
26+
```bash
27+
git clone https://github.com/appwrite/php-scrypt.git && \
28+
cd php-scrypt
29+
```
30+
Compile the extension
31+
```bash
32+
cargo build --release
33+
```
34+
35+
<details>
36+
<summary>
937

10-
MacOS:
11-
```php
12-
extension=libphp_scrypt.dylib
38+
### Building for Alpine
39+
40+
</summary>
41+
While writing this extension we found out that [Rust in general](https://github.com/rust-lang/rust/issues/59302) still has a few issues with [musl libc](https://musl.libc.org/) found in Alpine. It is possible to build this project successfully by using an alternative linker and building on a gnu-based system targetting `linux-unknown-musl`.
42+
43+
We strongly recommend using [zigbuild](https://github.com/messense/cargo-zigbuild) as the linker for this project as we found it's the most stable and easy to install alternate linker. we also use the "-C target-feature=crt-static" compiler flags to aid with building on musl as stated [here](https://github.com/rust-lang/rust/issues/59302).
44+
45+
The build command for these platforms will look like so:
46+
```sh
47+
RUSTFLAGS="-C target-feature=-crt-static" cargo zigbuild --workspace --all-targets --target x86_64-unknown-linux-musl --release
1348
```
49+
This will produce a .so file similar to a normal build.
50+
</details>
1451

15-
Linux:
16-
```php
17-
extension=libphp_scrypt.so
52+
### Installing the Extension
53+
Copy the compiled extension from the `target` directory into your PHP extension directory.
54+
55+
If you don't know where your PHP extension directory is you can run the following command:
56+
```bash
57+
php -i | grep extension_dir
1858
```
1959

20-
Windows:
21-
```php
22-
extension=libphp_scrypt.dll
60+
Copy the extension to the directory outputted
61+
```bash
62+
cp target/release/libphp-scrypt.so /path/to/extension_dir
2363
```
2464

25-
After that the extension will be available to you, check out **Usage** below to see how to use it.
65+
> Depending on your OS, your extension may end with `.dll` for windows or `.dylib` for macOS.
66+
67+
### Enabling the extension
68+
69+
After compiling and moving the extension into the correct directory, you can enable the extension by adding the following line to your `php.ini` file:
70+
71+
```
72+
extension=libphp-scrypt.so
73+
```
74+
> Change .so to .dll for Windows or .dylib for macOS.
2675
2776
## Usage
2877
Using the scrypt extension is easy, there is only one function in this extension the usage is as follows:
@@ -41,25 +90,6 @@ $hash = \scrypt("password", "salt", 32768, 8, 1, 64);
4190
\var_dump("Your hash is " . $hash);
4291
```
4392

44-
## Building the extension
45-
Building this extension requires that you have a version of PHP installed that has the `php-config` command.
46-
47-
After all the prequisites are met simply run the following command to build a release version of the extension:
48-
```sh
49-
cargo build --release
50-
```
51-
52-
### Building for Alpine
53-
While writing this extension we found out that [Rust in general](https://github.com/rust-lang/rust/issues/59302) still has a few issues with [musl libc](https://musl.libc.org/) found in Alpine. It is possible to build this project successfully by using an alternative linker and building on a gnu-based system targetting linux-unknown-musl.
54-
55-
We strongly recommend using [zigbuild](https://github.com/messense/cargo-zigbuild) as the linker for this project as we found it's the most stable and easy to install alternate linker. we also use the "-C target-feature=crt-static" compiler flags to aid with building on musl as stated [here](https://github.com/rust-lang/rust/issues/59302).
56-
57-
The build command for these platforms will look like so:
58-
```sh
59-
RUSTFLAGS="-C target-feature=-crt-static" cargo zigbuild --workspace --all-targets --target x86_64-unknown-linux-musl --release
60-
```
61-
This will produce a .so file similar to a normal build.
62-
6393
## Authors
6494

6595
**Bradley Schofield**
@@ -73,9 +103,15 @@ This will produce a .so file similar to a normal build.
73103
**Eldad Fux**
74104
- [https://github.com/eldadfux](https://github.com/eldadfux)
75105

76-
## Copyright and license
106+
## Special Thanks
107+
- [davidcole1340](https://github.com/davidcole1340) - For developing the [ext-php-rs](https://github.com/davidcole1340/ext-php-rs) bindings used for this project.
77108

78-
The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
109+
## Contributing
79110

111+
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
80112

113+
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the [contribution guide](CONTRIBUTING.md).
114+
115+
## Copyright and license
81116

117+
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

0 commit comments

Comments
 (0)