A .cml
file contains a single json5 object literal with the keys below.
Where string values are expected, a list of valid values is generally documented. The following string value types are reused and must follow specific rules.
String types
Names
Both capabilities and a component's children are named. A name string must consist of one or
more of the following characters: a-z
, 0-9
, _
, .
, -
.
References
A reference string takes the form of #<name>
, where <name>
refers to the name of a child:
- A static child instance whose name is
<name>
, or - A collection whose name is
<name>
.
Top-level keys
include
array of string
(optional)
The optional include
property describes zero or more other component manifest
files to be merged into this component manifest. For example:
include: [ "syslog/client.shard.cml" ]
In the example given above, the component manifest is including contents from a
manifest shard provided by the syslog
library, thus ensuring that the
component functions correctly at runtime if it attempts to write to syslog
. By
convention such files are called "manifest shards" and end with .shard.cml
.
Include paths prepended with //
are relative to the source root of the Fuchsia
checkout. However, include paths not prepended with //
, as in the example
above, are resolved from Fuchsia SDK libraries (//sdk/lib
) that export
component manifest shards.
For reference, inside the Fuchsia checkout these two include paths are equivalent:
syslog/client.shard.cml
//sdk/lib/syslog/client.shard.cml
You can review the outcome of merging any and all includes into a component manifest file by invoking the following command:
fx cmc include cmx_file --includeroot $FUCHSIA_DIR --includepath $FUCHSIA_DIR/sdk/lib
Includes are transitive, meaning that shards can have their own includes.
Include paths can have diamond dependencies. For instance this is valid: A includes B, A includes C, B includes D, C includes D. In this case A will transitively include B, C, D.
Include paths cannot have cycles. For instance this is invalid: A includes B, B includes A. A cycle such as the above will result in a compile-time error.
program
object
(optional)
Components that are executable include a program
section. The program
section must set the runner
property to select a runner to run
the component. The format of the rest of the program
section is determined by
that particular runner.
ELF runners
If the component uses the ELF runner, program
must include the following
properties, at a minimum:
runner
: must be set to"elf"
binary
: Package-relative path to the executable binaryargs
(optional): List of arguments
Example:
program: {
runner: "elf",
binary: "bin/hippo",
args: [ "Hello", "hippos!" ],
},
For a complete list of properties, see: ELF Runner
Other runners
If a component uses a custom runner, values inside the program
stanza other
than runner
are specific to the runner. The runner receives the arguments as a
dictionary of key and value pairs. Refer to the specific runner being used to
determine what keys it expects to receive, and how it interprets them.
children
array of object
(optional)
The children
section declares child component instances as described in
Child component instances.
name
: (string
) The name of the child component instance, which is a string of one or more of the following characters:a-z
,0-9
,_
,.
,-
. The name identifies this component when used in a reference.url
: (string
) The component URL for the child component instance.startup
: (string
) The component instance's startup mode. One of:lazy
(default): Start the component instance only if another component instance binds to it.eager
: Start the component instance as soon as its parent starts.
on_terminate
: (optionalstring
) Determines the fault recovery policy to apply if this component terminates.none
(default): Do nothing.reboot
: Gracefully reboot the system if the component terminates for any reason. This is a special feature for use only by a narrow set of components; see Termination policies for more information.
environment
: (optionalstring
) If present, the name of the environment to be assigned to the child component instance, one ofenvironments
. If omitted, the child will inherit the same environment assigned to this component.
Example:
children: [
{
name: "logger",
url: "fuchsia-pkg://fuchsia.com/logger#logger.cm",
},
{
name: "pkg_cache",
url: "fuchsia-pkg://fuchsia.com/pkg_cache#meta/pkg_cache.cm",
startup: "eager",
},
{
name: "child",
url: "#meta/child.cm",
}
],
collections
array of object
(optional)
The collections
section declares collections as described in
Component collections.
name
: (string
) The name of the component collection, which is a string of one or more of the following characters:a-z
,0-9
,_
,.
,-
. The name identifies this collection when used in a reference.durability
: (string
) The duration of child component instances in the collection.transient
: The instance exists until its parent is stopped or it is explicitly destroyed.single_run
: The instance is started when it is created, and destroyed when it is stopped.
environment
: (optionalstring
) If present, the environment that will be assigned to instances in this collection, one ofenvironments
. If omitted, instances in this collection will inherit the same environment assigned to this component.allowed_offers
: (optionalstring
) Constraints on the dynamic offers that target the components in this collection. Dynamic offers are specified when callingfuchsia.component.Realm/CreateChild
.static_only
: Only those specified in this.cml
file. No dynamic offers. This is the default.static_and_dynamic
: Both static offers and those specified at runtime withCreateChild
are allowed.
allow_long_names
: (optionalbool
) Allow child names up to 1024 characters long instead of the usual 100 character limit. Default is false.
Example:
collections: [
{
name: "tests",
durability: "transient",
},
],
environments
array of object
(optional)
The environments
section declares environments as described in
Environments.
name
: (string
) The name of the environment, which is a string of one or more of the following characters:a-z
,0-9
,_
,.
,-
. The name identifies this environment when used in a reference.extends
: (optionalstring
) How the environment should extend this realm's environment.realm
: Inherit all properties from this compenent's environment.none
: Start with an empty environment, do not inherit anything.
runners
: (optional array ofobject
) The runners registered in the environment. An array of objects with the following properties:runner
: (string
) The name of a runner capability, whose source is specified infrom
.from
: (string
) The source of the runner capability, one of:parent
: The component's parent.self
: This component.#<child-name>
: A reference to a child component instance.as
: (optionalstring
) An explicit name for the runner as it will be known in this environment. If omitted, defaults torunner
.
resolvers
: (optional array ofobject
) The resolvers registered in the environment. An array of objects with the following properties:resolver
: (string
) The name of a resolver capability, whose source is specified infrom
.from
: (string
) The source of the resolver capability, one of:parent
: The component's parent.self
: This component.#<child-name>
: A reference to a child component instance.scheme
: (string
) The URL scheme for which the resolver should handle resolution.
debug
: (optional array ofobject
) Debug protocols available to any component in this environment acquired throughuse from debug
.protocol
: (optionalstring or array of strings
) The name(s) of the protocol(s) to make available.from
: (string
) The source of the capability(s), one of:parent
: The component's parent.self
: This component.#<child-name>
: A reference to a child component instance.as
: (optionalstring
) If specified, the name that the capability inprotocol
should be made available as to clients. Disallowed ifprotocol
is an array.
stop_timeout_ms
: (optionalnumber
) The number of milliseconds to wait, after notifying a component in this environment that it should terminate, before forcibly killing it.
Example:
environments: [
{
name: "test-env",
extend: "realm",
runners: [
{
runner: "gtest-runner",
from: "#gtest",
},
],
resolvers: [
{
resolver: "universe-resolver",
from: "parent",
scheme: "fuchsia-pkg",
},
],
},
],
capabilities
array of object
(optional)
The capabilities
section defines capabilities that are provided by this component.
Capabilities that are offered or exposed from self
must be declared
here.
One and only one of the capability type keys (protocol
, directory
, service
, ...) is required.
service
: (optionalstring or array of strings
) The name for this service capability. Specifyingpath
is valid only when this value is a string.protocol
: (optionalstring or array of strings
) The name for this protocol capability. Specifyingpath
is valid only when this value is a string.directory
: (optionalstring
) The name for this directory capability.storage
: (optionalstring
) The name for this storage capability.runner
: (optionalstring
) The name for this runner capability.resolver
: (optionalstring
) The name for this resolver capability.event
: (optionalstring
) The name for this event capability.event_stream
: (optionalstring or array of strings
) The name for this event_stream capability.path
: (optionalstring
) The path within the outgoing directory of the component's program to source the capability.For
protocol
andservice
, defaults to/svc/${protocol}
, otherwise required.For
protocol
, the target of the path MUST be a channel, which tends to speak the protocol matching the name of this capability.For
service
,directory
, the target of the path MUST be a directory.For
runner
, the target of the path MUST be a channel and MUST speak the protocolfuchsia.component.runner.ComponentRunner
.For
resolver
, the target of the path MUST be a channel and MUST speak the protocolfuchsia.component.resolution.Resolver
.rights
: (optionalstring
) (directory
only) The maximum directory rights that may be set when using this directory.from
: (optionalstring
) (storage
only) The source component of an existing directory capability backing this storage capability, one of:parent
: The component's parent.self
: This component.#<child-name>
: A reference to a child component instance.
backing_dir
: (optionalstring
) (storage
only) The name of the directory capability backing the storage. The capability must be available from the component referenced infrom
.subdir
: (optionalstring
) (storage
only) A subdirectory withinbacking_dir
where per-component isolated storage directories are createdstorage_id
: (optionalstring
) (storage only
) The identifier used to isolated storage for a component, one of:static_instance_id
: The instance ID in the component ID index is used as the key for a component's storage. Components which are not listed in the component ID index will not be able to use this storage capability.static_instance_id_or_moniker
: If the component is listed in the component ID index, the instance ID is used as the key for a component's storage. Otherwise, the component's relative moniker from the storage capability is used.
use
array of object
(optional)
For executable components, declares capabilities that this
component requires in its namespace at runtime.
Capabilities are routed from the parent
unless otherwise specified,
and each capability must have a valid route through all components between
this component and the capability's source.
service
: (optionalstring or array of strings
) When using a service capability, the name of a service capability.protocol
: (optionalstring or array of strings
) When using a protocol capability, the name of a protocol capability.directory
: (optionalstring
) When using a directory capability, the name of a directory capability.storage
: (optionalstring
) When using a storage capability, the name of a storage capability.event
: (optionalstring or array of strings
) When using an event capability, the name of an event capability.event_stream_deprecated
: (optionalstring
) Deprecated.event_stream
: (optionalstring or array of strings
) When using an event stream capability, the name of an event stream capability.from
: (optionalstring
) The source of the capability. Defaults toparent
. One of:parent
: The component's parent.debug
: One ofdebug_capabilities
in the environment assigned to this component.framework
: The Component Framework runtime.self
: This component.#<capability-name>
: The name of another capability from which the requested capability is derived.#<child-name>
: A reference to a child component instance.
path
: (optionalstring
) The path at which to install the capability in the component's namespace. For protocols, defaults to/svc/${protocol}
. Required fordirectory
andstorage
. This property is disallowed for declarations with arrays of capability names.rights
: (optionalstring
) (directory
only) the maximum directory rights to apply to the directory in the component's namespace.subdir
: (optionalstring
) (directory
only) A subdirectory within the directory capability to provide in the component's namespace.as
: (optionalstring
) TODO(fxb/96705): Document events features.scope
: (optionalstring or array of strings
) TODO(fxb/96705): Document events features.filter
: (optionalobject
) TODO(fxb/96705): Document events features.subscriptions
: (optionalstring
) TODO(fxb/96705): Document events features.dependency
: (optionalstring
)dependency
(optional): The type of dependency between the source and this component, one of:strong
: a strong dependency, which is used to determine shutdown ordering. Component manager is guaranteed to stop the target before the source. This is the default.weak_for_migration
: a weak dependency, which is ignored during shutdown. When component manager stops the parent realm, the source may stop before the clients. Clients of weak dependencies must be able to handle these dependencies becoming unavailable. This type exists to keep track of weak dependencies that resulted from migrations into v2 components.
availability
: (optionalstring
) Determines whether this capability is required to be available, or if its presence is optional.
Example:
use: [
{
protocol: [
"fuchsia.ui.scenic.Scenic",
"fuchsia.accessibility.Manager",
]
},
{
directory: "themes",
path: "/data/themes",
rights: [ "r*" ],
},
{
storage: "persistent",
path: "/data",
},
{
event: [
"started",
"stopped",
],
from: "framework",
},
],
expose
array of object
(optional)
Declares the capabilities that are made available to the parent component or to the
framework. It is valid to expose
from self
or from a child component.
One and only one of the capability type keys (protocol
, directory
, service
, ...) is required.
service
: (optionalstring or array of strings
) When routing a service, the name of a service capability.protocol
: (optionalstring or array of strings
) When routing a protocol, the name of a protocol capability.directory
: (optionalstring or array of strings
) When routing a directory, the name of a directory capability.runner
: (optionalstring or array of strings
) When routing a runner, the name of a runner capability.resolver
: (optionalstring or array of strings
) When routing a resolver, the name of a resolver capability.from
: (string or array of strings
)from
: The source of the capability, one of:self
: This component. Requires a correspondingcapability
declaration.framework
: The Component Framework runtime.#<child-name>
: A reference to a child component instance.
as
: (optionalstring
) The name for the capability as it will be known by the target. If omitted, defaults to the original name.as
cannot be used when an array of multiple capability names is provided.to
: (optionalstring
) The capability target. Eitherparent
orframework
. Defaults toparent
.rights
: (optionalstring
) (directory
only) the maximum directory rights to apply to the exposed directory capability.subdir
: (optionalstring
) (directory
only) the relative path of a subdirectory within the source directory capability to route.event_stream
: (optionalstring or array of strings
) TODO(fxb/96705): Complete.scope
: (optionalstring or array of strings
) TODO(fxb/96705): Complete.
Example:
expose: [
{
directory: "themes",
from: "self",
},
{
protocol: "pkg.Cache",
from: "#pkg_cache",
as: "fuchsia.pkg.PackageCache",
},
{
protocol: [
"fuchsia.ui.app.ViewProvider",
"fuchsia.fonts.Provider",
],
from: "self",
},
{
runner: "web-chromium",
from: "#web_runner",
as: "web",
},
{
resolver: "universe-resolver",
from: "#universe_resolver",
},
],
offer
array of object
(optional)
Declares the capabilities that are made available to a child component instance or a child collection.
service
: (optionalstring or array of strings
) When routing a service, the name of a service capability.protocol
: (optionalstring or array of strings
) When routing a protocol, the name of a protocol capability.directory
: (optionalstring or array of strings
) When routing a directory, the name of a directory capability.runner
: (optionalstring or array of strings
) When routing a runner, the name of a runner capability.resolver
: (optionalstring or array of strings
) When routing a resolver, the name of a resolver capability.storage
: (optionalstring or array of strings
) When routing a storage capability, the name of a storage capability.event
: (optionalstring or array of strings
) When routing an event, the name of the event.from
: (string or array of strings
)from
: The source of the capability, one of:parent
: The component's parent. This source can be used for all capability types.self
: This component. Requires a correspondingcapability
declaration.framework
: The Component Framework runtime.#<child-name>
: A reference to a child component instance. This source can only be used when offering protocol, directory, or runner capabilities.void
: The source is intentionally omitted. Only valid whenavailability
is notrequired
.
to
: (string or array of strings
) A capability target or array of targets, each of which is a reference to the child or collection to which the capability is being offered, of the form#<target-name>
.as
: (optionalstring
) An explicit name for the capability as it will be known by the target. If omitted, defaults to the original name.as
cannot be used when an array of multiple names is provided.dependency
: (optionalstring
) The type of dependency between the source and targets, one of:strong
: a strong dependency, which is used to determine shutdown ordering. Component manager is guaranteed to stop the target before the source. This is the default.weak_for_migration
: a weak dependency, which is ignored during shutdown. When component manager stops the parent realm, the source may stop before the clients. Clients of weak dependencies must be able to handle these dependencies becoming unavailable. This type exists to keep track of weak dependencies that resulted from migrations into v2 components.
rights
: (optionalstring
) (directory
only) the maximum directory rights to apply to the offered directory capability.subdir
: (optionalstring
) (directory
only) the relative path of a subdirectory within the source directory capability to route.filter
: (optionalobject
) TODO(fxb/96705): Complete.event_stream
: (optionalstring or array of strings
) TODO(fxb/96705): Complete.scope
: (optionalstring or array of strings
) TODO(fxb/96705): Complete.availability
: (optionalstring
) Whether or not this capability must be present. Defaults torequired
.source_availability
: (optionalstring
) Whether or not the source of this offer must exist. If set tounknown
, the source of this offer will be rewritten tovoid
if the source does not exist (i.e. is not defined in this manifest). The availability must be set tooptional
whensource_availability
is set tounknown
. Defaults torequired
.
Example:
offer: [
{
protocol: "fuchsia.logger.LogSink",
from: "#logger",
to: [ "#fshost", "#pkg_cache" ],
dependency: "weak_for_migration",
},
{
protocol: [
"fuchsia.ui.app.ViewProvider",
"fuchsia.fonts.Provider",
],
from: "#session",
to: [ "#ui_shell" ],
dependency: "strong",
},
{
directory: "blobfs",
from: "self",
to: [ "#pkg_cache" ],
},
{
directory: "fshost-config",
from: "parent",
to: [ "#fshost" ],
as: "config",
},
{
storage: "cache",
from: "parent",
to: [ "#logger" ],
},
{
runner: "web",
from: "parent",
to: [ "#user-shell" ],
},
{
resolver: "universe-resolver",
from: "parent",
to: [ "#user-shell" ],
},
{
event: "stopped",
from: "framework",
to: [ "#logger" ],
},
],
facets
object
(optional)
Contains metadata that components may interpret for their own purposes. The component framework enforces no schema for this section, but third parties may expect their facets to adhere to a particular schema.
config
object
(optional)
The configuration schema as defined by a component. Each key represents a single field in the schema.
NOTE: This feature is currently experimental and access is controlled through an allowlist
in fuchsia.git at //tools/cmc/build/restricted_features/BUILD.gn
.
Configuration fields are JSON objects and must define a type
which can be one of the
following strings:
bool
, uint8
, int8
, uint16
, int16
, uint32
, int32
, uint64
, int64
,
string
, vector
Example:
config: {
debug_mode: {
type: "bool"
},
}
Strings must define the max_size
property as a non-zero integer.
Example:
config: {
verbosity: {
type: "string",
max_size: 20,
}
}
Vectors must set the max_count
property as a non-zero integer. Vectors must also set the
element
property as a JSON object which describes the element being contained in the
vector. Vectors can contain booleans, integers, and strings but cannot contain other
vectors.
Example:
config: {
tags: {
type: "vector",
max_count: 20,
element: {
type: "string",
max_size: 50,
}
}
}