Skip to content

Commit

Permalink
Back to buildable state
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
  • Loading branch information
CodeLieutenant committed Jan 1, 2024
1 parent dc1fd18 commit fbd386f
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 330 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install libclang
run: sudo apt-get install -y llvm-dev libclang-dev clang
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/license.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The framework that allows us to write PHP extensions using pure and safe Rust wh

### Necessary

- **rust** 1.74 or later
- **rust** 1.75 or later
- **libclang** 14.0 or later
- **php** 8.1 or later

Expand All @@ -35,13 +35,13 @@ The framework that allows us to write PHP extensions using pure and safe Rust wh
- [x] 8.3
- **mode**
- [x] nts
- [ ] ~~zts~~
- [ ] zts
- **sapi**
- [x] cli
- [x] fpm
- **debug**
- [x] disable
- [ ] ~~enable~~
- [ ] enable

## Examples

Expand Down
27 changes: 13 additions & 14 deletions phper-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{env, ffi::OsStr, fmt::Debug, path::PathBuf, process::Command};
fn main() {
println!("cargo:rerun-if-env-changed=PHP_CONFIG");
let current_dir = std::env::current_dir().unwrap();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

let c_files = std::fs::read_dir(current_dir.join("c"))
.unwrap()
Expand All @@ -24,17 +25,14 @@ fn main() {
c_files
.iter()
.for_each(|file| println!("cargo:rerun-if-changed={}", file));
println!("cargo:rustc-link-search={}", out_path.to_str().unwrap());
println!("cargo:rustc-link-lib=static=phpwrapper");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let php_config = env::var("PHP_CONFIG").unwrap_or_else(|_| "php-config".to_string());

let includes = execute_command(&[php_config.as_str(), "--includes"]);
let includes = includes.split(' ').collect::<Vec<_>>();

// Generate libphpwrapper.a.

println!("cargo:warning={:?}", includes);
println!("cargo:warning={:?}", c_files);
let mut builder = cc::Build::new();

includes.iter().for_each(|include| {
Expand All @@ -43,18 +41,19 @@ fn main() {

builder
.cpp(false)
.debug(false)
// .debug(false)
.files(&c_files)
.extra_warnings(true)
// .extra_warnings(true)
.include("include")
.flag("-falign-functions")
.flag("-flto=auto")
.flag("-std=c2x") // Replace with -std=c23 after CLANG 18
.flag("-pedantic")
.force_frame_pointer(false)
.opt_level(3)
// .flag("-falign-functions")
// .flag("-flto=auto")
// .flag("-std=c2x") // Replace with -std=c23 after CLANG 18
// .flag("-pedantic")
// .flag("-Wno-ignored-qualifiers")
// .force_frame_pointer(false)
// .opt_level(3)
.warnings(true)
.use_plt(false)
// .use_plt(false)
.static_flag(true)
.pic(true)
.compile("phpwrapper");
Expand Down
4 changes: 2 additions & 2 deletions phper-sys/c/php_alloc.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <phper.h>

ZEND_FASTCALL void *phper_emalloc(size_t size) {
void *phper_emalloc(size_t size) {
return emalloc(size);
}

ZEND_FASTCALL void phper_efree(void *ptr) {
void phper_efree(void *ptr) {
efree(ptr);
}
60 changes: 25 additions & 35 deletions phper-sys/c/php_array.c
Original file line number Diff line number Diff line change
@@ -1,93 +1,83 @@
#include <phper.h>

ZEND_FASTCALL zval *phper_zend_hash_str_update(HashTable *ht, const char *key,
size_t len, zval *pData) {
zval *phper_zend_hash_str_update(HashTable *ht, const char *key, size_t len,
zval *pData) {
return zend_hash_str_update(ht, key, len, pData);
}

ZEND_FASTCALL zval *phper_zend_hash_index_update(HashTable *ht, zend_ulong h,
zval *pData) {
zval *phper_zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData) {
return zend_hash_index_update(ht, h, pData);
}

ZEND_FASTCALL zval *phper_zend_hash_next_index_insert(HashTable *ht,
zval *pData) {
zval *phper_zend_hash_next_index_insert(HashTable *ht, zval *pData) {
return zend_hash_next_index_insert(ht, pData);
}

ZEND_FASTCALL void phper_array_init(zval *arg) {
void phper_array_init(zval *arg) {
array_init(arg);
}

ZEND_FASTCALL void *phper_zend_hash_str_find_ptr(const HashTable *ht,
const char *str, size_t len) {
void *phper_zend_hash_str_find_ptr(const HashTable *ht, const char *str,
size_t len) {
return zend_hash_str_find_ptr(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_hash_str_exists(const HashTable *ht,
const char *str, size_t len) {
bool phper_zend_hash_str_exists(const HashTable *ht, const char *str,
size_t len) {
return zend_hash_str_exists(ht, str, len) != 0;
}

ZEND_FASTCALL bool phper_zend_hash_index_exists(const HashTable *ht,
zend_ulong h) {
bool phper_zend_hash_index_exists(const HashTable *ht, zend_ulong h) {
return zend_hash_index_exists(ht, h) != 0;
}

ZEND_FASTCALL zend_array *phper_zend_new_array(uint32_t size) {
zend_array *phper_zend_new_array(uint32_t size) {
return zend_new_array(size);
}

ZEND_FASTCALL zend_array *phper_zend_array_dup(zend_array *source) {
zend_array *phper_zend_array_dup(zend_array *source) {
return zend_array_dup(source);
}

ZEND_FASTCALL zval *phper_zend_hash_index_find(const HashTable *ht,
zend_ulong h) {
zval *phper_zend_hash_index_find(const HashTable *ht, zend_ulong h) {
return zend_hash_index_find(ht, h);
}

ZEND_FASTCALL bool phper_zend_hash_index_del(HashTable *ht, zend_ulong h) {
bool phper_zend_hash_index_del(HashTable *ht, zend_ulong h) {
return zend_hash_index_del(ht, h) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_symtable_str_update(HashTable *ht,
const char *str, size_t len,
zval *pData) {
zval *phper_zend_symtable_str_update(HashTable *ht, const char *str, size_t len,
zval *pData) {
return zend_symtable_str_update(ht, str, len, pData);
}

ZEND_FASTCALL bool phper_zend_symtable_str_del(HashTable *ht, const char *str,
size_t len) {
bool phper_zend_symtable_str_del(HashTable *ht, const char *str, size_t len) {
return zend_symtable_str_del(ht, str, len) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_symtable_str_find(HashTable *ht, const char *str,
size_t len) {
zval *phper_zend_symtable_str_find(HashTable *ht, const char *str, size_t len) {
return zend_symtable_str_find(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_symtable_str_exists(HashTable *ht,
const char *str, size_t len) {
bool phper_zend_symtable_str_exists(HashTable *ht, const char *str,
size_t len) {
return zend_symtable_str_exists(ht, str, len) != 0;
}

ZEND_FASTCALL zval *phper_zend_str_update(HashTable *ht, const char *str,
size_t len, zval *pData) {
zval *phper_zend_str_update(HashTable *ht, const char *str, size_t len,
zval *pData) {
return zend_hash_str_update(ht, str, len, pData);
}

ZEND_FASTCALL bool phper_zend_str_del(HashTable *ht, const char *str,
size_t len) {
bool phper_zend_str_del(HashTable *ht, const char *str, size_t len) {
return zend_hash_str_del(ht, str, len) == SUCCESS;
}

ZEND_FASTCALL zval *phper_zend_str_find(HashTable *ht, const char *str,
size_t len) {
zval *phper_zend_str_find(HashTable *ht, const char *str, size_t len) {
return zend_hash_str_find(ht, str, len);
}

ZEND_FASTCALL bool phper_zend_str_exists(HashTable *ht, const char *str,
size_t len) {
bool phper_zend_str_exists(HashTable *ht, const char *str, size_t len) {
return zend_hash_str_exists(ht, str, len) != 0;
}
38 changes: 19 additions & 19 deletions phper-sys/c/php_smart_string.c
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
#include <phper.h>
#include <zend_smart_str.h>

ZEND_FASTCALL void phper_smart_str_alloc(smart_str *str, size_t len,
void phper_smart_str_alloc(smart_str *str, size_t len,
bool persistent) {
smart_str_alloc(str, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_extend_ex(smart_str *dest, size_t len,
void phper_smart_str_extend_ex(smart_str *dest, size_t len,
bool persistent) {
smart_str_extend_ex(dest, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_erealloc(smart_str *str, size_t len) {
void phper_smart_str_erealloc(smart_str *str, size_t len) {
smart_str_erealloc(str, len);
}

ZEND_FASTCALL void phper_smart_str_realloc(smart_str *str, size_t len) {
void phper_smart_str_realloc(smart_str *str, size_t len) {
smart_str_realloc(str, len);
}

ZEND_FASTCALL void phper_smart_str_free_ex(smart_str *str, bool persistent) {
void phper_smart_str_free_ex(smart_str *str, bool persistent) {
smart_str_free_ex(str, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_escaped(smart_str *str, const char *s,
void phper_smart_str_append_escaped(smart_str *str, const char *s,
size_t l) {
smart_str_append_escaped(str, s, l);
}

ZEND_FASTCALL void phper_smart_str_append_double(smart_str *str, double num,
void phper_smart_str_append_double(smart_str *str, double num,
int precision,
bool zero_fraction) {
smart_str_append_double(str, num, precision, zero_fraction);
}

ZEND_FASTCALL void phper_smart_str_append_escaped_truncated(
void phper_smart_str_append_escaped_truncated(
smart_str *str, const zend_string *value, size_t length) {
smart_str_append_escaped_truncated(str, value, length);
}

ZEND_FASTCALL void phper_smart_str_append_scalar(smart_str *str,
void phper_smart_str_append_scalar(smart_str *str,
const zval *value,
size_t truncate) {
smart_str_append_scalar(str, value, truncate);
}

ZEND_FASTCALL void phper_smart_str_0(smart_str *str) {
void phper_smart_str_0(smart_str *str) {
smart_str_0(str);
}

ZEND_FASTCALL size_t phper_smart_str_get_len(const smart_str *str) {
size_t phper_smart_str_get_len(const smart_str *str) {
return smart_str_get_len((smart_str *)str);
}

ZEND_FASTCALL zend_string *phper_smart_str_extract(smart_str *str) {
zend_string *phper_smart_str_extract(smart_str *str) {
return smart_str_extract(str);
}

ZEND_FASTCALL void phper_smart_str_appendc_ex(smart_str *dest, char ch,
void phper_smart_str_appendc_ex(smart_str *dest, char ch,
bool persistent) {
smart_str_appendc_ex(dest, ch, persistent);
}

ZEND_FASTCALL void phper_smart_str_appendl_ex(smart_str *dest, const char *str,
void phper_smart_str_appendl_ex(smart_str *dest, const char *str,
size_t len, bool persistent) {
smart_str_appendl_ex(dest, str, len, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_ex(smart_str *dest,
void phper_smart_str_append_ex(smart_str *dest,
const zend_string *src,
bool persistent) {
smart_str_append_ex(dest, src, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_smart_str_ex(smart_str *dest,
void phper_smart_str_append_smart_str_ex(smart_str *dest,
const smart_str *src,
bool persistent) {
smart_str_append_smart_str_ex(dest, src, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_long_ex(smart_str *dest,
void phper_smart_str_append_long_ex(smart_str *dest,
zend_long num,
bool persistent) {
smart_str_append_long_ex(dest, num, persistent);
}

ZEND_FASTCALL void phper_smart_str_append_unsigned_ex(smart_str *dest,
void phper_smart_str_append_unsigned_ex(smart_str *dest,
zend_ulong num,
bool persistent) {
smart_str_append_unsigned_ex(dest, num, persistent);
}

ZEND_FASTCALL void phper_smart_str_setl(smart_str *dest, const char *src,
void phper_smart_str_setl(smart_str *dest, const char *src,
size_t len) {
smart_str_setl(dest, src, len);
}
Loading

0 comments on commit fbd386f

Please sign in to comment.