Skip to content

Mobile bundles, signing, and two phar fixes that also affect desktop - #7

Merged
simonhamp merged 3 commits into
mainfrom
mobile-bundles
Nov 19, 2026
Merged

simonhamp merged 3 commits into
mainfrom
mobile-bundles

Conversation

@simonhamp

@simonhamp simonhamp commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Gets Parcel bundles working for NativePHP Mobile, and fixes two bugs that also affect desktop bundles.

Bugs that affect desktop too

Migrations and discovered event listeners go missing. PHP's glob() only reads the real filesystem, so under a phar:// path it returns nothing, with no error. Laravel's migrator and event discovery both use it. The compactor now rewrites global glob() calls to \nativephp_glob() (in box-helper.php), which walks the phar with scandir() and does its own pattern matching. Outside a phar it just calls glob(). It handles GLOB_BRACE, GLOB_ONLYDIR, GLOB_MARK, GLOB_NOSORT, GLOB_NOCHECK and GLOB_NOESCAPE, and it doesn't use fnmatch() because PHP built for iOS doesn't have it. The rewrite works on tokens, so methods named glob (like Filesystem::glob()) are left alone.

None of the app's config files load. The compactor returned early for LoadConfiguration.php, SplFileInfo.php and BladeIconsServiceProvider.php, so the general realpath() rewrite never ran on them. LoadConfiguration::getConfigurationFiles() then called the real realpath() on the config path inside the phar, got false, and returned no files. The app ran on framework and package defaults. I suspect desktop got away with it because Bifrost runs php artisan optimize before bundling, but anything that rebuilds the config cache from inside the bundle would hit it. The special cases now add to the general rewrites.

After both fixes, booting the same app as plain files and as a phar gives the same config, routes, providers and event listeners. The one difference left is a trailing slash on view paths, which nativephp_rp() adds to directories.

Mobile

parcel prepare --mobile sets up an app that mobile-air's native:build has staged. That copy has no artisan, so it looks for bootstrap/app.php instead. The mobile Box config:

  • takes the whole staged app except public/, storage/ and .env, which stay beside the bundle on the device
  • leaves the app's own autoloader alone (dump-autoload: false). Box's dump is --no-dev, which breaks debug builds whose package manifest lists dev providers
  • writes build/__nativephp_app_bundle.phar. The device opens files inside it by phar:// path, and PHP can only find where the archive ends in such a path if its file name has an extension.

parcel sign <bundle> --project=<id> signs with ECDSA P-256, the scheme Bifrost already uses for OTA releases. The message follows the OTA one: nativephp-parcel-bundle-v1, the project, the bundle's SHA-256 and its size, one per line. Binding the project lets Bifrost's single key sign for every app without a bundle from one running in another.

  • With PARCEL_SIGNING_URL and PARCEL_SIGNING_TOKEN set, Parcel sends only the project, hash and size to that endpoint and Bifrost signs. The private key never has to be on the build machine.
  • Otherwise it signs with a local PEM key in PARCEL_SIGNING_KEY (named by PARCEL_SIGNING_KEY_ID, default local), for testing.
  • Either way the signature is checked against the returned public key before it's written. The .sig is JSON with the key id and a base64 DER signature, and --public-key-output writes {key id: public key} for the build to embed in the app.

This adds ext-openssl to the requirements.

Testing

Unit tests cover the glob helper against a real phar (including a run with fnmatch disabled), the compactor rewrites, the mobile stubs, and signing both locally and through a stand-in for Bifrost's endpoint (tests/Fixtures/signing-server.php under php -S). 65 pass. I didn't run the Feature suite, which clones kitchen-sink from GitHub.

End to end: the mobile-air side (NativePHP/mobile-air#707) built devnull-mobile with this, and it ran on an iOS simulator from a signed 12.5 MB phar. The normal debug build's app.zip is 64 MB. A release build, without dev packages, comes out at 7.5 MB.

For review

  • nativephp_rp() never returns false and doesn't resolve .., unlike realpath(). The compactor swaps it in across all of vendor, so any package that relies on realpath() returning false, or uses it to block path traversal, behaves differently inside a bundle. That was already true before this PR; I didn't find a case in devnull's dependencies, but it's worth keeping in mind.
  • Desktop bundles keep the old box.json and GPG signing. Nothing changes for them except the two fixes above.

🤖 Generated with Claude Code

simonhamp and others added 2 commits November 18, 2026 03:02
Two things go quietly missing when a Laravel app runs from a bundle.

glob() only reads the real filesystem, so under a phar:// path it returns
nothing. Laravel finds migrations and discovers event listeners with it,
so a bundled app ran no migrations and registered no discovered listeners.
The compactor now points global glob() calls at nativephp_glob(), which
walks the phar with scandir() and matches names itself. It doesn't use
fnmatch(), because PHP built for iOS doesn't have it. Methods called glob,
like Filesystem::glob(), are left alone.

The compactor also returned early for LoadConfiguration, SplFileInfo and
BladeIconsServiceProvider, so the general realpath() rewrite never ran on
them. LoadConfiguration then called the real realpath() on the config
path inside the phar, got false, and loaded none of the app's config
files. The special cases now add to the general rewrites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parcel prepare --mobile` sets up an app staged by NativePHP Mobile's
native:build, which has no artisan file. Its Box config takes the whole
staged app except public/, storage/ and .env, which stay outside the
bundle on the device, and keeps the app's own autoloader so debug builds
with dev packages still boot. The output is named
__nativephp_app_bundle.phar: the device opens files inside it by
phar:// path, and PHP can only find the end of the archive in such a path
when the file name has an extension.

`parcel sign <bundle>` writes a detached Ed25519 signature over
"nativephp.parcel-bundle.v1:" and the bundle's SHA-256. The key comes
from PARCEL_SIGNING_KEY so it never shows in a process list, and
--public-key-output writes the public key for the build to embed in the
app. Ed25519 because iOS can check it with CryptoKit; it can't check GPG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parcel sign` now uses ECDSA P-256, the scheme Bifrost already signs OTA
releases with, so Bifrost's existing key can sign bundles too. The signed
message follows the OTA one: a format line, the project, the bundle's
SHA-256 and its size. Binding the project means one key can sign for
every app without a bundle from one running in another.

With PARCEL_SIGNING_URL and PARCEL_SIGNING_TOKEN set, parcel sends only
the project, hash and size to that endpoint and Bifrost signs, so the
private key never has to be on the build machine. Otherwise it signs
with a local PEM key from PARCEL_SIGNING_KEY. Either way the signature
is checked against the returned public key before it's written, as
JSON with the key id, and --public-key-output writes {key id: public
key} for the build to put in the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp merged commit 41392e1 into main Nov 19, 2026
6 checks passed
@simonhamp
simonhamp deleted the mobile-bundles branch November 19, 2026 23:38
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

Successfully merging this pull request may close these issues.

1 participant