Explorar o código

add add_deps for rules

ruki %!s(int64=3) %!d(string=hai) anos
pai
achega
ea6b0c7ca8

+ 64 - 0
manual/custom_rule.md

@@ -750,6 +750,70 @@ rule("markdown")
     end)
 ```
 
+### rule:add_deps
+
+#### Adding rule dependencies
+
+Associated dependencies can bind a batch of rules, i.e. instead of adding rules one by one to a target using `add_rules()`, just apply a rule that will take effect for it and all its dependencies.
+
+For example
+
+```lua
+rule("foo")
+    add_deps("bar")
+
+rule("bar")
+   ...
+```
+
+We only need `add_rules("foo")` to apply both foo and bar rules.
+
+However, by default there is no order of execution between dependencies, and scripts such as `on_build_file` for foo and bar are executed in parallel, in an undefined order.
+
+To strictly control the order of execution, you can configure `add_deps("bar", {order = true})` to tell xmake that we need to execute scripts at the same level according to the order of dependencies.
+
+Example.
+
+```lua
+rule("foo")
+    add_deps("bar", {order = true})
+    on_build_file(function (target, sourcefile)
+    end)
+
+rule("bar")
+    on_build_file(function (target, sourcefile)
+    end)
+```
+
+bar's `on_build_file` will be executed first.
+
+!> To control the order of dependencies, we need xmake 2.7.2 or above to support this.
+
+However, this way of controlling dependencies only works if both foo and bar rules are custom rules, and this does not work if you want to insert your own rules to be executed before xmake's built-in rules.
+
+In this case, we need to use a more flexible dynamic rule creation and injection approach to modify the built-in rules.
+
+For example, if we want to execute the `on_build_file` script for a custom cppfront rule before the built-in `c++.build` rule, we can do this in the following way.
+
+```lua
+rule("cppfront")
+    set_extensions(".cpp2")
+    on_load(function (target)
+        local rule = target:rule("c++.build"):clone()
+        rule:add("deps", "cppfront", {order = true})
+        target:rule_add(rule)
+    end)
+    on_build_file(function (target, sourcefile, opt)
+        print("build cppfront file")
+    end)
+
+target("test")
+    set_kind("binary")
+    add_rules("cppfront")
+    add_files("src/*.cpp")
+    add_files("src/*.cpp2")
+```
+
 ### rule:add_imports
 
 #### Add imported modules for all custom scripts

+ 45 - 0
mirror/manual/custom_rule.html

@@ -588,6 +588,51 @@ target("example")
         os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
     end)
 </code></pre>
+<h3 id="ruleadd_deps">rule:add_deps</h3>
+<h4 id="addingruledependencies">Adding rule dependencies</h4>
+<p>Associated dependencies can bind a batch of rules, i.e. instead of adding rules one by one to a target using <code>add_rules()</code>, just apply a rule that will take effect for it and all its dependencies.</p>
+<p>For example</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("bar")
+
+rule("bar")
+   ...
+</code></pre>
+<p>We only need <code>add_rules("foo")</code> to apply both foo and bar rules.</p>
+<p>However, by default there is no order of execution between dependencies, and scripts such as <code>on_build_file</code> for foo and bar are executed in parallel, in an undefined order.</p>
+<p>To strictly control the order of execution, you can configure <code>add_deps("bar", {order = true})</code> to tell xmake that we need to execute scripts at the same level according to the order of dependencies.</p>
+<p>Example.</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("bar", {order = true})
+    on_build_file(function (target, sourcefile)
+    end)
+
+rule("bar")
+    on_build_file(function (target, sourcefile)
+    end)
+</code></pre>
+<p>bar&#39;s <code>on_build_file</code> will be executed first.</p>
+<p>!> To control the order of dependencies, we need xmake 2.7.2 or above to support this.</p>
+<p>However, this way of controlling dependencies only works if both foo and bar rules are custom rules, and this does not work if you want to insert your own rules to be executed before xmake&#39;s built-in rules.</p>
+<p>In this case, we need to use a more flexible dynamic rule creation and injection approach to modify the built-in rules.</p>
+<p>For example, if we want to execute the <code>on_build_file</code> script for a custom cppfront rule before the built-in <code>c++.build</code> rule, we can do this in the following way.</p>
+<pre><code class="lang-lua">rule("cppfront")
+    set_extensions(".cpp2")
+    on_load(function (target)
+        local rule = target:rule("c++.build"):clone()
+        rule:add("deps", "cppfront", {order = true})
+        target:rule_add(rule)
+    end)
+    on_build_file(function (target, sourcefile, opt)
+        print("build cppfront file")
+    end)
+
+target("test")
+    set_kind("binary")
+    add_rules("cppfront")
+    add_files("src/*.cpp")
+    add_files("src/*.cpp2")
+</code></pre>
 <h3 id="ruleadd_imports">rule:add_imports</h3>
 <h4 id="addimportedmodulesforallcustomscripts">Add imported modules for all custom scripts</h4>
 <p>For usage and description, please see: <a href="#targetadd_imports">target:add_imports</a>, the usage is the same.</p>

+ 45 - 0
mirror/zh-cn/manual/custom_rule.html

@@ -591,6 +591,51 @@ target("example")
         os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
     end)
 </code></pre>
+<h3 id="ruleadd_deps">rule:add_deps</h3>
+<h4 id="">添加规则依赖</h4>
+<p>关联依赖可以绑定一批规则,也就是不必对 target 挨个去使用 <code>add_rules()</code> 添加规则,只需要应用一个规则,就能生效它和它的所有依赖规则。</p>
+<p>例如:</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("bar")
+
+rule("bar")
+   ...
+</code></pre>
+<p>我们只需要 <code>add_rules("foo")</code>,就能同时应用 foo 和 bar 两个规则。</p>
+<p>但是,默认情况下,依赖之间是不存在执行的先后顺序的,foo 和 bar 的 <code>on_build_file</code> 等脚本是并行执行的,顺序未定义。</p>
+<p>如果要严格控制执行顺序,可以配置 <code>add_deps("bar", {order = true})</code>,告诉 xmake,我们需要根据依赖顺序来执行同级别的脚本。</p>
+<p>例如:</p>
+<pre><code class="lang-lua">rule("foo")
+    add_deps("bar", {order = true})
+    on_build_file(function (target, sourcefile)
+    end)
+
+rule("bar")
+    on_build_file(function (target, sourcefile)
+    end)
+</code></pre>
+<p>bar 的 <code>on_build_file</code> 将会被先执行。</p>
+<p>!> 控制依赖顺序,我们需要 xmake 2.7.2 以上版本才支持。</p>
+<p>不过,这种控制依赖的方式,只适合 foo 和 bar 两个规则都是自定义规则,如果想要将自己的规则插入到 xmake 的内置规则之前执行,这就不适用了。</p>
+<p>这个时候,我们需要使用更加灵活的动态规则创建和注入的方式,去修改内置规则。</p>
+<p>例如,我们想在内置的 <code>c++.build</code> 规则之前,执行自定义 cppfront 规则的 <code>on_build_file</code> 脚本,我们可以通过下面的方式来实现。</p>
+<pre><code class="lang-lua">rule("cppfront")
+    set_extensions(".cpp2")
+    on_load(function (target)
+        local rule = target:rule("c++.build"):clone()
+        rule:add("deps", "cppfront", {order = true})
+        target:rule_add(rule)
+    end)
+    on_build_file(function (target, sourcefile, opt)
+        print("build cppfront file")
+    end)
+
+target("test")
+    set_kind("binary")
+    add_rules("cppfront")
+    add_files("src/*.cpp")
+    add_files("src/*.cpp2")
+</code></pre>
 <h3 id="ruleadd_imports">rule:add_imports</h3>
 <h4 id="">为所有自定义脚本预先导入扩展模块</h4>
 <p>使用方式和说明请见:<a href="#targetadd_imports">target:add_imports</a>,用法相同。</p>

+ 100 - 100
sitemap.xml

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

+ 64 - 0
zh-cn/manual/custom_rule.md

@@ -752,6 +752,70 @@ rule("markdown")
     end)
 ```
 
+### rule:add_deps
+
+#### 添加规则依赖
+
+关联依赖可以绑定一批规则,也就是不必对 target 挨个去使用 `add_rules()` 添加规则,只需要应用一个规则,就能生效它和它的所有依赖规则。
+
+例如:
+
+```lua
+rule("foo")
+    add_deps("bar")
+
+rule("bar")
+   ...
+```
+
+我们只需要 `add_rules("foo")`,就能同时应用 foo 和 bar 两个规则。
+
+但是,默认情况下,依赖之间是不存在执行的先后顺序的,foo 和 bar 的 `on_build_file` 等脚本是并行执行的,顺序未定义。
+
+如果要严格控制执行顺序,可以配置 `add_deps("bar", {order = true})`,告诉 xmake,我们需要根据依赖顺序来执行同级别的脚本。
+
+例如:
+
+```lua
+rule("foo")
+    add_deps("bar", {order = true})
+    on_build_file(function (target, sourcefile)
+    end)
+
+rule("bar")
+    on_build_file(function (target, sourcefile)
+    end)
+```
+
+bar 的 `on_build_file` 将会被先执行。
+
+!> 控制依赖顺序,我们需要 xmake 2.7.2 以上版本才支持。
+
+不过,这种控制依赖的方式,只适合 foo 和 bar 两个规则都是自定义规则,如果想要将自己的规则插入到 xmake 的内置规则之前执行,这就不适用了。
+
+这个时候,我们需要使用更加灵活的动态规则创建和注入的方式,去修改内置规则。
+
+例如,我们想在内置的 `c++.build` 规则之前,执行自定义 cppfront 规则的 `on_build_file` 脚本,我们可以通过下面的方式来实现。
+
+```lua
+rule("cppfront")
+    set_extensions(".cpp2")
+    on_load(function (target)
+        local rule = target:rule("c++.build"):clone()
+        rule:add("deps", "cppfront", {order = true})
+        target:rule_add(rule)
+    end)
+    on_build_file(function (target, sourcefile, opt)
+        print("build cppfront file")
+    end)
+
+target("test")
+    set_kind("binary")
+    add_rules("cppfront")
+    add_files("src/*.cpp")
+    add_files("src/*.cpp2")
+```
+
 ### rule:add_imports
 
 #### 为所有自定义脚本预先导入扩展模块