toolchain
toolchain 定义了单个构建平台的编译工具链。
节点属性
| 属性 | 内容 | 说明 |
|---|---|---|
| 是否可选 | 否 | - |
| 取值类型 | 工具链配置字典 | - |
| 取值范围 | 有效的工具链配置字典 | - |
节点说明
toolchain 定义构建平台的工具链配置:
yaml
platforms:
arm64:
toolchain:
# 源编译器 - 使用 source_type
c-compiler:
source_type: c
path: aarch64-none-elf-gcc
flags: "-Wall -O2 -std=c99 -nostdlib"
cpp-compiler:
source_type: cpp
path: aarch64-none-elf-g++
flags: "-Wall -O2 -std=c++17 -fno-exceptions"
assembler:
source_type: asm
path: aarch64-none-elf-gcc
flags: "-c -x assembler-with-cpp -D__ASSEMBLY__"
dtc-compiler:
source_type: dts
path: dtc
flags: "-I dts -O dtb"
# 构建工具 - 使用 tool_type
archiver:
tool_type: archiver
path: aarch64-none-elf-ar
flags: qc
linker:
tool_type: linker
path: aarch64-none-elf-ld
flags: "-static -nostartfiles"
objcopy:
tool_type: objcopy
path: aarch64-none-elf-objcopy
nm:
tool_type: nm
path: aarch64-none-elf-nm
size:
tool_type: size
path: aarch64-none-elf-size
strip:
tool_type: strip
path: aarch64-none-elf-strip
arm:
toolchain:
...
...在上面的示例中,包含了一个 ARM64 的交叉编译工具链配置。其中定义了多种源代码的编译器,以及其他工具(binutils)的配置。
工具配置
Catboy 将 toolchain 中定义的每一个工具,区分为「源编译器」或「构建工具」。其中:
- 「源编译器」:需要处理源代码的工具,如
gcc,g++,dtc等,常见为编译器。 - 「构建工具」:不处理源代码的工具,如
strip,ld,nm等,常见为binutil套件中的程序。
Catboy 通过在程序内部区分这两种工具类型来实现最大化的并行构建。两种工具类型的配置有细微不同:
源编译器配置
示例配置:
yaml
platforms:
arm64:
toolchain:
c-compiler:
source_type: c
path: aarch64-none-elf-gcc
flags: "-Wall -O2 -std=c99 -nostdlib"
...
...| 属性 | 可选 | 取值 | 示例值 | 说明 |
|---|---|---|---|---|
<tool> | 否 | 工具名字 | c-compiler | 字面值定义了工具的名称 |
source_type | 否 | 绑定的源代码类型 | c | 源代码列表中匹配的源代码类型使用本工具编译 *1 |
path | 否 | 可执行文件路径 | aarch64-none-elf-gcc | 相对路径或绝对路径皆可 *2 |
flags | 是 | 默认标志 | "-Wall -O2 -std=c99 -nostdlib" | 工具链级别的默认标志 *3 |
💡 提示
- 在源代码列表
sources中,你需要指定源代码的类型,例如c。Catboy 会查找工具链中,source_type与c匹配的工具来编译。 - Catboy 会自动处理 Windows 与 UNIX 的路径分隔符,你可以只使用
/。 - Catboy 具有标志追加与覆盖机制。此处定义的标志是工具的默认标志。用户可以在目标(
target)以及源文件级别追加其他标志,或是覆盖工具链的默认标志:
若标志的每层级配置如下:
- 工具链默认标志:
-Wall -O2 -std=c99 -nostdlib - 目标级标志:
-Wextra - 源代码文件单独配置的标志:
-Wno-unused-functions
则编译时,标志会按照自顶向下的层级合并:
gcc -Wall -O2 -std=c99 -nostdlib -Wextra -Wno-unused-functions ...构建工具配置
示例配置:
yaml
platforms:
arm64:
toolchain:
linker:
tool_type: linker
path: aarch64-none-elf-ld
flags: "-static -nostartfiles"
...
...| 属性 | 可选 | 取值 | 示例值 | 说明 |
|---|---|---|---|---|
<tool> | 否 | 工具名字 | linker | 字面值定义了工具的名称 |
tool_type | 否 | 工具类型 | linker | 取值范围 *1 |
path | 否 | 可执行文件路径 | aarch64-none-elf-ld | 相对路径或绝对路径皆可 *2 |
flags | 是 | 默认标志 | "-Wall -O2 -std=c99 -nostdlib" | 工具链级别的默认标志 *3 |
💡 提示
- Catboy 具有部分预定义的工具类型,同时允许用户拓展自己的工具类型。
- Catboy 会自动处理 Windows 与 UNIX 的路径分隔符,你可以只使用
/。 - Catboy 具有标志追加与覆盖机制。此处定义的标志是工具的默认标志。