Component manifest (.cml) reference

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:

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 binary
  • args (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: (optional string) 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: (optional string) If present, the name of the environment to be assigned to the child component instance, one of environments. 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: (optional string) If present, the environment that will be assigned to instances in this collection, one of environments. If omitted, instances in this collection will inherit the same environment assigned to this component.
  • allowed_offers: (optional string) Constraints on the dynamic offers that target the components in this collection. Dynamic offers are specified when calling fuchsia.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 with CreateChild are allowed.
  • allow_long_names: (optional bool) Allow child names up to 1024 characters long instead of the usual 100 character limit. Default is false.
  • persistent_storage: (optional bool) If set to true, 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: (optional string) 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 of object) 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 in from.
    • 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: (optional string) An explicit name for the runner as it will be known in this environment. If omitted, defaults to runner.
  • resolvers: (optional array of object) 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 in from.
    • 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 of object) Debug protocols available to any component in this environment acquired through use from debug.

    • protocol: (optional string 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: (optional string) If specified, the name that the capability in protocol should be made available as to clients. Disallowed if protocol is an array.
  • stop_timeout_ms: (optional number) 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: "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: (optional string or array of strings) The name for this service capability. Specifying path is valid only when this value is a string.
  • protocol: (optional string or array of strings) The name for this protocol capability. Specifying path is valid only when this value is a string.
  • directory: (optional string) The name for this directory capability.
  • storage: (optional string) The name for this storage capability.
  • runner: (optional string) The name for this runner capability.
  • resolver: (optional string) The name for this resolver capability.
  • event: (optional string) The name for this event capability.
  • event_stream: (optional string or array of strings) The name for this event_stream capability.
  • path: (optional string) The path within the outgoing directory of the component's program to source the capability.

    For protocol and service, 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 protocol fuchsia.component.runner.ComponentRunner.

    For resolver, the target of the path MUST be a channel and MUST speak the protocol fuchsia.component.resolution.Resolver.

  • rights: (optional string) (directory only) The maximum directory rights that may be set when using this directory.

  • from: (optional string) (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: (optional string) (storage only) The name of the directory capability backing the storage. The capability must be available from the component referenced in from.

  • subdir: (optional string) (storage only) A subdirectory within backing_dir where per-component isolated storage directories are created

  • storage_id: (optional string) (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: (optional string or array of strings) When using a service capability, the name of a service capability.
  • protocol: (optional string or array of strings) When using a protocol capability, the name of a protocol capability.
  • directory: (optional string) When using a directory capability, the name of a directory capability.
  • storage: (optional string) When using a storage capability, the name of a storage capability.
  • event: (optional string or array of strings) When using an event capability, the name of an event capability.
  • event_stream_deprecated: (optional string) Deprecated.
  • event_stream: (optional string or array of strings) When using an event stream capability, the name of an event stream capability.
  • from: (optional string) The source of the capability. Defaults to parent. One of:
    • parent: The component's parent.
    • debug: One of debug_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: (optional string) The path at which to install the capability in the component's namespace. For protocols, defaults to /svc/${protocol}. Required for directory and storage. This property is disallowed for declarations with arrays of capability names.
  • rights: (optional string) (directory only) the maximum directory rights to apply to the directory in the component's namespace.
  • subdir: (optional string) (directory only) A subdirectory within the directory capability to provide in the component's namespace.
  • as: (optional string) TODO(fxb/96705): Document events features.
  • scope: (optional string or array of strings) TODO(fxb/96705): Document events features.
  • filter: (optional object) TODO(fxb/96705): Document events features.
  • subscriptions: (optional string) TODO(fxb/96705): Document events features.
  • dependency: (optional string) 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: (optional string) 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).

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: (optional string or array of strings) When routing a service, the name of a service capability.
  • protocol: (optional string or array of strings) When routing a protocol, the name of a protocol capability.
  • directory: (optional string or array of strings) When routing a directory, the name of a directory capability.
  • runner: (optional string or array of strings) When routing a runner, the name of a runner capability.
  • resolver: (optional string 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 corresponding capability declaration.
    • framework: The Component Framework runtime.
    • #<child-name>: A reference to a child component instance.
  • as: (optional string) 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: (optional string) The capability target. Either parent or framework. Defaults to parent.
  • rights: (optional string) (directory only) the maximum directory rights to apply to the exposed directory capability.
  • subdir: (optional string) (directory only) the relative path of a subdirectory within the source directory capability to route.
  • event_stream: (optional string or array of strings) TODO(fxb/96705): Complete.
  • scope: (optional string 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: "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: (optional string or array of strings) When routing a service, the name of a service capability.
  • protocol: (optional string or array of strings) When routing a protocol, the name of a protocol capability.
  • directory: (optional string or array of strings) When routing a directory, the name of a directory capability.
  • runner: (optional string or array of strings) When routing a runner, the name of a runner capability.
  • resolver: (optional string or array of strings) When routing a resolver, the name of a resolver capability.
  • storage: (optional string or array of strings) When routing a storage capability, the name of a storage capability.
  • event: (optional string 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 corresponding capability 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 when availability is not required.
  • 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: (optional string) 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: (optional string) 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: (optional string) (directory only) the maximum directory rights to apply to the offered directory capability.
  • subdir: (optional string) (directory only) the relative path of a subdirectory within the source directory capability to route.
  • filter: (optional object) TODO(fxb/96705): Complete.
  • event_stream: (optional string or array of strings) TODO(fxb/96705): Complete.
  • scope: (optional string or array of strings) TODO(fxb/96705): Complete.
  • availability: (optional string) availability (optional): The expectations around this capability's availability. One of:
    • required (default): a required dependency, the target of this offer must receive this capability.
    • optional: an optional dependency, the target of this offer may or may not receive this capability, and the target must consume this capability as optional.
    • same_as_target: the availability expectations of this capability will match whatever the target's. If the target requires the capability, then this field is set to required. If the target has an optional dependency on the capability, then the field is set to optional.
  • source_availability: (optional string) Whether or not the source of this offer must exist. If set to unknown, the source of this offer will be rewritten to void if the source does not exist (i.e. is not defined in this manifest). Defaults to required.

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: "full-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,
        }
    }
}