ruki 3 år sedan
förälder
incheckning
08cd41d697

+ 45 - 0
mirror/package/remote_package.html

@@ -1082,6 +1082,51 @@ upgrading packages ..
   zlib: 1.2.10 -> 1.2.11
 1 package is upgraded!
 </code></pre>
+<h2 id="distributingandusingcustompackagerules">Distributing and using custom package rules</h2>
+<p>Since version 2.7.2 we have been able to add custom build rule scripts to the package management repository to enable dynamic distribution and installation following packages.</p>
+<p>We need to place the custom rules in the <code>packages/x/xxx/rules</code> directory of the repository and it will follow the package as it is installed.</p>
+<ul>
+<li>For in-package rules, we cannot add <code>on_load</code>, <code>after_load</code> scripts, but we can usually use <code>on_config</code> instead.</li>
+</ul>
+<h3 id="addingpackagerules">Adding package rules</h3>
+<p>We need to add the rules script to the rules fixed directory, for example: packages/z/zlib/rules/foo.lua</p>
+<pre><code class="lang-lua">rule("foo")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+</code></pre>
+<h3 id="applyingpackagerules">Applying package rules</h3>
+<p>The rules are used in a similar way as before, the only difference being that we need to specify which package&#39;s rules to access by prefixing them with <code>@packagename/</code>.</p>
+<p>The exact format: <code>add_rules("@packagename/rulename")`, e.g.:</code>add_rules("@zlib/foo")`.</p>
+<p><code></code>lua<br>add_requires("zlib", {system = false})<br>target("test")<br>    set_kind("binary")<br>    add_files("src/*.cpp")<br>    add_packages("zlib")<br>    add_rules("@zlib/foo")</p>
+<pre><code>
+### Referencing rules by package alias
+
+If a package alias exists, xmake will give preference to the package alias to get the rules.
+
+``` lua
+add_requires("zlib", {alias = "zlib2", system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib2")
+    add_rules("@zlib2/foo")
+</code></pre><h3 id="addingpackageruledependencies">Adding package rule dependencies</h3>
+<p>We can use <code>add_deps("@bar")</code> to add additional rules relative to the current package directory.</p>
+<p>However, we cannot add rule dependencies from other packages, they are completely isolated and we can only refer to rules from other packages imported by <code>add_requires</code> in the user project.</p>
+<p>packages/z/zlib/rules/foo.lua</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("@bar")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+</code></pre>
+<p>packages/z/zlib/rules/bar.lua</p>
+<pre><code class="lang-lua">rule("bar")
+    on_config(function (target)
+        print("bar: on_config %s", target:name())
+    end)
+</code></pre>
 <h2 id="usingxrepospackagemanagementincmake">Using Xrepo&#39;s package management in CMake</h2>
 <p>CMake wrapper for <a href="https://xrepo.xmake.io/">Xrepo</a> C and C++ package manager.</p>
 <p>This allows using CMake to build your project, while using Xrepo to manage<br>dependent packages. This project is partially inspired by<br><a href="https://github.com/conan-io/cmake-conan">cmake-conan</a>.</p>

+ 48 - 0
mirror/zh-cn/package/remote_package.html

@@ -1060,6 +1060,54 @@ upgrading packages ..
   zlib: 1.2.10 -> 1.2.11
 1 package is upgraded!
 </code></pre>
+<h2 id="">分发和使用自定义包规则</h2>
+<p>2.7.2 版本之后,我们可以在包管理仓库中,添加自定义构架规则脚本,实现跟随包进行动态下发和安装。</p>
+<p>我们需要将自定义规则放到仓库的 <code>packages/x/xxx/rules</code> 目录中,它会跟随包一起被安装。</p>
+<ul>
+<li>在包中规则,我们不能添加 <code>on_load</code>, <code>after_load</code> 脚本,但是通常我们可以使用 <code>on_config</code> 来代替。</li>
+</ul>
+<h3 id="">添加包规则</h3>
+<p>我们需要将规则脚本添加到 rules 固定目录下,例如:packages/z/zlib/rules/foo.lua</p>
+<pre><code class="lang-lua">rule("foo")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+</code></pre>
+<h3 id="">应用包规则</h3>
+<p>使用规则的方式跟之前类似,唯一的区别就是,我们需要通过 <code>@packagename/</code> 前缀去指定访问哪个包里面的规则。</p>
+<p>具体格式:<code>add_rules("@packagename/rulename")</code>,例如:<code>add_rules("@zlib/foo")</code>。</p>
+<pre><code class="lang-lua">add_requires("zlib", {system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib")
+    add_rules("@zlib/foo")
+</code></pre>
+<h3 id="">通过包别名引用规则</h3>
+<p>如果存在一个包的别名,xmake 将优先考虑包的别名来获得规则。</p>
+<pre><code class="lang-lua">add_requires("zlib", {alias = "zlib2", system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib2")
+    add_rules("@zlib2/foo")
+</code></pre>
+<h3 id="">添加包规则依赖</h3>
+<p>我们可以使用<code>add_deps("@bar")</code>来添加相对于当前包目录的其他规则。</p>
+<p>然而,我们不能添加来自其他包的规则依赖,它们是完全隔离的,我们只能参考用户项目中由<code>add_requires</code>导入的其他包的规则。</p>
+<p>packages/z/zlib/rules/foo.lua</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("@bar")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+</code></pre>
+<p>packages/z/zlib/rules/bar.lua</p>
+<pre><code class="lang-lua">rule("bar")
+    on_config(function (target)
+        print("bar: on_config %s", target:name())
+    end)
+</code></pre>
 <h2 id="cmakexrepo">在 CMake 中使用 Xrepo 的依赖包管理</h2>
 <p>我们新增了一个独立项目 <a href="https://github.com/xmake-io/xrepo-cmake">xrepo-cmake</a>。</p>
 <p>它是一个基于 Xrepo/Xmake 的 C/C++ 包管理器的 CMake 包装器。</p>

+ 72 - 0
package/remote_package.md

@@ -1530,6 +1530,78 @@ upgrading packages ..
 1 package is upgraded!
 ```
 
+## Distributing and using custom package rules
+
+Since version 2.7.2 we have been able to add custom build rule scripts to the package management repository to enable dynamic distribution and installation following packages.
+
+We need to place the custom rules in the `packages/x/xxx/rules` directory of the repository and it will follow the package as it is installed.
+
+- For in-package rules, we cannot add `on_load`, `after_load` scripts, but we can usually use `on_config` instead.
+
+### Adding package rules
+
+We need to add the rules script to the rules fixed directory, for example: packages/z/zlib/rules/foo.lua
+
+```lua
+rule("foo")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+```
+
+### Applying package rules
+
+The rules are used in a similar way as before, the only difference being that we need to specify which package's rules to access by prefixing them with `@packagename/`.
+
+The exact format: ``add_rules("@packagename/rulename")`, e.g.: ``add_rules("@zlib/foo")`.
+
+``lua
+add_requires("zlib", {system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib")
+    add_rules("@zlib/foo")
+```
+
+### Referencing rules by package alias
+
+If a package alias exists, xmake will give preference to the package alias to get the rules.
+
+``` lua
+add_requires("zlib", {alias = "zlib2", system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib2")
+    add_rules("@zlib2/foo")
+```
+
+### Adding package rule dependencies
+
+We can use `add_deps("@bar")` to add additional rules relative to the current package directory.
+
+However, we cannot add rule dependencies from other packages, they are completely isolated and we can only refer to rules from other packages imported by `add_requires` in the user project.
+
+packages/z/zlib/rules/foo.lua
+
+```lua
+rule("foo")
+    add_deps("@bar")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+```
+
+packages/z/zlib/rules/bar.lua
+
+```lua
+rule("bar")
+    on_config(function (target)
+        print("bar: on_config %s", target:name())
+    end)
+```
+
 ## Using Xrepo's package management in CMake
 
 CMake wrapper for [Xrepo](https://xrepo.xmake.io/) C and C++ package manager.

+ 100 - 100
sitemap.xml

@@ -12,502 +12,502 @@
 
 <url>
   <loc>https://xmake.io/mirror/guide/project_examples.html</loc>
-  <lastmod>2022-10-09T09:30:46+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:42+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/guide/quickstart.html</loc>
-  <lastmod>2022-10-09T09:30:47+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/guide/faq.html</loc>
-  <lastmod>2022-10-09T09:30:47+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/guide/configuration.html</loc>
-  <lastmod>2022-10-09T09:30:47+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/guide/syntax_description.html</loc>
-  <lastmod>2022-10-09T09:30:47+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/guide/installation.html</loc>
-  <lastmod>2022-10-09T09:30:47+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/remote_build.html</loc>
-  <lastmod>2022-10-09T09:30:48+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:43+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/unity_build.html</loc>
-  <lastmod>2022-10-09T09:30:48+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:44+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/distcc_build.html</loc>
-  <lastmod>2022-10-09T09:30:48+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:44+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/trybuild.html</loc>
-  <lastmod>2022-10-09T09:30:48+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:44+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/autogen.html</loc>
-  <lastmod>2022-10-09T09:30:48+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:44+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/features/build_cache.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:44+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/plugin/plugin_development.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/plugin/more_plugins.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/plugin/builtin_plugins.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/awesome.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/technical_support.html</loc>
-  <lastmod>2022-10-09T09:30:49+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/changelog.html</loc>
-  <lastmod>2022-10-09T09:30:50+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:45+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/contact.html</loc>
-  <lastmod>2022-10-09T09:30:50+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:46+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/introduction.html</loc>
-  <lastmod>2022-10-09T09:30:50+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:46+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/who_is_using_xmake.html</loc>
-  <lastmod>2022-10-09T09:30:50+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:46+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/about/sponsor.html</loc>
-  <lastmod>2022-10-09T09:30:50+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:46+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/index.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:46+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/project_examples.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/quickstart.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/faq.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/configuration.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/syntax_description.html</loc>
-  <lastmod>2022-10-09T09:30:51+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/guide/installation.html</loc>
-  <lastmod>2022-10-09T09:30:52+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:47+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/remote_build.html</loc>
-  <lastmod>2022-10-09T09:30:52+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:48+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/unity_build.html</loc>
-  <lastmod>2022-10-09T09:30:52+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:48+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/distcc_build.html</loc>
-  <lastmod>2022-10-09T09:30:52+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:48+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/trybuild.html</loc>
-  <lastmod>2022-10-09T09:30:52+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:48+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/autogen.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:48+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/features/build_cache.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/plugin/plugin_development.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/plugin/more_plugins.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/plugin/builtin_plugins.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/awesome.html</loc>
-  <lastmod>2022-10-09T09:30:53+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/technical_support.html</loc>
-  <lastmod>2022-10-09T09:30:54+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:49+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/changelog.html</loc>
-  <lastmod>2022-10-09T09:30:54+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:50+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/contact.html</loc>
-  <lastmod>2022-10-09T09:30:54+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:50+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/peripheral_items.html</loc>
-  <lastmod>2022-10-09T09:30:54+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:50+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/introduction.html</loc>
-  <lastmod>2022-10-09T09:30:54+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:50+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/who_is_using_xmake.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:50+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/sponsor.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:51+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/about/course.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:51+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/index.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:51+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/getting_started.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:51+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/specification.html</loc>
-  <lastmod>2022-10-09T09:30:55+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:51+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/builtin_variables.html</loc>
-  <lastmod>2022-10-09T09:30:56+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/conditions.html</loc>
-  <lastmod>2022-10-09T09:30:56+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/custom_rule.html</loc>
-  <lastmod>2022-10-09T09:30:56+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/target_instance.html</loc>
-  <lastmod>2022-10-09T09:30:56+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/project_target.html</loc>
-  <lastmod>2022-10-09T09:30:56+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/builtin_modules.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:52+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/custom_toolchain.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:53+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/plugin_task.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:53+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/package_dependencies.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:53+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/configuration_option.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:53+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/extension_modules.html</loc>
-  <lastmod>2022-10-09T09:30:57+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:53+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/helper_interfaces.html</loc>
-  <lastmod>2022-10-09T09:30:58+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:54+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/global_interfaces.html</loc>
-  <lastmod>2022-10-09T09:30:58+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:54+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/package_instance.html</loc>
-  <lastmod>2022-10-09T09:30:58+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:54+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/manual/option_instance.html</loc>
-  <lastmod>2022-10-09T09:30:58+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:54+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/theme/builtin_themes.html</loc>
-  <lastmod>2022-10-09T09:30:58+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:54+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/theme/switch_theme.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/package/local_3rd_source_library.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/package/local_package_old.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/package/local_package.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/package/system_package.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/package/remote_package.html</loc>
-  <lastmod>2022-10-09T09:30:59+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:55+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/toolchain/remote_toolchain.html</loc>
-  <lastmod>2022-10-09T09:31:00+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:56+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/zh-cn/toolchain/builtin_toolchains.html</loc>
-  <lastmod>2022-10-09T09:31:00+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:56+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/getting_started.html</loc>
-  <lastmod>2022-10-09T09:31:00+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:56+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/specification.html</loc>
-  <lastmod>2022-10-09T09:31:00+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:56+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/builtin_variables.html</loc>
-  <lastmod>2022-10-09T09:31:00+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:56+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/conditions.html</loc>
-  <lastmod>2022-10-09T09:31:01+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:57+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/custom_rule.html</loc>
-  <lastmod>2022-10-09T09:31:01+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:57+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/target_instance.html</loc>
-  <lastmod>2022-10-09T09:31:01+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:57+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/project_target.html</loc>
-  <lastmod>2022-10-09T09:31:01+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:57+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/builtin_modules.html</loc>
-  <lastmod>2022-10-09T09:31:01+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:57+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/custom_toolchain.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:58+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/plugin_task.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:58+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/package_dependencies.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:58+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/configuration_option.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:58+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/extension_modules.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:58+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/helper_interfaces.html</loc>
-  <lastmod>2022-10-09T09:31:02+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:59+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/global_interfaces.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:59+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/package_instance.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:59+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/manual/option_instance.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:59+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/theme/builtin_themes.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:50:59+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/theme/switch_theme.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/package/local_3rd_source_library.html</loc>
-  <lastmod>2022-10-09T09:31:03+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/package/local_package_old.html</loc>
-  <lastmod>2022-10-09T09:31:04+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/package/local_package.html</loc>
-  <lastmod>2022-10-09T09:31:04+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/package/system_package.html</loc>
-  <lastmod>2022-10-09T09:31:04+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/package/remote_package.html</loc>
-  <lastmod>2022-10-09T09:31:04+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:00+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/toolchain/remote_toolchain.html</loc>
-  <lastmod>2022-10-09T09:31:04+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:01+08:00</lastmod>
 </url>
 
 <url>
   <loc>https://xmake.io/mirror/toolchain/builtin_toolchains.html</loc>
-  <lastmod>2022-10-09T09:31:05+08:00</lastmod>
+  <lastmod>2022-10-09T09:51:01+08:00</lastmod>
 </url>
 
 </urlset>

+ 72 - 0
zh-cn/package/remote_package.md

@@ -1506,6 +1506,78 @@ upgrading packages ..
 1 package is upgraded!
 ```
 
+## 分发和使用自定义包规则
+
+2.7.2 版本之后,我们可以在包管理仓库中,添加自定义构架规则脚本,实现跟随包进行动态下发和安装。
+
+我们需要将自定义规则放到仓库的 `packages/x/xxx/rules` 目录中,它会跟随包一起被安装。
+
+- 在包中规则,我们不能添加 `on_load`, `after_load` 脚本,但是通常我们可以使用 `on_config` 来代替。
+
+### 添加包规则
+
+我们需要将规则脚本添加到 rules 固定目录下,例如:packages/z/zlib/rules/foo.lua
+
+```lua
+rule("foo")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+```
+
+### 应用包规则
+
+使用规则的方式跟之前类似,唯一的区别就是,我们需要通过 `@packagename/` 前缀去指定访问哪个包里面的规则。
+
+具体格式:`add_rules("@packagename/rulename")`,例如:`add_rules("@zlib/foo")`。
+
+```lua
+add_requires("zlib", {system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib")
+    add_rules("@zlib/foo")
+```
+
+### 通过包别名引用规则
+
+如果存在一个包的别名,xmake 将优先考虑包的别名来获得规则。
+
+```lua
+add_requires("zlib", {alias = "zlib2", system = false})
+target("test")
+    set_kind("binary")
+    add_files("src/*.cpp")
+    add_packages("zlib2")
+    add_rules("@zlib2/foo")
+```
+
+### 添加包规则依赖
+
+我们可以使用`add_deps("@bar")`来添加相对于当前包目录的其他规则。
+
+然而,我们不能添加来自其他包的规则依赖,它们是完全隔离的,我们只能参考用户项目中由`add_requires`导入的其他包的规则。
+
+packages/z/zlib/rules/foo.lua
+
+```lua
+rule("foo")
+    add_deps("@bar")
+    on_config(function (target)
+        print("foo: on_config %s", target:name())
+    end)
+```
+
+packages/z/zlib/rules/bar.lua
+
+```lua
+rule("bar")
+    on_config(function (target)
+        print("bar: on_config %s", target:name())
+    end)
+```
+
 ## 在 CMake 中使用 Xrepo 的依赖包管理
 
 我们新增了一个独立项目 [xrepo-cmake](https://github.com/xmake-io/xrepo-cmake)。