Repository navigation
Conversation
Experimental and off by default. With NATIVEPHP_PARCEL=true, native:build hands the staged app to Parcel and ships its PHP as a single compressed phar instead of a tree of files. app.zip then holds the phar, .env and public/. On the device PHP reads the code straight out of the phar through phar://, so it is never unpacked. Build: Parcel works on an APFS clone of nativephp/ios/laravel, so the staged app the next build reuses is left as it was. NATIVEPHP_PARCEL_BINARY says where parcel is. Runtime: AppUpdateManager.getCodePath() is where every lane now finds its PHP (persistent, webview, async, queue, classic, artisan). A phar is read-only, so prepareCodeEnvironment() points Laravel's bootstrap caches at the extracted app directory, and the iOS bootstrap scripts read .env and public/ from there through NATIVEPHP_BUNDLE_ROOT. Signing: with NATIVEPHP_PARCEL_SIGNING_KEY set, the build runs `parcel sign`, ships the .sig beside the phar and writes the public key into bundle_meta.json, inside the code-signed .app. The key is always stripped from the bundled .env. A shell with a key runs only a phar that matches its signature. Anything else, including no phar at all, gets an empty code path, and launch puts back the copy shipped in the .app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The phar and its signature now ship loose inside the .app instead of in app.zip, and PHP reads the code from there. Nothing unpacks it, so the device keeps one copy instead of two, the code isn't in the app's backed up Documents folder, and on a normal phone the shipped copy can't be changed at all. app.zip only carries .env and public/, which the device has to be able to rewrite. A build without Parcel deletes any phar a previous Parcel build left in the Xcode project, because the runtime would run it in preference to app.zip. An OTA update brings its own phar and signature into Documents/app, and that runs instead of the shipped one while it is there. Each phar carries its own signature, checked against the one public key the shell was built with, so a release never replaces another's signature and the shipped pair is always there to fall back to. A payload's phar is checked before it replaces the working app as well as on every launch, and an installed phar that stops matching puts the shipped app back. A shell that ships a phar refuses a plain-tree payload by looking inside the zip before unpacking it. Any refused payload is now deleted: it would fail the same way on every launch, after being unpacked again each time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signatures are now ECDSA P-256 in the same shape as Bifrost's OTA release signatures, so Bifrost can sign bundles with its existing KMS key. The build no longer holds a key: with NATIVEPHP_PARCEL_SIGN=true it runs `parcel sign`, which asks Bifrost to sign (PARCEL_SIGNING_URL and PARCEL_SIGNING_TOKEN) or uses a local PARCEL_SIGNING_KEY for testing. The signature is bound to the project (BIFROST_APP_ID, or the app id for local builds), so with one key for every app a bundle signed for one still can't run in another. bundle_meta.json now carries parcel_signing: the project and the keys the app trusts, by key id. The .sig names the key it was made with, and only listed keys count, which leaves room to rotate keys later. PARCEL_SIGNING_KEY and PARCEL_SIGNING_TOKEN are always stripped from the bundled .env. An app is now built to run either Parcel bundles or a plain tree, never both. A plain-tree app ignores any phar and refuses Parcel payloads, just as a Parcel app refuses plain-tree ones, so existing apps behave exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nativephp/parcel can't be a Composer dependency of this package: Box, which it builds on, only supports Symfony up to 7, so requiring it would stop any app on Symfony 8 (Laravel 13 apps, for one) installing nativephp/mobile at all. It would also add 58 packages, about 34 MB, to every app's vendor folder. So Parcel stays a separate tool, installed with `composer global require nativephp/parcel`, and the package suggests it. Before a Parcel build runs, check Parcel is there and is 1.0 or later (1.0 is the first with `sign` and mobile bundles), and say how to install or update it if not, instead of failing later with "command not found". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
It should be
Weird. Ok... Let's do it
What's this about? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets an iOS app ship its PHP as one signed, compressed phar built by Parcel instead of as a tree of files. The phar sits inside the
.appand PHP reads the code straight out of it, so it's never unpacked. OTA updates bring their own signed phar. Bifrost signs with the P-256 key it already uses for OTA releases, and the key never reaches the build machine. It's off by default and iOS only, and apps that don't turn it on behave exactly as before. Needs Parcel, which is now on Packagist, installed globally. Use 1.0.1 or later.Why
Smaller apps, far less on the device, a faster first launch, the code a little harder to read, and a way to tell if it's been changed. This is the mechanism Bifrost already uses for desktop bundles.
devnull-mobile, debug build, iOS simulator, same code both ways:
.appapp.zipapp.zipDocuments/appon the deviceA release build of the same app, without dev packages, makes a 7.5 MB phar.
How it works
Build. With
NATIVEPHP_PARCEL=true,native:buildtakes an APFS clone of the staged app innativephp/ios/laravel, runsparcel prepare --mobile, regenerates the autoloader so Parcel's path helpers load, and runsparcel compile. The phar (and its.sig) go intonativephp/ios/NativePHP/, which is a synchronized folder in the Xcode project, so they ship loose in the.app.app.ziponly carries.envandpublic/. A build without Parcel deletes any phar a previous Parcel build left there.NATIVEPHP_PARCEL_BINARYsays whereparcelis.Parcel itself. Parcel is a separate tool you install with
composer global require nativephp/parcel. It isn't a Composer dependency of this package, andcomposer.jsononly suggests it. Box, which Parcel builds on, only supports Symfony up to 7 (still true of Box 4.7.1). Requiring it would stop any app on Symfony 8 from installingnativephp/mobileat all, devnull on Laravel 13 included. It would also put 58 packages, about 34 MB, into every app's vendor folder, Parcel or not. Before a Parcel build bundles anything, it now runsparcel listto check Parcel is there and is 1.0 or later (1.0 is the first withsignand mobile bundles), and it says how to install or update Parcel if not.Runtime.
AppUpdateManager.getCodePath()is where every lane now finds its PHP: persistent, webview, async, queue worker, classic requests and artisan. It returns, in order:Documents/app, if there is one.appA phar is read-only, so
prepareCodeEnvironment()pointsAPP_PACKAGES_CACHE,APP_SERVICES_CACHEand friends atDocuments/app/bootstrap/cache, and the three iOS bootstrap scripts callnativephp_use_bundle_paths()to read.envandpublic/fromDocuments/app(NATIVEPHP_BUNDLE_ROOT). Storage, compiled views and the database were already outside the app directory.Signing. With
NATIVEPHP_PARCEL_SIGN=truethe build runsparcel sign --project=<id>. On Bifrost, Parcel sends just the project, the phar's SHA-256 and its size to Bifrost (PARCEL_SIGNING_URL, authenticated withPARCEL_SIGNING_TOKEN), and Bifrost signs with its OTA key in KMS. So no private key is ever on the Mac. For local testing Parcel signs with a P-256 key inPARCEL_SIGNING_KEY. The project isBIFROST_APP_ID, or the app id for local builds.The signature is ECDSA P-256 over the same kind of message Bifrost signs for OTA releases:
nativephp-parcel-bundle-v1, the project, the SHA-256 and the size, one per line. Binding the project means one key can sign for every app while a bundle signed for one can't run in another. The.sigis JSON naming the key id. The build writesparcel_signingintobundle_meta.json(the project, and the trusted keys by id), which sits inside the code-signed.app.PARCEL_SIGNING_KEYandPARCEL_SIGNING_TOKENare always stripped from the bundled.env, whatevercleanup_env_keyssays.The app checks whichever phar it's about to run with CryptoKit, once per file, and only against keys listed in
bundle_meta.json. A phar that doesn't match gets an empty code path, so PHP can't boot from it. A build that wasn't signed (a local one) runs its bundle unchecked.One kind of app or the other. An app runs Parcel bundles if it shipped with a phar, and a plain tree otherwise, never both. A plain-tree app ignores any phar it finds and refuses Parcel payloads, so existing apps behave exactly as before. A Parcel app refuses plain-tree payloads.
OTA updates. Every phar carries its own signature, made once when it's built, and every one is checked against the same keys. So a new release never replaces anyone's signature, and the shipped phar and
.sigin the.appare never touched: going back to the code the app was installed with always works. IninstallUpdate:__nativephp_app_bundle.phar, its.sig,.env,public/) has its signature checked before it replaces the working app, then again on every launch.pending.zipand was unpacked and refused again on every launch. That part applies to any app, not just Parcel ones.Bifrost needs some work before this ships (not in this PR): a per-project switch that sets
NATIVEPHP_PARCELandNATIVEPHP_PARCEL_SIGN, Parcel installed on the Mac builders (composer global require nativephp/parcel, no token needed now), an endpoint that signs a bundle hash withReleaseSigneronce per build, OTA builds that produce Parcel payloads (phar,.sig,.env,public/,ota.json), and Parcel mode in the shell fingerprint so each app only gets updates of its own kind. Bifrost's own payload signature, which the mobile-ota plugin checks at download, stays as it is. The plugin needs no change: core does the unpacking.Tested
On the simulator with devnull-mobile, signed through a stand-in for Bifrost's endpoint (Parcel's test fixture under
php -S):.app, taps round-trip through PHP, all migrations ran from inside the phar (the app's and this package's), andstorage:linklands inDocuments/app/public..app, boots from the unpacked tree, takes a plain-tree update, refuses a Parcel payload.boxfirst on the PATH: builds, signs and boots. (1.0.0 picked up that otherboxand failed. Fixed in Run the Box that was installed alongside Parcel parcel#10.)NATIVEPHP_PARCEL_BINARYpointing at nothing: the build stops before bundling and gives the install command.Unit tests cover the bundle-paths helper, the signing secrets never reaching
.env,parcel_signingonly appearing for a signed build, a non-Parcel build removing a leftover phar, and the Parcel check (missing, older than 1.0, 1.0). The unit suite passes (1476) and the Feature files pass one by one. The fullvendor/bin/pestrun stops early onmaintoo, atTestingSuiteV2Test.Watch for
bundle_meta.jsonalready holds keys by id, so a new key can be added to new builds. Apps already installed only know the keys they were built with, so Bifrost has to keep signing their updates with an old key until none are left, as it does for OTA.public/isn't covered by the signature. For apps that run a lot of JavaScript in a web view that's code too.parcel --versionhas no number). 1.0.0 only works if its ownvendor/bincomes first on the PATH, so it's worth giving Parcel a real version number.fnmatch()(HAVE_FNMATCHis undefined when cross-compiling). Parcel doesn't need it any more, but app code calling it would crash. Probably worthac_cv_func_fnmatch_works=yesin php-bin-mobile.Trying it
🤖 Generated with Claude Code