Search by

Shared model of the php-baremetal build manifest and the SDK driver contract.

Package info

github.com/php-baremetal/spec

pkg:composer/php-baremetal/spec

Statistics

Installs: 645

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.5.0 2026-11-27 15:09 UTC

This package is auto-updated.

Last update: 2026-11-27 15:09:55 UTC


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 (a SdkRequirement, <name>@<constraint>), board, runtime, storage, php (a version such as 8.5.11, phpMinor() gives 8.5), src, entry, env, boardOverrides and options. Project::fromComposer() builds it from extra.baremetal and config.platform.php.
  • Package: name, type (always bm-*), version, path and meta (the package's extra.baremetal). kind() returns the type without bm-. A bm-boards package carries boards (see below) and needs no extra.baremetal.
  • Manifest::fromFile(), fromArray(), toJson(), ofKind('ext'), has($name).
  • ManifestValidator::validate() returns a list of problems: extensions without a module or sharing one, a bm-hal for another platform than the SDK's, a bm-php-ext that carries more than php-ext, a malformed extra.baremetal.board-blocks, and a malformed extra.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 an Sdk and checks it: boards against their chip, extension modules and entry symbols for clashes, extension requirements for cycles. The descriptor classes are in Sdk\Descriptor (SdkDescriptor, Chip, Board, Module, Option, PhpExtension, PhpRelease, Requirements, SourceArchive).

  • sdk.json may list the official board packages in board-packages (Composer names, SdkDescriptor::$boardPackages, empty when missing).

  • SdkLoader::withBoardPackages($sdk, $packages, $projectDir) returns the Sdk with the boards of the given bm-boards packages (manifest Packages; other types are skipped) added: boards/<sdk name>/*.json of 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 Board knows its source: 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::$boards keys such boards by the long form and the others by their id.

  • A board file may name its GPIOs in pins, an object name => GPIO (names /^[A-Z][A-Z0-9_]*$/, e.g. D13, LED_BUILTIN; values integers >= 0; several names may share a GPIO). pins is not a block: it has no type and is not in peripherals nor capabilities(). Board::$pins keeps them in the file's order (empty when missing). A string value of a block (other than type) equal to a pin name becomes its GPIO when the board is read ("i2c": {"type": "i2c", "sda": "A4"} gives sda 11 with "A4": 11); any other string stays as it is. Board::withOverrides() resolves the override values against the board's pins; pins itself cannot be overridden.

  • Sdk\Driver is the interface an SDK driver implements, Driver::CONTRACT being the contract version (1) that sdk.json must declare:

    Method Meaning
    toolchain() A Toolchain: status(), install(), env().
    build($plan, $out) Build the firmware from a BuildPlan; returns Artifacts.
    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; false for the others.
    monitor($port) Open the serial console; returns the exit code.
    identify($port) A ChipInfo, or null when the chip does not belong to this platform.
    ports() The serial ports found.

    The driver is constructed with a Context (SDK directory, toolchain directory, a Process to run commands), and reports progress through an Output.

  • Sdk::driver($context) loads the driver class named in sdk.json (driver.class, autoloaded from driver.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.