1. 主页
  2. 文档
  3. Fuchsia OS 简体中文文档 2022...
  4. Fuchsia 入门
  5. 构建 Fuchsia

构建 Fuchsia

这篇文档将引导您在主机上配置并构建 Fuchsia。

步骤如下:

  1. 前提条件
  2. 设置构建配置
  3. 提升构建速度(可选)
  4. 构建 Fuchsia

    1. 前提条件 {#prerequisites}

    在开始之前,请先检查是否满足如下要求:

    • 源代码设置
    • 硬件要求

      源代码设置 {#source-code-setup}

      根据文档下载 Fuchsia 源代码指示下载 Fuchsia 的源代码,然后在您的计算机上设置开发环境。

      硬件要求 {#hardware-requirements}

      您只能在具有下列主机架构之一的计算机上构建 Fuchsia:

      <!–

    • x86-64 Linux (Debian-based distributions only)
    • x86-64 macOS
      –>
    • x86-64 Linux (只支持基于 Debian 系列的发行版)
    • x86-64 macOS

      注意:不支持 Windows 和 ARM64。

      2. 设置构建配置 {#set-your-build-configuration}

      Fuchsia 的构建配置告诉构建系统进行构建的产品,以及构建面向的平台。

      <!–
      To set your Fuchsia build configuration, run the following
      [fx set][fx-set-reference] command:
      –>

      要设置您的 Fuchsia 构建配置,请运行 fx set 命令:

      fx set {{ '<var>' }}PRODUCT{{ '</var>' }}.{{ '<var>' }}BOARD{{ '</var>' }}

      请替换以下选项:

      <!–

    • PRODUCT: The Fuchsia product that you want to build; for example, core and
      workstation_eng.
    • BOARD: The architecture of the product; for example, x64 and qemu-x64
      –>
    • PRODUCT(产品):您想要构建的 Fuchsia 产品,比如:coreworkstation_eng
    • BOARD(板型):产品的可执行文件架构,比如:x64qemu-x64
      <!–
      The example command below sets a build configuration to core.qemu-x64:
      –>

      下面的示例将一项构建配置设置为 core.qemu-x64

fx set core.qemu-x64

在这个示例中:

<!–
* core is a product with the minimum feature set of Fuchsia, including
common network capabilities.
* qemu-x64 is a board that refers to the x64 architecture of the Fuchsia
emulator (FEMU), which is based on the open source emulator
[QEMU][qemu]{:.external}.
–>

  • core 是 Fuchsia 具备最小功能集的产品,包括常用的网络功能。
  • qemu-x64 是 Fuchsia 模拟器(FEMU)的 x64 架构这一板型,FEMU 基于开源模拟器 QEMU{:.external}。
    <!–
    On the other hand, the example below sets the build configuration to
    workstation_eng.x64, which is commonly used to
    [install Fuchsia’s Workstation product on a device][build-workstation]:
    –>

    另外,下面的例子将一项构建配置设置为 workstation_eng.x64,这常用于在设备上安装 Fuchsia 工作站

fx set workstation_eng.x64

要获取关于构建配置的更多信息,请参阅配置构建

3. 提升构建速度(可选) {#speed-up-the-build}

注意:这一步对于构建 Fuchsia 而言并不是必需的,但是可以在您构建 Fuchsia 时节省很多时间,因此建议您完成该步骤。

要提升 Fuchsia 构建速度,您可以使用下列服务之一:

  • 启用 Goma
  • 安装 ccache

    启用 Goma {#enable-goma}

    Goma{:.external} 是一个分布式编译器服务,适用于 Chrome、Android 和 Fuchsia 等开源项目。

    如果您能访问 Goma, 请在您的计算机上 Goma 客户端:

fx goma

安装 ccache {#install-ccache}

<!–
If you do not have access to Goma, but want to accelerate the Fuchsia build
locally, use ccache{:.external} to cache
artifacts from previous builds.
–>
如果您无法访问 Goma,但想在本地加速构建,则可以使用 ccache{:.external} 缓存之前构建的产物。

  • {Linux}
    <!–
    To use ccache on Linux, install the following package:
    –>

    要在 Linux 上使用 ccache,请安装如下安装包:

    sudo apt install ccache
  • {macOS}

    对于 macOS ,请参阅在 Mac 上使用 CCache{:.external} 中的安装步骤。

    <!–
    ccache is enabled automatically if your CCACHE_DIR environment variable
    refers to an existing directory.
    –>

    如果您的 CCACHE_DIR 环境变量指向已有路径,那么 ccache 就会自动开启。

    <!–
    To override this default behavior, specify the following flags to fx set:
    –>

    要覆盖此默认行为,请为 fx set 指定以下标志:

    <!–

  • Force the use of ccache even when other accelerators are available:
    –>
  • 即使其他的加速项可用,也要强制使用 ccache,则:

    fx set PRODUCT.BOARD --ccache
    

    <!–

  • Disable the use of ccache:
    –>
  • 要禁用 ccache
    fx set PRODUCT.BOARD --no-ccache
    

    4. 构建 Fuchsia {#build-fuchsia}

    <!–
    The [fx build][fx-build-reference] command executes the build to transform
    source code into packages and other build artifacts.
    –>

    fx build 命令可以把源代码构建打包,或者构建成其他的类型。

    要构建 Fuchsia,请运行以下命令:

    注意:构建时间一般为 90 分钟。

fx build

<!–
When you modify source code, run the fx build command again to perform an
incremental build, or run the fx -i build command to start a watcher, which
automatically builds whenever you update the source code.
–>

当您修改源代码后,请再次运行命令 fx build 进行增量构建,或者运行 fx -i build 命令来开启一个监视进程,这个监视进程会在发现源代码更新时自动构建。

要获取关于构建 Fuchsia 的更多信息,请参阅执行构建

后续步骤

要在您的计算机上启动 Fuchsia 模拟器 (FEMU),请参阅开启 Fuchsia 模拟器

不过,如果您想在硬件设备上运行 Fuchsia,请参阅在设备上安装 Fuchsia

我们要如何帮助您?

Comments

Leave a reply

您的电子邮箱地址不会被公开。 必填项已用*标注