ruki пре 5 година
родитељ
комит
54893cce9a

+ 16 - 2
manual/builtin_modules.md

@@ -923,10 +923,24 @@ Similar to [os.exec](#osexec), just the way to pass parameters is passed through
 
 ```lua
 os.execv("echo", {"hello", "xmake!"})
-os.execv("echo", {"hello", "xmake!"}, {stdout = "/tmp/out", stderr = io.open("/tmp/err", 'w')})
-os.execv("echo", {"hello", "xmake!"}, {envs = {PATH="..."}})
 ```
 
+In addition, this interface also supports an optional parameter for passing settings: redirect output, perform environment variable settings, for example:
+
+```lua
+os.execv("echo", {"hello", "xmake!"}, {stdout = outfile, stderr = errfile, envs = {PATH = "xxx;xx", CFLAGS = "xx"}}
+```
+
+Among them, the stdout and stderr parameters are used to pass redirected output and error output. You can directly pass in the file path or the file object opened by io.open.
+
+After v2.5.1, we also support setting the stdin parameter to support redirecting input files.
+
+!> stdout/stderr/stdin can simultaneously support three types of values: file path, file object, and pipe object.
+
+In addition, if you want to temporarily set and rewrite some environment variables during this execution, you can pass the envs parameter. The environment variable settings inside will replace the existing settings, but will not affect the outer execution environment, only the current command.
+
+We can also get all the current environment variables through the `os.getenvs()` interface, and then pass in the envs parameter after rewriting some parts.
+
 #### os.iorun
 
 - Quietly running native shell commands and getting output

+ 39 - 0
manual/project_target.md

@@ -125,6 +125,7 @@ target("test2")
 | [set_policy](#targetset_policy)                 | Set build policy                                          | >= 2.3.4                    |
 | [set_plat](#targetset_plat)                     | Set the compilation platform for the specified target     | >= 2.3.5                    |
 | [set_arch](#targetset_arch)                     | Set the compilation architecture for the specified target | >= 2.3.5                    |
+| [set_runtimes](#targetset_runtimes)             | Set the runtime library of the compilation target         | >= 2.5.1                    |
 
 ### target
 
@@ -2556,3 +2557,41 @@ Of course, if the build source files in some special targets depend on previous
 ```bash
 set_policy("build.across_targets_in_parallel", false)
 ```
+
+### target:set_runtimes
+
+#### Set the runtime library of the compilation target
+
+This is a newly added interface since v2.5.1, which is used to abstractly set the runtime library that the compilation target depends on. Currently, only the abstraction of the msvc runtime library is supported, but the mapping to other compiler runtime libraries may be expanded in the future.
+
+Some of the currently supported configuration values are described as follows:
+
+
+| Value  | Description                                                  |
+| ------ | -----------------------------------------                    |
+| MT     | msvc runtime library: multithreaded static library           |
+| MTd    | msvc runtime library: multithreaded static library (debug)   |
+| MD     | msvc runtime library: multi-threaded dynamic library         |
+| MDd    | msvc runtime library: multi-threaded dynamic library (debug) |
+
+About vs runtime, you can refer to: [msvc runtime description](https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view =msvc-160)
+
+And this interface passes in the MT/MTd parameter configuration, xmake will automatically configure the `/MT /nodefaultlib:msvcrt.lib` parameter.
+
+We can set different runtimes for different targets.
+
+In addition, if we set `set_runtimes` in the global root domain, then all `add_requires("xx")` package definitions will also be globally synchronized to the corresponding vs runtime configuration
+
+```lua
+set_runtimes("MD")
+add_requires("libcurl", "fmt")
+target("test")
+   set_kind("binary")
+   add_files("src/*.c")
+```
+
+Of course, we can also use `add_requires("xx", {configs = {vs_runtime = "MD"}})` to modify the vs runtime library for specific packages.
+
+We can also use `xmake f --vs_runtime=MD` to switch it globally through parameter configuration.
+
+Issues related to this api: [#1071](https://github.com/xmake-io/xmake/issues/1071#issuecomment-750817681)

+ 10 - 1
plugin/builtin_plugins.md

@@ -80,7 +80,7 @@ $ xmake project -k [vsxmake2010|vsxmake2013|vsxmake2015|..] -m "debug;release"
 If no version is specified, xmake will automatically detect the current version of vs to generate:
 
 ```bash
-$ xmake project -k vsxmake -m "debug;release"
+$ xmake project -k vsxmake -m "debug,release"
 ```
 
 ![](/assets/img/manual/qt_vs.png)
@@ -89,6 +89,15 @@ In addition, the vsxmake plugin will additionally generate a custom configuratio
 
 ![](/assets/img/manual/property_page_vsxmake.png)
 
+The v2.5.1 version provides a `add_rules("plugin.vsxmake.autoupdate")` rule. If this rule is applied, the production vs project will be checked for changes in xmake.lua and the code file list after the compilation is completed. If there are changes , The vs project will be updated automatically.
+
+```lua
+add_rules("plugin.vsxmake.autoupdate")
+target("test")
+     set_kind("binary")
+     add_files("src/*.c")
+```
+
 #### Using vs built-in compilation mechanism
 
 !> It is recommended to use the new version of the vs. plugin provided after v2.2.8 mentioned above. The support is more complete. The generation method here does not support the rules of xmake, and the generation of projects such as qt.

+ 4 - 0
zh-cn/manual/builtin_modules.md

@@ -937,6 +937,10 @@ os.execv("echo", {"hello", "xmake!"}, {stdout = outfile, stderr = errfile, envs
 
 其中,stdout和stderr参数用于传递重定向输出和错误输出,可以直接传入文件路径,也可以传入io.open打开的文件对象。
 
+v2.5.1 之后的版本,我们还支持设置 stdin 参数,来支持重定向输入文件。
+
+!> stdout/stderr/stdin 可以同时支持:文件路径、文件对象、管道对象等三种类型值。
+
 另外,如果想在这次执行中临时设置和改写一些环境变量,可以传递envs参数,里面的环境变量设置会替换已有的设置,但是不影响外层的执行环境,只影响当前命令。
 
 我们也可以通过`os.getenvs()`接口获取当前所有的环境变量,然后改写部分后传入envs参数。

+ 39 - 0
zh-cn/manual/project_target.md

@@ -126,6 +126,7 @@ target("test2")
 | [set_policy](#targetset_policy)                 | 设置构建行为策略                     | >= 2.3.4 |
 | [set_plat](#targetset_plat)                     | 设置指定目标的编译平台               | >= 2.3.5 |
 | [set_arch](#targetset_arch)                     | 设置指定目标的编译架构               | >= 2.3.5 |
+| [set_runtimes](#targetset_runtimes)             | 设置编译目标依赖的运行时库           | >= 2.5.1 |
 
 ### target
 
@@ -2559,3 +2560,41 @@ set_policy("check.auto_map_flags", false)
 ```bash
 set_policy("build.across_targets_in_parallel", false)
 ```
+
+### target:set_runtimes
+
+#### 设置编译目标依赖的运行时库
+
+这是 v2.5.1 开始新增的接口,用于抽象化设置编译目标依赖的运行时库,目前仅仅支持对 msvc 运行时库的抽象,但后续也许会扩展对其他编译器运行时库的映射。
+
+目前支持的一些配置值说明如下:
+
+
+| 值     | 描述                                      |
+| ------ | ----------------------------------------- |
+| MT     | msvc 运行时库:多线程静态库               |
+| MTd    | msvc 运行时库:多线程静态库(调试)       |
+| MD     | msvc 运行时库:多线程动态库               |
+| MDd    | msvc 运行时库:多线程动态库(调试)       |
+
+关于 vs 运行时,可以参考:[msvc 运行时说明](https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-160)
+
+而这个接口传入 MT/MTd 参数配置,xmake 会自动配置上 `/MT /nodefaultlib:msvcrt.lib` 参数。
+
+我们可以针对不同的 target 设置不同的运行时。
+
+另外,如果我们将 `set_runtimes` 设置在全局根域,那么所有的 `add_requires("xx")` 包定义也会全局同步切换到对应的 vs runtime 配置
+
+```lua
+set_runtimes("MD")
+add_requires("libcurl", "fmt")
+target("test")
+   set_kind("binary")
+   add_files("src/*.c")
+```
+
+当然,我们也可以通过 `add_requires("xx", {configs = {vs_runtime = "MD"}})` 对特定包修改 vs 运行时库。
+
+我们也可以通过 `xmake f --vs_runtime=MD` 通过参数配置来全局切换它。
+
+与此 api 相关的 issue:[#1071](https://github.com/xmake-io/xmake/issues/1071#issuecomment-750817681)

+ 10 - 1
zh-cn/plugin/builtin_plugins.md

@@ -89,7 +89,7 @@ $ xmake project -k [vsxmake2010|vsxmake2013|vsxmake2015|..] -m "debug;release"
 如果没指明版本,那么xmake会自动探测当前已有的vs版本来生成:
 
 ```bash
-$ xmake project -k vsxmake -m "debug;release"
+$ xmake project -k vsxmake -m "debug,release"
 ```
 
 ![](/assets/img/manual/qt_vs.png)
@@ -98,6 +98,15 @@ $ xmake project -k vsxmake -m "debug;release"
 
 ![](/assets/img/manual/property_page_vsxmake.png)
 
+v2.5.1 版本提供了一个 `add_rules("plugin.vsxmake.autoupdate")` 规则,如果应用此规则,生产的vs工程在编译完成后,会检测 xmake.lua 和代码文件列表的改动,如果有变化,就会自动更新 vs 工程。
+
+```lua
+add_rules("plugin.vsxmake.autoupdate")
+target("test")
+    set_kind("binary")
+    add_files("src/*.c")
+```
+
 #### 使用vs内置编译机制
 
 !> 建议尽量使用上文提到的v2.2.8之后提供的新版的vs生成插件,支持更加完善,此处的生成方式不支持xmake的rules,以及对qt等工程的生成。