Skip to content

Commit

Permalink
check bigendian
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Mar 21, 2024
1 parent 7974223 commit 7a3ca31
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 106 deletions.
15 changes: 15 additions & 0 deletions manual/helper_interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,18 @@ checking for STRING_SIZE ... 24
```

Alternatively, I can check for it in the script field with `target:check_sizeof`.

#### Detecting big-endian

After version 2.8.9, we added the ``check_bigendian`` interface to determine if the current compilation target is in bigendian mode.

```lua
includes("@builtin/check")

target("test")
set_kind("static")
add_files("*.cpp")
check_bigendian("IS_BIG_ENDIAN")
```

If the test passes and it is currently in big endian mode, then `IS_BIG_ENDIAN=1` is defined.
2 changes: 1 addition & 1 deletion mirror/manual/custom_rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ <h4 id="customloadscript">Custom load script</h4>
<p>The load script used to implement the custom rules will be executed when the target is loaded. You can customize some target configurations in it, for example:</p>
<pre><code class="lang-lua">rule("test")
on_load(function (target)
target:add("defines", "-DTEST")
target:add("defines", "TEST")
end)
</code></pre>
<h3 id="ruleon_config">rule:on_config</h3>
Expand Down
10 changes: 10 additions & 0 deletions mirror/manual/helper_interfaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,16 @@ <h4 id="detecttypesize">Detect type size</h4>
checking for STRING_SIZE ... 24
</code></pre>
<p>Alternatively, I can check for it in the script field with <code>target:check_sizeof</code>.</p>
<h4 id="detectingbigendian">Detecting big-endian</h4>
<p>After version 2.8.9, we added the <code>check_bigendian</code> interface to determine if the current compilation target is in bigendian mode.</p>
<pre><code class="lang-lua">includes("@builtin/check")

target("test")
set_kind("static")
add_files("*.cpp")
check_bigendian("IS_BIG_ENDIAN")
</code></pre>
<p>If the test passes and it is currently in big endian mode, then <code>IS_BIG_ENDIAN=1</code> is defined.</p>
</article>
</body>
</html>
1 change: 1 addition & 0 deletions mirror/manual/project_target.html
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,7 @@ <h4 id="enablingordisablingexceptions">Enabling or disabling exceptions</h4>
<h3 id="targetset_encodings">target:set_encodings</h3>
<h4 id="setencodings">Set encodings</h4>
<p>This is a new interface in version 2.8.2, we can use this interface to set the encoding of source and target files.</p>
<p>All supported encodings: utf-8, gb2312 (msvc)</p>
<p>By default, just specifying the encoding will work for both the source and target files.</p>
<pre><code class="lang-lua">-- for all source/target encodings
set_encodings("utf-8") -- msvc: /utf-8
Expand Down
2 changes: 1 addition & 1 deletion mirror/zh-cn/manual/custom_rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ <h4 id="">自定义加载脚本</h4>
<p>用于实现自定规则的加载脚本,当加载target的时候,会被执行,可在里面自定义设置一些target配置,例如:</p>
<pre><code class="lang-lua">rule("test")
on_load(function (target)
target:add("defines", "-DTEST")
target:add("defines", "TEST")
end)
</code></pre>
<h3 id="ruleon_link">rule:on_link</h3>
Expand Down
10 changes: 10 additions & 0 deletions mirror/zh-cn/manual/helper_interfaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ <h4 id="">检测类型大小</h4>
checking for STRING_SIZE ... 24
</code></pre>
<p>另外,我也可以通过 <code>target:check_sizeof</code> 在脚本域进行检测。</p>
<h4 id="">检测大小端</h4>
<p>在 2.8.9 版本之后,我们新增了 <code>check_bigendian</code> 接口,来判断当前编译目标是否为大端模式。</p>
<pre><code class="lang-lua">includes("@builtin/check")

target("test")
set_kind("static")
add_files("*.cpp")
check_bigendian("IS_BIG_ENDIAN")
</code></pre>
<p>如果检测通过,当前是大端模式,那么会定义 <code>IS_BIG_ENDIAN=1</code></p>
</article>
</body>
</html>
1 change: 1 addition & 0 deletions mirror/zh-cn/manual/project_target.html
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,7 @@ <h4 id="">启用或者禁用异常</h4>
<h3 id="targetset_encodings">target:set_encodings</h3>
<h4 id="">设置编码</h4>
<p>这是 2.8.2 版本新增的接口,我们可以用这个接口设置源文件、目标执行文件的编码。</p>
<p>目前支持的编码:utf-8, gb2312 (msvc)</p>
<p>默认情况下,我们仅仅指定编码,是会同时对源文件,目标文件生效。</p>
<pre><code class="lang-lua">-- for all source/target encodings
set_encodings("utf-8") -- msvc: /utf-8
Expand Down
Loading

0 comments on commit 7a3ca31

Please sign in to comment.