Skip to content

Commit 7e93bf1

Browse files
committed
update post
1 parent f476ce8 commit 7e93bf1

2 files changed

Lines changed: 70 additions & 70 deletions

File tree

docs/posts/xmake-update-v3.1.1.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,18 @@ architectures, a reworked template distribution, and a `pkg` package manager for
2222
An addon extends **xmake itself**. Where a package provides libraries for your program, an
2323
addon provides new abilities for the build tool.
2424

25-
```sh
26-
$ xmake addon --install esp32-devel
27-
$ xmake create -t esp32.blink -l c blink
28-
$ cd blink
29-
$ xmake f --board=esp32c3
30-
$ xmake
31-
$ xmake install # flash it to the board
32-
```
33-
34-
Those five lines are the whole ESP32 setup: the addon carried the cross toolchain, the build
35-
rules, the flashing logic and the project template.
36-
3725
#### What an addon can carry
3826

3927
Every payload is optional, an addon ships only what it provides:
4028

4129
| Payload | What it becomes | Used as |
4230
| --- | --- | --- |
43-
| `plugins/` | a new xmake command | `xmake monitor` |
44-
| `rules/` | a build rule | `add_rules("@addon/esp32-devel/app")` |
45-
| `toolchains/` | a toolchain | `set_toolchains("@addon/esp32-devel/esp32")` |
46-
| `templates/` | a project template | `xmake create -t esp32.blink` |
47-
| `modules/` | importable lua modules | `import("@addon.serial-tools.serial")` |
48-
| `includes/` | includable configuration | `includes("@addon/esp32-devel/board")` |
31+
| `plugins/` | a new xmake command | `xmake hello` |
32+
| `rules/` | a build rule | `add_rules("@addon/my-addon/app")` |
33+
| `toolchains/` | a toolchain | `set_toolchains("@addon/my-addon/mycc")` |
34+
| `templates/` | a project template | `xmake create -t myapp` |
35+
| `modules/` | importable lua modules | `import("@addon.my-addon.utils")` |
36+
| `includes/` | includable configuration | `includes("@addon/my-addon/board")` |
4937

5038
The payloads are namespaced through `@addon/<name>/...`, so two addons never collide. Plugins
5139
and templates are the exception — a command name is global — and an install which would
@@ -54,14 +42,14 @@ shadow another addon's command is rejected.
5442
#### Managing addons
5543

5644
```sh
57-
$ xmake addon --install esp32-devel # from the repository index
58-
$ xmake addon --install github:xmake-addons/esp32-devel # from github, `#branch` works too
45+
$ xmake addon --install my-addon # from the repository index
46+
$ xmake addon --install github:myrepo/my-addon # from github, `#branch` works too
5947
$ xmake addon --install https://github.com/user/repo.git # from any git url
6048
$ xmake addon --install /path/to/my-addon # from a local directory
6149

6250
$ xmake addon --list
63-
$ xmake addon --search esp32
64-
$ xmake addon --remove esp32-devel
51+
$ xmake addon --search my
52+
$ xmake addon --remove my-addon
6553
$ xmake addon --upgrade
6654
```
6755

@@ -71,12 +59,12 @@ A project can declare what it needs, so a fresh clone does not have to install a
7159
hand — xmake fetches the missing addons when the project is loaded:
7260

7361
```lua
74-
add_addons("esp32-devel 1.0.x")
62+
add_addons("my-addon 1.0.x")
7563

76-
includes("@addon/esp32-devel/board")
64+
includes("@addon/my-addon/board")
7765

78-
target("blink")
79-
add_rules("@addon/esp32-devel/app")
66+
target("hello")
67+
add_rules("@addon/my-addon/app")
8068
add_files("src/*.c")
8169
```
8270

@@ -153,7 +141,7 @@ Three places, a handful of interfaces:
153141

154142
```lua
155143
-- 1. in xmake.lua, what a project needs
156-
add_addons("esp32-devel 1.0.x")
144+
add_addons("my-addon 1.0.x")
157145
```
158146

159147
```lua
@@ -164,7 +152,7 @@ addon("my-addon")
164152
set_license("Apache-2.0")
165153
set_sourcedir("src") -- the payload root inside the repository
166154
add_deps("serial-tools") -- other addons this one needs
167-
add_globalmodules("detect.tools.find_avrdude") -- only for the lookups xmake does by name
155+
add_globalmodules("detect.tools.find_mytool") -- only for the lookups xmake does by name
168156
```
169157

170158
```lua
@@ -206,10 +194,10 @@ carries the package recipes and exposes them through an includes file:
206194

207195
```lua
208196
-- src/includes/packages/xmake.lua
209-
package("avr-gcc")
197+
package("mycc")
210198
set_kind("toolchain")
211-
add_urls("https://.../avr-gcc-$(version).tar.bz2")
212-
add_versions("7.3.0", "<sha256>")
199+
add_urls("https://.../mycc-$(version).tar.gz")
200+
add_versions("1.0.0", "<sha256>")
213201
on_install(function (package)
214202
os.cp("*", package:installdir())
215203
end)
@@ -219,11 +207,11 @@ package_end()
219207
```lua
220208
-- src/includes/board/xmake.lua
221209
includes("../packages")
222-
option("board", {default = "uno", description = "Set the target board."})
223-
add_requires("avr-gcc", "avrdude")
210+
option("board", {default = "myboard", description = "Set the target board."})
211+
add_requires("mycc", "myflasher")
224212
```
225213

226-
The project writes one line — `includes("@addon/avr-devel/board")` — and gets the options,
214+
The project writes one line — `includes("@addon/my-addon/board")` — and gets the options,
227215
the toolchain and the flash tool.
228216

229217
#### The official addons
@@ -240,6 +228,18 @@ The first batch is already in xmake-repo:
240228
| `format-plugin` / `doxygen-plugin` / `macro-plugin` | the former builtin commands |
241229
| `basic-templates` | the templates which need an external sdk (sdl, qt, verilator) |
242230

231+
`esp32-devel`, for instance, carries the cross toolchain, the build rules, the flashing logic
232+
and the project template, so the whole ESP32 setup is:
233+
234+
```sh
235+
$ xmake addon --install esp32-devel
236+
$ xmake create -t esp32.blink -l c blink
237+
$ cd blink
238+
$ xmake f --board=esp32c3
239+
$ xmake
240+
$ xmake install # flash it to the board
241+
```
242+
243243
### xmake ai, an Agent Written in Xmake Lua
244244

245245
[xmake-harness](https://github.com/xmake-addons/xmake-harness) is the addon that shows how far
@@ -375,8 +375,8 @@ New architectures for the cross and linux platforms, e.g. SPARC64.
375375
### Reworked Template Distribution
376376

377377
The templates directory was reorganized and the distribution reworked, which is what makes the
378-
`templates/` payload of an addon possible — `xmake create -t esp32.blink` comes from an addon,
379-
not from the xmake installation.
378+
`templates/` payload of an addon possible — the templates behind `xmake create -t` can now come
379+
from an addon instead of being built into the xmake installation.
380380

381381
### pkg Package Manager for BSD
382382

docs/zh/posts/xmake-update-v3.1.1.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,32 @@ outline: deep
1616

1717
我们平时用的包,提供的是程序要链接的库,而 addon 扩展的是 xmake 本身,给构建工具增加新的能力。
1818

19-
```sh
20-
$ xmake addon --install esp32-devel
21-
$ xmake create -t esp32.blink -l c blink
22-
$ cd blink
23-
$ xmake f --board=esp32c3
24-
$ xmake
25-
$ xmake install # 烧写到板子
26-
```
27-
28-
整个 ESP32 的开发流程就这几行,交叉工具链、构建规则、烧写逻辑和工程模板,全部由这个 addon 提供,用户不需要再单独去装任何东西。
29-
3019
#### 一个 addon 可以提供什么
3120

3221
下面这几类扩展内容都是可选的,addon 提供哪些就带哪些:
3322

3423
| 目录 | 提供的能力 | 使用方式 |
3524
| --- | --- | --- |
36-
| `plugins/` | 新的 xmake 命令 | `xmake monitor` |
37-
| `rules/` | 构建规则 | `add_rules("@addon/esp32-devel/app")` |
38-
| `toolchains/` | 工具链 | `set_toolchains("@addon/esp32-devel/esp32")` |
39-
| `templates/` | 工程模板 | `xmake create -t esp32.blink` |
40-
| `modules/` | 可导入的 lua 模块 | `import("@addon.serial-tools.serial")` |
41-
| `includes/` | 可包含的配置片段 | `includes("@addon/esp32-devel/board")` |
25+
| `plugins/` | 新的 xmake 命令 | `xmake hello` |
26+
| `rules/` | 构建规则 | `add_rules("@addon/my-addon/app")` |
27+
| `toolchains/` | 工具链 | `set_toolchains("@addon/my-addon/mycc")` |
28+
| `templates/` | 工程模板 | `xmake create -t myapp` |
29+
| `modules/` | 可导入的 lua 模块 | `import("@addon.my-addon.utils")` |
30+
| `includes/` | 可包含的配置片段 | `includes("@addon/my-addon/board")` |
4231

4332
这些扩展内容都是带命名空间的,统一通过 `@addon/<name>/...` 来引用,所以两个 addon 即使提供了同名的规则也不会冲突。只有插件和模板是例外,因为命令名和模板 id 是全局的,如果安装的 addon 会覆盖掉别的 addon 的命令,xmake 会直接拒绝。
4433

4534
#### addon 的管理
4635

4736
```sh
48-
$ xmake addon --install esp32-devel # 从仓库索引安装
49-
$ xmake addon --install github:xmake-addons/esp32-devel # 从 github 安装,支持 `#branch`
37+
$ xmake addon --install my-addon # 从仓库索引安装
38+
$ xmake addon --install github:myrepo/my-addon # 从 github 安装,支持 `#branch`
5039
$ xmake addon --install https://github.com/user/repo.git # 从任意 git url 安装
5140
$ xmake addon --install /path/to/my-addon # 从本地目录安装
5241

5342
$ xmake addon --list
54-
$ xmake addon --search esp32
55-
$ xmake addon --remove esp32-devel
43+
$ xmake addon --search my
44+
$ xmake addon --remove my-addon
5645
$ xmake addon --upgrade
5746
```
5847

@@ -61,12 +50,12 @@ $ xmake addon --upgrade
6150
工程也可以直接声明自己需要哪些 addon,这样别人克隆下来就不用手动安装了,加载工程的时候,xmake 会自动把缺失的 addon 拉下来:
6251

6352
```lua
64-
add_addons("esp32-devel 1.0.x")
53+
add_addons("my-addon 1.0.x")
6554

66-
includes("@addon/esp32-devel/board")
55+
includes("@addon/my-addon/board")
6756

68-
target("blink")
69-
add_rules("@addon/esp32-devel/app")
57+
target("hello")
58+
add_rules("@addon/my-addon/app")
7059
add_files("src/*.c")
7160
```
7261

@@ -139,7 +128,7 @@ addon 相关的接口不多,主要就是下面三个地方:
139128

140129
```lua
141130
-- 1. 在 xmake.lua 中,声明工程需要哪些 addon
142-
add_addons("esp32-devel 1.0.x")
131+
add_addons("my-addon 1.0.x")
143132
```
144133

145134
```lua
@@ -150,7 +139,7 @@ addon("my-addon")
150139
set_license("Apache-2.0")
151140
set_sourcedir("src") -- 仓库内存放扩展目录的根目录
152141
add_deps("serial-tools") -- 依赖的其他 addon
153-
add_globalmodules("detect.tools.find_avrdude") -- 只有需要被 xmake 按名字查找的模块才用得上
142+
add_globalmodules("detect.tools.find_mytool") -- 只有需要被 xmake 按名字查找的模块才用得上
154143
```
155144

156145
```lua
@@ -187,10 +176,10 @@ addon 提供的所有东西,都要通过 `@addon/<name>/...` 或者 `@addon.<n
187176

188177
```lua
189178
-- src/includes/packages/xmake.lua
190-
package("avr-gcc")
179+
package("mycc")
191180
set_kind("toolchain")
192-
add_urls("https://.../avr-gcc-$(version).tar.bz2")
193-
add_versions("7.3.0", "<sha256>")
181+
add_urls("https://.../mycc-$(version).tar.gz")
182+
add_versions("1.0.0", "<sha256>")
194183
on_install(function (package)
195184
os.cp("*", package:installdir())
196185
end)
@@ -200,11 +189,11 @@ package_end()
200189
```lua
201190
-- src/includes/board/xmake.lua
202191
includes("../packages")
203-
option("board", {default = "uno", description = "Set the target board."})
204-
add_requires("avr-gcc", "avrdude")
192+
option("board", {default = "myboard", description = "Set the target board."})
193+
add_requires("mycc", "myflasher")
205194
```
206195

207-
工程里只需要 `includes("@addon/avr-devel/board")` 一行,配置选项、工具链和烧写工具就都齐了。
196+
工程里只需要 `includes("@addon/my-addon/board")` 一行,配置选项、工具链和烧写工具就都齐了。
208197

209198
#### 目前提供的官方 addon
210199

@@ -220,6 +209,17 @@ add_requires("avr-gcc", "avrdude")
220209
| `format-plugin` / `doxygen-plugin` / `macro-plugin` | 原来的几个内置命令 |
221210
| `basic-templates` | 依赖外部 SDK 的工程模板(sdl、qt、verilator) |
222211

212+
`esp32-devel` 为例,交叉工具链、构建规则、烧写逻辑和工程模板都由它提供,所以整个 ESP32 的开发流程就这么几行,用户不需要再单独去装什么东西:
213+
214+
```sh
215+
$ xmake addon --install esp32-devel
216+
$ xmake create -t esp32.blink -l c blink
217+
$ cd blink
218+
$ xmake f --board=esp32c3
219+
$ xmake
220+
$ xmake install # 烧写到板子
221+
```
222+
223223
### xmake ai,用 xmake lua 写的 AI 助手
224224

225225
[xmake-harness](https://github.com/xmake-addons/xmake-harness) 这个 addon 算是把 addon 的能力用到了极致,它是一个完整的 AI Agent 框架,会话记录、agent 主循环、工具管线、权限策略、沙箱、skills、子 agent、斜杠命令和终端 UI,全部用 xmake lua 实现,没有任何第三方依赖。装上之后就多了一个 `xmake ai` 命令:
@@ -332,7 +332,7 @@ set_policy("package.host.install_locally", true) -- 如果你确实想让工
332332

333333
### 重构模板分发
334334

335-
我们重新组织了模板目录,也重构了模板的分发方式,addon 的 `templates/` 目录正是基于这个改动才能实现,`xmake create -t esp32.blink` 这个模板来自 addon,而不是 xmake 安装包自带的
335+
我们重新组织了模板目录,也重构了模板的分发方式,addon 的 `templates/` 目录正是基于这个改动才能实现,`xmake create -t` 用到的模板现在可以由 addon 提供,而不必内置在 xmake 安装包里
336336

337337
### BSD 的 pkg 包管理器
338338

0 commit comments

Comments
 (0)