From 5830d56f227c80b4634b770b25a9848df5388452 Mon Sep 17 00:00:00 2001 From: Mirko Galimberti Date: Sat, 26 Mar 2022 13:57:26 +0100 Subject: [PATCH] Improved Apple Silicon support (variadic functions) + add tests on apple-silicon-m1 (self hosted runner) (#85) * Add tests on apple-silicon-m1 (Self hosted runner) * Remove (unnecessary?) dylib and fix Makefile to build them as universal2 * Fixes variadic function call on ARM64 * IMP*(void*, SEL, ...) is failing on Apple Silicon but is not our fault * ffi_prep_cif_var should be guarded via __builtin_available(macOS 10.15, *) * On iOS we're using a non-apple version of ffi that should support ffi_prep_cif_var --- .ci/osx_ci.sh | 13 ++++++++++ .github/workflows/python-package.yml | 33 ++++++++++++++++++++++---- Makefile | 5 ++-- objc_classes/test/CArrayTestlib.dylib | Bin 42440 -> 0 bytes objc_classes/test/testlib.dylib | Bin 31000 -> 0 bytes objc_classes/test/testlib.m | 14 ++++++++++- pyobjus/_runtime.h | 20 +++++++++++++++- pyobjus/common.pxi | 6 ++--- pyobjus/pyobjus.pyx | 17 ++++++++++--- 9 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 .ci/osx_ci.sh delete mode 100755 objc_classes/test/CArrayTestlib.dylib delete mode 100755 objc_classes/test/testlib.dylib diff --git a/.ci/osx_ci.sh b/.ci/osx_ci.sh new file mode 100644 index 0000000..8cdd1ac --- /dev/null +++ b/.ci/osx_ci.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e -x + +arm64_set_path_and_python_version(){ + python_version="$1" + if [[ $(/usr/bin/arch) = arm64 ]]; then + export PATH=/opt/homebrew/bin:$PATH + eval "$(pyenv init --path)" + pyenv install $python_version -s + pyenv global $python_version + export PATH=$(pyenv prefix)/bin:$PATH + fi +} \ No newline at end of file diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a95f556..53a56e6 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -5,25 +5,48 @@ on: [push, pull_request] jobs: build: - runs-on: macOs-latest + name: "build (${{ matrix.runs_on }}, ${{ matrix.python }})" + defaults: + run: + shell: ${{ matrix.run_wrapper || 'bash --noprofile --norc -eo pipefail {0}' }} + runs-on: ${{ matrix.runs_on || 'macos-latest' }} strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] - + include: + - runs_on: macos-latest + python: "3.7" + - runs_on: macos-latest + python: "3.8" + - runs_on: macos-latest + python: "3.9" + - runs_on: macos-latest + python: "3.10" + - runs_on: apple-silicon-m1 + run_wrapper: arch -arm64 bash --noprofile --norc -eo pipefail {0} + python: "3.9.11" + - runs_on: apple-silicon-m1 + run_wrapper: arch -arm64 bash --noprofile --norc -eo pipefail {0} + python: "3.10.3" steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python }} + # Needs to be skipped on our self-hosted runners tagged as 'apple-silicon-m1' + if: ${{ matrix.runs_on != 'apple-silicon-m1' }} uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.python }} - name: Install project run: | + source .ci/osx_ci.sh + arm64_set_path_and_python_version ${{ matrix.python }} pip install cython pytest pip install . - name: Test with pytest run: | + source .ci/osx_ci.sh + arm64_set_path_and_python_version ${{ matrix.python }} make test_lib make make tests diff --git a/Makefile b/Makefile index 68521bb..ee7255b 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,9 @@ build_ext: env CFLAGS="-O0" python setup.py build_ext --inplace -g test_lib: - rm -rf objc_classes/test/usrlib.dylib - clang objc_classes/test/testlib.m -o objc_classes/test/testlib.dylib -dynamiclib -framework Foundation + rm -rf objc_classes/test/testlib.dylib objc_classes/test/CArrayTestlib.dylib + clang objc_classes/test/testlib.m -o objc_classes/test/testlib.dylib -dynamiclib -framework Foundation -arch arm64 -arch x86_64 + clang objc_classes/test/CArrayTestlib.m -o objc_classes/test/CArrayTestlib.dylib -dynamiclib -framework Foundation -arch arm64 -arch x86_64 tests: build_ext cd tests && env PYTHONPATH=..:$(PYTHONPATH) python -m pytest -v diff --git a/objc_classes/test/CArrayTestlib.dylib b/objc_classes/test/CArrayTestlib.dylib deleted file mode 100755 index 8220e7ad075cde956514ce96528363d994210d1e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 42440 zcmeHQdw5jUwLgQPQNhG_z}Lt_5hV!-6r<>bBseHwAV6sqCX>vBj3zU2W`aD74Hc*% z!cD)ct*zE#Z)>eq8+)-ISFJbH2h?Y%FRIo?MQ^ZZ0kx%S;jXp!TIcLJXP4O(&8|Nx)v;+b@=kC&?aTcY7kfy2fZGg8|y@ zEh>|m$B_ZXKK8J_*%i&s`qq=Zcd(;DVJwlZzAecc63JL3k*rUFkUhT3E2UBVlZ?Hf{@>x)>m2e~Lv4YIu!m{!oD-QF!Wdx%wgU`uB& z7R^S58@s(uvPac65Zmmj;X(cC>eY$GZm*Z@^-?E8>}^lyAkGo8-no z>}78_$l(}|L}tyLb7f`4Og;uRlYtOz32&!)8vAg7ShyJmpAdWs;Unqz9WaVpGU?*R zR9&>OxG_;%Twaz=M_0^`XR?5bVk_Vq#Gs5cjJ6Wo0Y4Z|7`8o#sT5uh^8xI)!L|yv z*k{q#a%hHi;3}`fFuF$=#<4&{K9&_g#}CS`f-Umg%FgwMF;v4m4QS}+2ix1eXuR#> z_ntW6hxh#|+SN50Xay*r2Qv+P#xX`36tuMnKB$ZS4dX=kKzmfL$YkS9#j_H%>1cXI z@eG_YZ%C!D%M_QV>Qd1nF^3|dcws!9Nx--(E|V-_1?|?r$Fy7UFr@c_fQQ`~sg@-4 zXE3ERUS4eR!7kdLs@gYp0pdJD1|ehE1B=Sk>}m9l_=Q7HR=sGts)_zEuV#Ht=!53^ zo_9N?<5tYNI$?vUGGHH1doW);(0`g?dmiDC97e|Z3dZ^mlz|o)Xn}zi7-)fitrl1i zZht>~^PW(6L*;?+hS|O0_SOU8_LjZjj+O)AZIuTwTEM;Gj>$(~A$I#<_ir05+G+ADi^ z<6%uv6T-vB3gPWgdlU}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mv`kfFGz;(HYswVQj@DgO zy{M>}2#QQ~#g)vSP*OCtC=8XPgJZ!vV% zNWALItdoZH z?kv8KE9;%ddQTQ#>&RmJ_`!gzcPKk;iP<+t$SFfJr)kDt!Y3$xKb+UZmMf!mnJePs zQ>-xYa;OMsy(xSzS2=I)bQ*%Al=+TledbNJQyCIra=l^zC(0|K^==dats{kRxzd<& zzGT{I4&s?1-b3xx{;Gu21XNuWutIW*f;aU&)S8&Vm@45kVG~fj&wZ7U zlEgw|yl1rNoPt;ceR5P{c; z^4rcmq~Oh_we%u%52<9vd`G(dtn~0NTUoZt)Cq4QJ(BeDQ zq1`REI{DcXM1Cw`cVCu_t3OM`$ER}MuXm^jXuT?JT_;|C<{Pn&p zzSfh)_Vc5h^}BddB=o)%0Y7h6VqKhB0(xH-zdx=lX%Bankh@Du#?LLDL3^FtEU*Oh z?kv8KE9=Z(Upb4fb!4%9{9r)l8NbHWz=Z?eki`GcpgR}Mi|6Mo? zocyntFYo0S4V?Vr|Dy6cum2Z6`Inan<@Bsk&NZ$7<*6MUqC36iJ{yOyqdd$uRyG)jF^~ diff --git a/objc_classes/test/testlib.dylib b/objc_classes/test/testlib.dylib deleted file mode 100755 index ad74c2087ac385411797945ea00a6d829e005c39..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 31000 zcmeHwdw5*MmFJbQK^POYjZMtE5jGgd581JaaS(1+pV^f@O}GFE^bwwU;XOTsZ)g znB$y-PZJWO(VFm<8Utnismc@`%FyXd!DlLyqtVXTuFf>qudn+vHtnYu+EC=lX}SpA zUNIW&=?c0B)&8cmw@(J{beVw}#+4kK} zeOJ;xl_%EM)p~QhwILdBZEOR{Z{N$SY|aQ3sI2<@VKf?RiZ-^3>&)fX7Ytc^tjLBU z=WAaXXM<*(ttqQ1vw6&49ba}hIy$~MJRKQlqW27DiAGzSqaC|jwzoA$6P@j-XKsC} zPV{;05_hUDQ5lUk*X7d}pnY3dzQ|sEV&9oelYsrs^poazN2lMuCh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)|pdH z$Y6UMNE?)z+{*fW<|u$&dk z0vqK7W)>>coOE*@Gm9?AGBZFqlbHqZf!0}Q7&Ma;2Cdu~-T%4~;jpdx1&AZ{iy zHf>Oj0GTrZb6GGWqp?Ucl9p+unQplg<|FC`S%yZQh4oSOgsj4%l?P=NV(I#e0169J z&NZn_nn0Q5%FjmlNcNzuf}$z?lLCrTUpgUEE9PA}%<5+o&fprqp-20;3TJSmdQjI# zcJbV7IkG!Z4s)DW6HQ(1yze#Nz~*?b61DpF%&!mS(ci6(-2hv6UD+n=i{hTLDElz5 z**eW)h@Z^q;JnG^xNue(Vk|m(cHvCG@$H;>Y&XxHW*Q@RlJ@4@sqDbH6ZOb ***********************/ /******************** ***********************/ diff --git a/pyobjus/_runtime.h b/pyobjus/_runtime.h index cb59157..c31b7ba 100644 --- a/pyobjus/_runtime.h +++ b/pyobjus/_runtime.h @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -52,4 +53,21 @@ id objc_msgSend_custom(id obj, SEL sel){ } bool MACOS_HAVE_OBJMSGSEND_STRET = false; -#endif \ No newline at end of file +#endif + + ffi_status guarded_ffi_prep_cif_var(ffi_cif *_Nonnull cif, ffi_abi abi, unsigned int nfixedargs, + unsigned int ntotalargs, ffi_type *_Nonnull rtype, ffi_type *_Nonnull *_Nonnull atypes) + { + if (ntotalargs > nfixedargs) + { + #if TARGET_OS_OSX + if (__builtin_available(macOS 10.15, *)) + { + return ffi_prep_cif_var(cif, abi, nfixedargs, ntotalargs, rtype, atypes); + } + #elif TARGET_OS_IOS + return ffi_prep_cif_var(cif, abi, nfixedargs, ntotalargs, rtype, atypes); + #endif + } + return ffi_prep_cif(cif, abi, ntotalargs, rtype, atypes); + } \ No newline at end of file diff --git a/pyobjus/common.pxi b/pyobjus/common.pxi index beca5bb..3a17bbb 100644 --- a/pyobjus/common.pxi +++ b/pyobjus/common.pxi @@ -148,9 +148,6 @@ cdef extern from "ffi/ffi.h": cdef ffi_type ffi_type_longdouble cdef ffi_type ffi_type_pointer - cdef ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, - unsigned int nargs,ffi_type *rtype, ffi_type **atypes) - cdef void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue) @@ -161,3 +158,6 @@ cdef extern from "_runtime.h": id objc_msgSend_custom(id obj, SEL sel) void objc_msgSend_stret__safe(id self, SEL selector, ...) bool MACOS_HAVE_OBJMSGSEND_STRET + ffi_status guarded_ffi_prep_cif_var(ffi_cif *cif, ffi_abi abi, + unsigned int nfixedargs, unsigned int ntotalargs, + ffi_type *rtype, ffi_type **atypes) \ No newline at end of file diff --git a/pyobjus/pyobjus.pyx b/pyobjus/pyobjus.pyx index 4e39414..4dfda18 100644 --- a/pyobjus/pyobjus.pyx +++ b/pyobjus/pyobjus.pyx @@ -294,6 +294,7 @@ cdef class ObjcMethod(object): # casting is needed here because otherwise we will get warning at compile cdef unsigned int num_args = len(signature_args) + cdef unsigned int num_fixed_args = len(self.signature_args) cdef unsigned int size = sizeof(ffi_type) * num_args # allocate memory to hold ffi_type* of arguments @@ -317,8 +318,17 @@ cdef class ObjcMethod(object): # FFI PREP cdef ffi_status f_status - f_status = ffi_prep_cif(&self.f_cif, FFI_DEFAULT_ABI, - num_args, self.f_result_type, self.f_arg_types) + + f_status = guarded_ffi_prep_cif_var( + &self.f_cif, + FFI_DEFAULT_ABI, + num_fixed_args, + num_args, + self.f_result_type, + self.f_arg_types, + ) + + if f_status != FFI_OK: raise ObjcException( 'Unable to prepare the method {0!r}'.format(self.name)) @@ -348,7 +358,8 @@ cdef class ObjcMethod(object): cdef size_t result_size = int(self.signature_return[1]) # check that we have at least the same number of arguments as the - # signature want. + # signature want (having more than expected could signify that the called + # function is variadic). if len(args) < len(self.signature_args) - 2: raise ObjcException('Not enough parameters for {}'.format( self.name))