Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于反射生成代码的一点建议 #426

Open
hebohang opened this issue Jan 29, 2023 · 2 comments
Open

关于反射生成代码的一点建议 #426

hebohang opened this issue Jan 29, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@hebohang
Copy link
Contributor

目前是使用一个 custom target 完成的,并且添加了 runtime 对此的依赖:

add_custom_target(${PRECOMPILE_TARGET} ALL

这样做会导致在写引擎的时候无论是用cmake项目还是生成出ide来使用,都会在编译时运行一遍 parser 生成出所需代码(_generated),并且runtime中依赖codegen出来的那些文件都会由于_generated被重新生成而重新编译。

如果不考虑像ue那样给客户使用也添加反射功能,可以把 codegen 单独写成一个批处理命令,例如在cmake中使用 execute_process 替代 add_custom_target,这样就把 parser 从编译时给提前到了 cmake 构建时运行,可以有效缩短编译时间。

@hebohang hebohang added the enhancement New feature or request label Jan 29, 2023
@liangzai12 liangzai12 reopened this Jan 30, 2023
@liangzai12
Copy link
Contributor

需要解析的代码可能会频繁修改,因此也需要重新解析生成代码。
不过你的提出的问题确实存在,或许可以尝试添加一种检测待解析的文件是否更改的逻辑。由于目前的代码生成依赖于全局的代码信息,所以还需要改成增量代码生成的逻辑。
目前codegen时间消耗点在于使用libclang解析源码的步骤,更具体的是头文件展开后代码的分析,减少工程中.h文件中对标准库和第三方库的include可以显著降低代码解析时间。

@hebohang
Copy link
Contributor Author

了解了,关于“检测待解析的文件是否更改”cmake是可以做到的,不过我还没有尝试过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants