Skip to content

Commit afa0018

Browse files
committed
update docs
1 parent 05196d7 commit afa0018

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

docs/guide/package-management/distribute-private-libraries.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,38 +265,35 @@ Xmake will automatically pull the package description from the `my-repo` reposit
265265

266266
## Distribute C++ Modules Package {#distribute-cxx-modules}
267267

268-
Xmake also supports distributing C++ Modules libraries. We only need to add `{install = true}` in `add_files` to package and distribute module files (`.mpp`, `.ixx`, etc.) together.
268+
Xmake also supports distributing C++ Modules libraries.
269269

270-
Usually, we need to define the package in an independent repository.
270+
### Prepare Module Library {#prepare-module-library}
271271

272-
### Configure Library Project
273-
274-
In the `xmake.lua` of the library project, we need to export the module files:
272+
If it is a pure module library, we recommend configuring `set_kind("moduleonly")` in the project `xmake.lua` and exporting module files like `.mpp`.
275273

276274
```lua
277275
target("foo")
278-
set_kind("static")
279-
add_files("src/*.cpp")
280-
-- Install and distribute module files
281-
add_files("src/*.mpp", {install = true})
276+
set_kind("moduleonly")
277+
add_files("src/*.mpp")
282278
```
283279

284-
### Package Repository
280+
### Define Module Package {#define-module-package}
285281

286-
In the private package repository (e.g., `my-repo`), add the package description file `packages/f/foo/xmake.lua`:
282+
In the package description, we need to set `set_kind("library", {moduleonly = true})`. This tells Xmake to treat it as a pure module package, which does not require conventional library linking and handles module dependencies better.
287283

288284
```lua
289285
package("foo")
290-
add_urls("[email protected]:mycompany/foo.git")
291-
add_versions("1.0", "<commit-sha>")
292-
on_install(function (package)
293-
import("package.tools.xmake").install(package)
286+
set_kind("library", {moduleonly = true})
287+
set_sourcedir(path.join(os.scriptdir(), "src"))
288+
289+
on_install(function(package)
290+
import("package.tools.xmake").install(package, {})
294291
end)
295292
```
296293

297-
### Integration
294+
### Consume Module Package {#consume-module-package}
298295

299-
When integrating on the consumer side, you only need to import the repository and enable the `build.c++.modules` policy:
296+
When using module packages, we need to enable C++20 module build support.
300297

301298
```lua
302299
add_repositories("my-repo [email protected]:mycompany/my-repo.git")
@@ -305,9 +302,9 @@ add_requires("foo")
305302
target("bar")
306303
set_kind("binary")
307304
set_languages("c++20")
308-
-- Enable C++ Modules support
309-
set_policy("build.c++.modules", true)
310305
add_packages("foo")
306+
-- Enable C++ module build policy
307+
set_policy("build.c++.modules", true)
311308
```
312309

313310
For more complete examples, please refer to: [C++ Modules Package Distribution Example](https://github.com/xmake-io/xmake/tree/master/tests/projects/c%2B%2B/modules/packages).

docs/zh/guide/package-management/distribute-private-libraries.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,38 +263,35 @@ Xmake 会自动拉取 `my-repo` 仓库中的包描述,然后根据 `add_urls`
263263

264264
## 分发 C++ Modules {#distribute-cxx-modules}
265265

266-
Xmake 也支持分发 C++ Modules 库。我们只需要在 `add_files` 中添加 `{install = true}`,即可将模块文件(`.mpp`, `.ixx` 等)一同打包分发。
266+
Xmake 也支持分发 C++ Modules 库。
267267

268-
通常,我们需要将包定义在独立的仓库中。
268+
### 准备模块库 {#prepare-module-library}
269269

270-
### 库工程
271-
272-
在库工程的 `xmake.lua` 中,我们需要导出模块文件:
270+
如果是纯模块库,我们建议在工程 `xmake.lua` 中配置 `set_kind("moduleonly")`,并导出 `.mpp` 等模块文件。
273271

274272
```lua
275273
target("foo")
276-
set_kind("static")
277-
add_files("src/*.cpp")
278-
-- 安装分发模块文件
279-
add_files("src/*.mpp", {install = true})
274+
set_kind("moduleonly")
275+
add_files("src/*.mpp")
280276
```
281277

282-
### 配置包仓库
278+
### 定义模块包 {#define-module-package}
283279

284-
在私有包仓库(例如 `my-repo`)中,添加包描述文件 `packages/f/foo/xmake.lua`
280+
在包的描述域中,我们需要设置 `set_kind("library", {moduleonly = true})`,这样 Xmake 会将其作为纯模块包处理,不需要进行常规的库链接操作,也能更好地处理模块依赖。
285281

286282
```lua
287283
package("foo")
288-
add_urls("[email protected]:mycompany/foo.git")
289-
add_versions("1.0", "<commit-sha>")
290-
on_install(function (package)
291-
import("package.tools.xmake").install(package)
284+
set_kind("library", {moduleonly = true})
285+
set_sourcedir(path.join(os.scriptdir(), "src"))
286+
287+
on_install(function(package)
288+
import("package.tools.xmake").install(package, {})
292289
end)
293290
```
294291

295-
### 使用模块包
292+
### 使用模块包 {#consume-module-package}
296293

297-
消费端集成时,只需要引入仓库,并开启 `build.c++.modules` 策略:
294+
使用模块包时,我们需要开启 C++20 模块构建支持。
298295

299296
```lua
300297
add_repositories("my-repo [email protected]:mycompany/my-repo.git")
@@ -303,9 +300,9 @@ add_requires("foo")
303300
target("bar")
304301
set_kind("binary")
305302
set_languages("c++20")
306-
-- 开启 C++ Modules 支持
307-
set_policy("build.c++.modules", true)
308303
add_packages("foo")
304+
-- 开启 C++ 模块构建策略
305+
set_policy("build.c++.modules", true)
309306
```
310307

311308
更多完整示例,可以参考:[C++ Modules 包分发例子](https://github.com/xmake-io/xmake/tree/master/tests/projects/c%2B%2B/modules/packages)

0 commit comments

Comments
 (0)