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 cml_file --includeroot $FUCHSIA_DIR --includepath $FUCHSIA_DIR/sdk/lib
Includes can cope with duplicate use
, offer
, expose
, or capabilities
declarations referencing the same capability, as long as the properties are the same. For
example:
// my_component.cml
include: [ "syslog.client.shard.cml" ]
use: [
{
protocol: [
"fuchsia.logger.LogSink",
"fuchsia.posix.socket.Provider",
],
},
],
// syslog.client.shard.cml
use: [
{ protocol: "fuchsia.logger.LogSink" },
],
In this example, the contents of the merged file will be the same as my_component.cml --
fuchsia.logger.LogSink
is deduped.
However, this would fail to compile:
// my_component.cml
include: [ "syslog.client.shard.cml" ]
use: [
{
protocol: "fuchsia.logger.LogSink",
// properties for fuchsia.logger.LogSink don't match
from: "#archivist",
},
],
// syslog.client.shard.cml
use: [
{ protocol: "fuchsia.logger.LogSink" },
],
An exception to this constraint is the availability
property. If two routing declarations
are identical, and one availability is stronger than the other, the availability will be
"promoted" to the stronger value (if availability
is missing, it defaults to required
).
For example:
// my_component.cml
include: [ "syslog.client.shard.cml" ]
use: [
{
protocol: [
"fuchsia.logger.LogSink",
"fuchsia.posix.socket.Provider",
],
availability: "optional",
},
],
// syslog.client.shard.cml
use: [
{
protocol: "fuchsia.logger.LogSink"
availability: "required", // This is the default
},
],
Becomes:
use: [
{
protocol: "fuchsia.posix.socket.Provider",
availability: "optional",
},
{
protocol: "fuchsia.logger.LogSink",
availability: "required",
},
],
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.
disable
object
(optional)
The disable
section disables certain features in a particular CML that are
otherwise enforced by cmc.
must_offer_protocol
: (optional array ofstring
) Lists protocols for which the option "--must-offer-protocol" is disabled.must_use_protocol
: (optional array ofstring
) Lists protocols for which the option "--must-use-protocol" is disabled.
Example:
disable: {
must_offer_protocol: [ "fuchsia.logger.LogSink", "fuchsia.component.Binder" ],
must_use_protocol: [ "fuchsia.logger.LogSink" ],
}
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.persistent_storage
: (optionalbool
) If set totrue
, the data in isolated storage used by dynamic child instances and their descendants will persist after the instances are destroyed. A new child instance created with the same name will share the same storage path as the previous instance.
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 component'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. This field is required if the environment extends fromnone
.
Example:
environments: [
{
name: "test-env",
extends: "realm",
runners: [
{
runner: "gtest-runner",
from: "#gtest",
},
],
resolvers: [
{
resolver: "full-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_stream
: (optionalstring or array of strings
) The name for this event_stream capability.dictionary
: (optionalstring
) The name for this dictionary 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
: (optionalarray of string
) (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.
(
dictionary
only) The contents to initialize a dictionary with. One of: -void
: Create the dictionary empty. -parent/<relative_path>
: A path to a dictionary offered byparent
. -#<child-name>/<relative_path>
: A path to a dictionary exposed by#<child-name>
. -self/<relative_path>
: A path to a dictionary defined by this component.<relative_path>
may be either a name, identifying a dictionary capability), or a path with multiple parts, identifying a nested dictionary.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 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_stream
: (optionalstring or array of strings
) When using an event stream capability, the name of an event stream capability.runner
: (optionalstring
) When using a runner capability, the name of a runner 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 and for runner capabilities.rights
: (optionalarray of string
) (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.scope
: (optionalstring or array of strings
) (event_stream
only) When defined the event stream will contain events about only the components defined in the scope.filter
: (optionalobject
) (event_stream
only) Capability requested event streams require specifying a filter referring to the protocol to which the events in the event stream apply. The content of the filter will be an object mapping from "name" to the "protocol name".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
: 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 property is disallowed for runner capabilities, which are always astrong
dependency.
availability
: (optionalstring
)availability
(optional): The expectations around this capability's availability. One of:required
(default): a required dependency, the component is unable to perform its work without this capability.optional
: an optional dependency, the component will be able to function without this capability (although if the capability is unavailable some functionality may be disabled).transitional
: the source may omit the route completely without even having to route fromvoid
. Used for soft transitions that introduce new capabilities. This property is disallowed for runner capabilities, which are alwaysrequired
.
Example:
use: [
{
protocol: [
"fuchsia.ui.scenic.Scenic",
"fuchsia.accessibility.Manager",
]
},
{
directory: "themes",
path: "/data/themes",
rights: [ "r*" ],
},
{
storage: "persistent",
path: "/data",
},
{
event_stream: [
"started",
"stopped",
],
from: "framework",
},
{
runner: "own_test_runner".
from: "#test_runner",
},
],
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.dictionary
: (optionalstring or array of strings
) When routing a dictionary, the name of a [dictionary capability][doc-dictionaries].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
: (optionalarray of string
) (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
) (event_stream
only) the name(s) of the event streams being exposed.scope
: (optionalstring or array of strings
) (event_stream
only) the scope(s) of the event streams being exposed. This is used to downscope the range of components to which an event stream refers and make it refer only to the components defined in the scope.availability
: (optionalstring
)availability
(optional): The expectations around this capability's availability. Affects build-time and runtime route validation. One of:required
(default): a required dependency, the source must exist and provide it. Use this when the target of this expose requires this capability to function properly.optional
: an optional dependency. Use this when the target of the expose can function with or without this capability. The target must not have arequired
dependency on the capability. The ultimate source of this expose must bevoid
or an actual component.same_as_target
: the availability expectations of this capability will match the target's. If the target requires the capability, then this field is set torequired
. If the target has an optional dependency on the capability, then the field is set tooptional
.transitional
: likeoptional
, but will tolerate a missing source. Use this only to avoid validation errors during transitional periods of multi-step code changes.
source_availability
: (optionalstring
) Whether or not the source of this offer must exist. One of:required
(default): the source (from
) must be defined in this manifest.unknown
: the source of this offer will be rewritten tovoid
if its source (from
) is not defined in this manifest after includes are processed.
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: "full-resolver",
from: "#full-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.dictionary
: (optionalstring or array of strings
) When routing a dictionary, the name of a [dictionary capability][doc-dictionaries].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
isoptional
ortransitional
.
to
: (string or array of strings
) Capability target(s). One of:#<target-name>
or [#name1
, ...]: A reference to a child or collection, or an array of references.all
: Short-hand for anoffer
clause containing all child references.
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
: 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.
rights
: (optionalarray of string
) (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.event_stream
: (optionalstring or array of strings
) (event_stream
only) the name(s) of the event streams being offered.scope
: (optionalstring or array of strings
) (event_stream
only) When defined the event stream will contain events about only the components defined in the scope.availability
: (optionalstring
)availability
(optional): The expectations around this capability's availability. Affects build-time and runtime route validation. One of:required
(default): a required dependency, the source must exist and provide it. Use this when the target of this offer requires this capability to function properly.optional
: an optional dependency. Use this when the target of the offer can function with or without this capability. The target must not have arequired
dependency on the capability. The ultimate source of this offer must bevoid
or an actual component.same_as_target
: the availability expectations of this capability will match the target's. If the target requires the capability, then this field is set torequired
. If the target has an optional dependency on the capability, then the field is set tooptional
.transitional
: likeoptional
, but will tolerate a missing source. Use this only to avoid validation errors during transitional periods of multi-step code changes.
source_availability
: (optionalstring
) Whether or not the source of this offer must exist. One of:required
(default): the source (from
) must be defined in this manifest.unknown
: the source of this offer will be rewritten tovoid
if its source (from
) is not defined in this manifest after includes are processed.
Example:
offer: [
{
protocol: "fuchsia.logger.LogSink",
from: "#logger",
to: [ "#fshost", "#pkg_cache" ],
dependency: "weak",
},
{
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: "full-resolver",
from: "parent",
to: [ "#user-shell" ],
},
{
event_stream: "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.
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"
},
}
Fields are resolved from a component's package by default. To be able to change the values
at runtime a mutability
specifier is required.
Example:
config: {
verbose: {
type: "bool",
mutability: [ "parent" ],
},
},
Currently "parent"
is the only mutability specifier supported.
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,
}
}
}