1# Taihe: 多语言系统接口编程模型 2 3## Taihe 是什么 4 5Taihe 提供了简单易用的 API 发布和消费机制。 6 7对于 API 发布方,Taihe 可以轻松地描述要发布的接口。 8```ts 9// idl/integer.arithmetic.taihe 10function divmod_i32(a: i32, b: i32): (i32, i32); 11``` 12 13对于 API 的发布和消费方,Taihe 生成各语言的绑定,提供原生的开发体验。 14```c++ 15// 发布 API 为 libinteger.so,源码位于 author/integer.arithmetic.impl.cpp 16#include "integer.arithmetic.impl.hpp" 17 18std::tuple<int32_t, int32_t> ohos_int_divmod(int32_t a, int32_t b) { 19 return { a / b, a % b }; 20} 21 22TH_EXPORT_CPP_API_divmod_i32(ohos_int_divmod) 23``` 24 25Taihe 将 API 的发布方和消费方在二进制级别隔离,允许二者在闭源的情况下独立升级。 26```c++ 27// 使用 libinteger.so 编写用户应用 28#include "integer.arithmetic.abi.hpp" 29#include <cstdio> 30 31using namespace integer; 32 33int main() { 34 auto [quo, rem] = arithmetic::divmod_i32(a, b); 35 printf("q=%d r=%d\n", quo, rem); 36 return 0; 37} 38``` 39 40## 加入 Taihe 的开发 41 42Ubuntu 环境(>= 22.04):运行 `./scripts/install-ubuntu-deps` 来一键安装环境 43 44运行 `python -m taihe.cli.tryit test -u sts /test/ani_array` 运行测试样例,检测环境是否可用 45 46开发和使用:参见 [文档索引](./docs/README.md) 47