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

Support extensions written in Rust? #26

Open
cmb69 opened this issue Aug 4, 2024 · 13 comments
Open

Support extensions written in Rust? #26

cmb69 opened this issue Aug 4, 2024 · 13 comments
Assignees
Labels
enhancement New feature or request maintainer investigating This ticket is being investigated by maintainers. Please check with us before contributing PRs etc!

Comments

@cmb69
Copy link
Member

cmb69 commented Aug 4, 2024

There is some discussion about PECL extensions written in Rust on the PECL mailing list (https://news-web.php.net/php.pecl.dev/17600 ff), but so far without any consensus. Since @derickr said:

For the new PECL installer (PIE, https://github.com/php/pie) supporting this "style" hasn't been taken under consideration.

So maybe it's a good idea to consider this?

@asgrim
Copy link
Collaborator

asgrim commented Aug 4, 2024

If a Rust ext uses phpize && ./configure && make && make install, it will work with PIE. If not, it's something we can certainly consider! Do we have any examples of Rust exts?

@cmb69
Copy link
Member Author

cmb69 commented Aug 4, 2024

https://pecl.php.net/package/skywalking is already on PECL (and there may be more), and https://github.com/genkgo/php-ext-fs-notify has requested to be added to PECL. Note that both extensions use https://github.com/phper-framework/phper.

The problem is not necessarily that these extensions don't support phpize && ./configure && make && make install, but rather that they require to have a Rust/Cargo environment already available. If you do something like pecl install skywalking that likely fails on the usual servers (which have C build environment, but none for Rust).

If an extension written in Rust would support Windows (I'm not aware of any), that might also be an issue for https://github.com/php/php-windows-builder.

Anyway, I don't necessarily suggest that there needs to be full Rust build support in PIE, but rather that there is some information in the schema (maybe just rough, or maybe more thorough), and maybe that this is checked before even downloading and trying to install such extensions.

@johannes
Copy link
Member

johannes commented Aug 4, 2024

I don't know much about pie, but I would suggest to try being agnostic to the build system. Even for C (or C++) extensions there is some value in CMake or other build systems. (Better cross platform support, tooling support, some libraries one was TA to wrap might use CMake or other as their primary system etc )

@derickr
Copy link
Member

derickr commented Aug 5, 2024

I don't think pie currently first checks for a working C compilation set-up. At least, PECL never used to do that. So although "pie" doesn't take a working rust build system under consideration, it is no different than checking for a working C build system.

So I guess that that could be the real question here — whether it should check for a working build environment?

I don't think PIE should first check for a working build (C/Rust) environment, as there will be way too many permutations. config.m4 is the place for that — and I suppose there could be a new provided check for this — perhaps initially for Rust — so that not everybody will have to write these on their own, but this issue (or repository) is the place for that discussion.

@cmb69
Copy link
Member Author

cmb69 commented Aug 5, 2024

So I guess that that could be the real question here — whether it should check for a working build environment?

Not necessarily. In my opinion it would be sufficient to have some information in the schema. Not sure if https://github.com/ThePHPF/pie-design/blob/main/composer-json-php-ext-schema.json is up-to-date, but it could be added there (or whereever), so users (not necessarily PIE) could check that in advance. Maybe there could even be a PIE (sub-)command to list these requirements (perhaps something like pie build-info <package>).

@asgrim asgrim added the question Further information is requested label Aug 5, 2024
@asgrim
Copy link
Collaborator

asgrim commented Aug 5, 2024

It's certainly something that could be considered as an enhancement at some point, but for the initial iteration lets try and keep it simple 😁

@cmb69
Copy link
Member Author

cmb69 commented Aug 5, 2024

At the very least, it appears sensible to me to add some info to the schema right away; maybe similar to "support-zts" (which, by the way, does not really cater to extensions which require ZTS, like PECL/parallel).

@frederikbosch
Copy link

Later this month, I am going to publish the fs-notify extension, and I will test if it works with PIE too. If not, I'll try to come up with a PR.

@shivammathur
Copy link
Member

@cmb69
php-windows-builder supports this by reading the PATH_PROG calls in config.w32.

For example in dd-trace extension, cargo is required.
https://github.com/DataDog/dd-trace-php/blob/master/config.w32#L5
https://github.com/shivammathur/php-windows-builder/actions/runs/10751274987/job/29818375901

@cmb69
Copy link
Member Author

cmb69 commented Sep 17, 2024

php-windows-builder supports this by reading the PATH_PROG calls in config.w32.

Ah, nice! :)

@Xenira
Copy link

Xenira commented Feb 7, 2025

Hey, I am a maintainer over at ext-php-rs. If you need any input let me know.

From my experience the best way to build the extensions is using Docker, as you can fully control the build environment.
But that would mean you need to setup the image with the correct environment for the target.

If you want to build directly you need php-dev , bison, re2c and libclang-dev iirc. And cargo of course.

@asgrim asgrim added maintainer investigating This ticket is being investigated by maintainers. Please check with us before contributing PRs etc! enhancement New feature or request and removed question Further information is requested labels Mar 4, 2025
@Xenira
Copy link

Xenira commented Mar 4, 2025

Using the config.m4 i managed to install a rust extension if the dependencies are present.

Basicly writing build steps into the Makefile.objects. The build step just calls cargo build and copies the result into the $phplibdir.

Would probably be easier if it would be possible to just define a custom make script but totally doable as is.

Thanks to @brettmc for helping me on this.

@asgrim
Copy link
Collaborator

asgrim commented Mar 11, 2025

Essentially, PIE does phpize && ./configure && make && make install; the phpize is necessary to setup the right PHP version/paths etc., the rest of the steps are fairly standard; if the rust exts can act accordingly for those steps, then they can work out the box.

If this isn't suitable, we would need to spec out exactly what Rust exts would need to do going forward, and ensure it is fully portable etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maintainer investigating This ticket is being investigated by maintainers. Please check with us before contributing PRs etc!
Projects
None yet
Development

No branches or pull requests

7 participants