Skip to content

add pqcrypto (rust) extension - #1331

Open
henderkes wants to merge 7 commits into
v3from
feat/pqcrypto
Open

henderkes wants to merge 7 commits into
v3from
feat/pqcrypto

Conversation

@henderkes

Copy link
Copy Markdown
Collaborator

What does this PR do?

closes #1329
prepares static-php/packages#32

  • drops rust toolchain (problems in php-ext-rs requiring bindgen and other things, we could set plenty of paths ourselves, but it's not worth it over just requiring rust - they only build on host for host anyways...)
  • doctor command for rust toolchain
  • add ext-pqsql

Checklist before merging

  • If you modified *.php or *.yml, run them locally to ensure your changes are valid:
    • composer cs-fix
    • composer analyse
    • composer test
    • bin/spc dev:lint-config

@henderkes
henderkes requested review from crazywhalecc and an adaptive review from Copilot December 4, 2026 10:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Rust check accepts compilers below pqcrypto’s required rustc 1.85, allowing false success while Cargo builds remain impossible, and the macOS linker-default documentation is outdated.

2 open issues
What changed in this PR

Adds pqcrypto shared-extension support using host Rust tools and disables macOS dead stripping to retain symbols needed by shared extensions, addressing #1329.

Changes:

  • Adds pqcrypto packaging and a reusable Cargo build executor.
  • Replaces managed Rust downloads with optional doctor checks and installation.
  • Updates bilingual documentation and macOS linker defaults.
File Description
src/​StaticPHP/​Runtime/​Executor/​UnixCargoExecutor.php Adds Cargo release builds.
src/​StaticPHP/​Doctor/​Item/​RustCheck.php Checks and installs Rust prerequisites.
src/​StaticPHP/​Command/​DoctorCommand.php Adds --with-rust.
src/​Package/​Extension/​pqcrypto.php Validates and builds pqcrypto.
src/​Package/​Artifact/​rust.php Removes managed Rust downloads.
docs/​zh/​guide/​cli-reference.md Documents the Rust option in Chinese.
docs/​zh/​develop/​system-build-tools.md Documents Cargo builds in Chinese.
docs/​zh/​develop/​package-model.md Replaces the Rust-specific example.
docs/​zh/​develop/​doctor-module.md Documents optional Rust checks.
docs/​en/​guide/​cli-reference.md Documents the Rust option in English.
docs/​en/​develop/​system-build-tools.md Documents Cargo builds in English.
docs/​en/​develop/​package-model.md Replaces the Rust-specific example.
docs/​en/​develop/​doctor-module.md Documents optional Rust checks.
config/​pkg/​target/​rust.yml Removes the managed Rust target.
config/​pkg/​ext/​ext-pqcrypto.yml Registers the shared-only extension.
config/​env.ini Disables default macOS dead stripping.

Review effort: Balanced (adaptive)

Comment thread src/StaticPHP/Doctor/Item/RustCheck.php Outdated
Comment on lines +34 to +36
return $missing === []
? CheckResult::ok()
: CheckResult::fail('Missing Rust tools: ' . implode(', ', $missing), 'install-rust');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a rustc >= 1.85.0 check with manual upgrade guidance for outdated or unrecognized versions; installRust() now returns false when the toolchain remains unsupported. Commit: 4f6edd44.

Comment thread config/env.ini
SPC_DEFAULT_CFLAGS="--target=${MAC_ARCH}-apple-darwin -O3 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffunction-sections -fdata-sections"
SPC_DEFAULT_CXXFLAGS="${SPC_DEFAULT_CFLAGS}"
SPC_DEFAULT_LDFLAGS="-Wl,-dead_strip"
SPC_DEFAULT_LDFLAGS=""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both performance pages to describe the macOS default and why symbols referenced by dynamically loaded shared extensions must be retained. Commit: 4f6edd44.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@ptondereau

Copy link
Copy Markdown

Thanks for this!

FYI, ext-php-rs can link statically into php-src to mainly avoid shared-only extensions (doc).

Didn't test but running something like:

EXT_PHP_RS_STATIC_EXT=1 cargo rustc --lib --locked --release --crate-type staticlib
cargo php static-glue --lib-name pqcrypto

and then copy pqcrypto/ and libpqcrypto.a into ext/pqcrypto and add --enable-pqcrypto

It should work on static musl builds, and it could solve the symbols resolve problem at link time.

The only downside is it needs a first PHP build (cli+php-config+headers) with the same version, ZTS, debug mode, and extension linking for each of these variants

@henderkes

Copy link
Copy Markdown
Collaborator Author

pqcrypto requires ZTS? It built fine on NTS for me in testing, but I've not really used it.

Thank you for the hint about static linkage, I'll work on that.

@ptondereau

Copy link
Copy Markdown

pqcrypto requires ZTS? It built fine on NTS for me in testing, but I've not really used it.

Thank you for the hint about static linkage, I'll work on that.

nop, my bad, it supports nts+zts+debug 8.1 to 8.6

@henderkes henderkes added the need-test This PR has not been tested yet, cannot merge now label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

StaticPHP Test Bot

Detected: Extensions: pqcrypto | Libraries: none | Targets: php, rust
Active labels: none
Available labels: need-test (gate), test/linux test/windows test/macos (platform), test/tier2 (extra arch), test/php-83 test/php-84 test/php-86 (PHP version), sapi/frankenphp (extra FrankenPHP SAPI build)
Config: Linux x86_64 + Windows x86_64 + macOS arm64 | PHP 8.5 NTS

@henderkes henderkes changed the title Feat/pqcrypto add pqcrypto (rust) extension Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-test This PR has not been tested yet, cannot merge now

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS builds strip ZEND_API symbols that shared extensions need (zend_vm_call_opcode_handler)

4 participants