Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use custom php-extension inside pib? #24

Open
kaineer opened this issue May 6, 2019 · 12 comments
Open

Can I use custom php-extension inside pib? #24

kaineer opened this issue May 6, 2019 · 12 comments

Comments

@kaineer
Copy link

kaineer commented May 6, 2019

Usual way to use extension with php is to copy compiled extension into extension_dir and then adding extension=ext-name.o to php.ini.

Is there any way to include some custom extension into pib bundle?

I'm just started to learn something about emacsen, so I yet can't figure solution by myself.

@oraoto
Copy link
Owner

oraoto commented May 6, 2019

Sorry, I don't have much time to investigate loading a extension dynamically from network or filesystem. Currently the only tested way to use php extension is to static link it into the binary.

@kaineer
Copy link
Author

kaineer commented May 7, 2019

Static linking would be ok. But is it possible for php extensions? Where can I read about it?

@oraoto
Copy link
Owner

oraoto commented May 7, 2019

A simple extension demo is add: a5f47e7

Explanation:

  1. Symbolic link (or copy) the extension source into php's ext folder

    ln -rsfv ext-example $PHP_PATH/ext
  2. Run buildconf --force to re-generate configs

    # Install
    apt-get update
    apt-get install -y autoconf
    ./buildconf --force
  3. Enable the extension in configure

    emconfigure ./configure --
      --disable-all \
      --disable-cgi \
      --disable-cli \
      --disable-rpath \
      --disable-phpdbg \
      --with-valgrind=no \
      --without-pear \
      --without-pcre-jit \
      --with-layout=GNU \
      --enable-embed=static \
      --enable-bcmath \
      --enable-json \
      --enable-ctype \
      --enable-mbstring \
      --disable-mbregex \
      --enable-tokenizer \
      --enable-example
  4. Build it as usual. For the latest emscripten, this step fails.

@oraoto
Copy link
Owner

oraoto commented May 8, 2019

With today's latest emscripten, it compiles and runs

@kaineer
Copy link
Author

kaineer commented May 8, 2019

Great :) Thank you.
I'll try this.

@kaineer
Copy link
Author

kaineer commented May 8, 2019

Updated emscripten to 1.38.31 and got bunch of errors like:

error: asm2wasm seeing an invalid argument type at index 1 (this will not validate) in call from $__php_s
tream_fopen_from_fd to $_lseek (this is likely due to undefined behavior in C, like defining a function $
ne way and calling it in another, which is important to fix)

Did you use 1.38.31 version, or some more later one?

@kaineer
Copy link
Author

kaineer commented May 8, 2019

After switching to php-7.3.0, both functions from example extension became available, yay :)
Thanks again :)

@oraoto
Copy link
Owner

oraoto commented May 8, 2019

I build the example using docker image trzeci/emscripten:sdk-incoming-64bit.

@kaineer
Copy link
Author

kaineer commented May 9, 2019

Oh, now I see. Fortunately, emacsen 1.38.31 was enough for me.

@kaineer
Copy link
Author

kaineer commented May 13, 2019

Good. First part of my problem is solved :)

But, there's second one :-/
I need to call Javascript function from my extension.

Samples that I've found use something like extern functionName(); notation and then just call that function. It seems like in php-extension I should use something else.

Didn't find anything useful in google, though. Perhaps, I don't know what to search for.

@oraoto
Copy link
Owner

oraoto commented May 13, 2019

You can call javascript functions using emacripten's emscripten_run_script.

@seanmorris
Copy link
Contributor

@kaineer I did it when I created vrzno. If you're still interested let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants