Skip to content

Commit e4d88da

Browse files
authored
Merge pull request #4 from mrsuh/arm64-support
Added arm64 support
2 parents 56da8d4 + 5c01fa3 commit e4d88da

File tree

9 files changed

+41
-22
lines changed

9 files changed

+41
-22
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- "8.0"
1717
- "8.1"
1818
- "8.2"
19+
- "8.3"
1920
operating-system:
2021
- "ubuntu-latest"
2122

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
UNAME := $(shell uname -s)
1+
OS := $(shell uname -s)
2+
PLATFORM := $(shell uname -m)
23
HFOLDERS := -I php-src -I php-src/Zend -I php-src/main -I php-src/TSRM -I php-src/ext/spl
3-
COMMAND := @echo Invalid operation system: $(UNAME)
4+
COMMAND := @echo Invalid operation system: $(OS)
45

56
ifeq ($(DEBUG), 1)
67
DEBUGFLAG := -D DEBUG
78
else
89
DEBUGFLAG :=
910
endif
1011

11-
ifeq ($(UNAME), Linux)
12-
COMMAND := g++ -O3 -fPIC -shared $(HFOLDERS) $(DEBUGFLAG) -o library/ffi_linux.so library/ffi.cpp
12+
ifeq ($(OS), Linux)
13+
COMMAND := g++ -O3 -fPIC -shared $(HFOLDERS) $(DEBUGFLAG) -o library/ffi_linux_$(PLATFORM).so library/ffi.cpp
1314
endif
1415

15-
ifeq ($(UNAME), Darwin)
16-
COMMAND := clang -shared -undefined dynamic_lookup $(HFOLDERS) $(DEBUGFLAG) -o library/ffi_darwin.dylib library/ffi.cpp
16+
ifeq ($(OS), Darwin)
17+
COMMAND := clang -shared -undefined dynamic_lookup $(HFOLDERS) $(DEBUGFLAG) -o library/ffi_darwin_$(PLATFORM).dylib library/ffi.cpp
1718
endif
1819

1920
all:

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It doesn't take into calculate the memory of handlers/functions/etc.
1212

1313
### Requirements
1414
* PHP >= 7.4 (with FFI)
15-
* Linux(x86_64) / Darwin(x86_64)
15+
* Linux(x86_64/aarch64) / Darwin(x86_64/arm64)
1616

1717
### How to install
1818
```bash
@@ -104,9 +104,17 @@ docker run -it --rm --name my-running-script -v "$PWD":/app image-php-var-sizeof
104104

105105
### How to compile library
106106
```bash
107+
git submodule update --init --recursive
107108
cd php-src
108109
./buildconf
109-
./configure
110+
./configure --with-ffi --with-iconv=/opt/homebrew/opt/libiconv
110111
cd ..
111112
make DEBUG=1
112113
```
114+
115+
```bash
116+
docker build -t php-var-sizeof -f Dockerfile-compile .
117+
docker run -it -v $(pwd)/library:/code/library php-var-sizeof bash
118+
cd /code
119+
make DEBUG=1
120+
```

library/ffi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "zend_types.h"
2+
3+
int zval_sizeof(zval *zv_ptr);
4+
5+
int zval_class_sizeof(zval *zv_ptr);
6+
7+
int properties_sizeof(zval *srcProperty, int count);
8+
9+
zval *get_zval_by_name(char *name);

library/ffi_darwin_arm64.dylib

50.1 KB
Binary file not shown.
File renamed without changes.

library/ffi_linux_aarch64.so

13 KB
Binary file not shown.
File renamed without changes.

src/VarInfo.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ public static function init(): void
1212
return;
1313
}
1414

15-
if (\php_uname('m') !== 'x86_64') {
16-
throw new \RuntimeException('Unsupported machine type');
17-
}
18-
19-
switch (\php_uname('s')) {
20-
case 'Linux':
21-
$libraryFileName = 'ffi_linux.so';
22-
break;
23-
case 'Darwin':
24-
$libraryFileName = 'ffi_darwin.dylib';
25-
break;
26-
default:
27-
throw new \RuntimeException('Unsupported operating system');
15+
$platform = strtolower(\php_uname('m'));
16+
$operatingSystem = strtolower(\php_uname('s'));
17+
18+
$libraryFilePath = sprintf(
19+
"%s/../library/ffi_%s_%s.%s",
20+
__DIR__,
21+
$operatingSystem,
22+
$platform,
23+
$operatingSystem === 'linux' ? 'so' : 'dylib'
24+
);
25+
26+
if(!is_file($libraryFilePath)) {
27+
throw new \RuntimeException(sprintf('Unsupported system "%s(%s)"', $operatingSystem, $platform));
2828
}
2929

3030
self::$libc = \FFI::cdef(
3131
"
3232
int var_sizeof(char *name);
3333
int var_class_sizeof(char *name);
3434
",
35-
__DIR__ . "/../library/" . $libraryFileName);
35+
$libraryFilePath);
3636
}
3737

3838
/**

0 commit comments

Comments
 (0)