php-baremetal / spec
Shared model of the php-baremetal build manifest and the SDK driver contract.
Requires
- php: >=8.4
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
- phpunit/phpunit: Required by Testing\DriverConformanceTestCase
Provides
None
Conflicts
None
Replaces
None
README
php-baremetal/spec is the contract between the tools and the SDKs of php-baremetal: a PHP library, published on
Packagist, that defines the build manifest of a project and the
interface an SDK driver implements. conductor writes the
manifest with it, phpbm reads it and loads SDKs with it, and an SDK such as esp32-sdk implements its driver
against it. It has no runtime dependency beyond PHP 8.4.
You need it directly only when you write a tool that reads a manifest, or an SDK driver for another platform.
composer require php-baremetal/spec
Manifest
PhpBaremetal\Spec\Manifest\Manifest is .phpbm/manifest.json (Manifest::PATH), schema Manifest::SCHEMA (1):
Project:name,sdk(aSdkRequirement,<name>@<constraint>),board,runtime,storage,php(a version such as8.5.11,phpMinor()gives8.5),src,entry,env,boardOverridesandoptions.Project::fromComposer()builds it fromextra.baremetalandconfig.platform.php.Package:name,type(alwaysbm-*),version,pathandmeta(the package'sextra.baremetal).kind()returns the type withoutbm-. Abm-boardspackage carries boards (see below) and needs noextra.baremetal.Manifest::fromFile(),fromArray(),toJson(),ofKind('ext'),has($name).ManifestValidator::validate()returns a list of problems: extensions without amoduleor sharing one, abm-halfor another platform than the SDK's, abm-php-extthat carries more thanphp-ext, a malformedextra.baremetal.board-blocks, and a malformedextra.baremetal.ide-stubs(a list of relative paths ending in.stub, without..segments).
SDK
An SDK is a directory (sdk.json, chips/, boards/, runtimes/, storages/, php/<minor>/extensions/*.json,
sources/) plus a driver class.
-
Sdk\SdkLoader::load($dir)reads the directory into anSdkand checks it: boards against their chip, extension modules and entry symbols for clashes, extension requirements for cycles. The descriptor classes are inSdk\Descriptor(SdkDescriptor,Chip,Board,Module,Option,PhpExtension,PhpRelease,Requirements,SourceArchive). -
sdk.jsonmay list the official board packages inboard-packages(Composer names,SdkDescriptor::$boardPackages, empty when missing). -
SdkLoader::withBoardPackages($sdk, $packages, $projectDir)returns theSdkwith the boards of the givenbm-boardspackages (manifestPackages; other types are skipped) added:boards/<sdk name>/*.jsonof each package, checked against their chip like the SDK's boards. Folders of other SDKs are ignored. A relative package path is resolved against$projectDir. Errors name the package and the file (vendor/boards-x: boards/esp32/x.json: chip 'y' does not exist). -
Each
Boardknows itssource:Board::SDK(sdk) or the package name;qualifiedId()is<source>:<id>.Sdk::board($id)takes the id or that long form (sdk:<id>,<vendor>/<package>:<id>). An id defined by more than one source must be given in the long form;Sdk::$boardskeys such boards by the long form and the others by their id. -
A board file may name its GPIOs in
pins, an objectname => GPIO(names/^[A-Z][A-Z0-9_]*$/, e.g.D13,LED_BUILTIN; values integers >= 0; several names may share a GPIO).pinsis not a block: it has notypeand is not inperipheralsnorcapabilities().Board::$pinskeeps them in the file's order (empty when missing). A string value of a block (other thantype) equal to a pin name becomes its GPIO when the board is read ("i2c": {"type": "i2c", "sda": "A4"}givessda11 with"A4": 11); any other string stays as it is.Board::withOverrides()resolves the override values against the board's pins;pinsitself cannot be overridden. -
Sdk\Driveris the interface an SDK driver implements,Driver::CONTRACTbeing the contract version (1) thatsdk.jsonmust declare:Method Meaning toolchain()A Toolchain:status(),install(),env().build($plan, $out)Build the firmware from a BuildPlan; returnsArtifacts.flash($artifacts, $plan, $port, $out)Write the images to the board on a Port.sync($plan, $port, $out)Copy the project sources to a storage the firmware does not carry; falsefor the others.monitor($port)Open the serial console; returns the exit code. identify($port)A ChipInfo, ornullwhen the chip does not belong to this platform.ports()The serial ports found. The driver is constructed with a
Context(SDK directory, toolchain directory, aProcessto run commands), and reports progress through anOutput. -
Sdk::driver($context)loads the driver class named insdk.json(driver.class, autoloaded fromdriver.autoload), refusing a contract version it does not support.
Testing an SDK
Testing\DriverConformanceTestCase (needs PHPUnit) is a base class: extend it, return the SDK directory from
sdkDir(), and it checks the contract version, that the driver implements Driver, and that toolchain(),
ports() and identify() behave. Testing\FakeProcess and Testing\BufferedOutput stand in for the process runner
and the output.
License
MIT.