《The Chrome Component Build》笔记

学习资料:《The Chrome Component Build》

学习进度

  • 2021.6.25下午,好多文档要看  :) ,周末该充电学习英语听力和口语了!!!Fighting!!!
  • 2021.6.25晚上,Ongoing
  • 2021.6.28下午,完成一半,了解static/dynamic library各自的优缺点。对symbol这个概念仍有一些疑问

Introduce

Release builds are static build which compile to one executable and zero-to-two shared libraries

This is efficient at runtime,but take a long time to link bedcasue so much code goes into a single binary

简单来说,Release 构建是静态构建,生成一个executable可执行文件,0~2个shared library,运行时是很高效的,但是link的时候会很浪费时间

问题:需要找书/资料看,学习C++编译的各个过程(各个阶段的产物是什么用的)

如果开启build_component,会生成更多small shared library,link速度加快,但是load速度会变慢  ,因为是运行时要加载,而不是一开始就加载

如果设置为false,components 将会link statically

共享库,静态库,动态库理解。一个库简单来说就是包含了一些已编译好的代码和数据,可以供其他程序使用(学习链接

  • 静态函数库,是指在程序运行之前,就加入到目标程序
    • 静态库,链接器从库中提取代码,并用于在编译/构建时产生最终可执行文件,executable运行不依赖该静态库(因为已经embeded)
    • 不用管动态库的版本,因为是一开始就嵌入到程序中了,所以可执行程序比较大
    • 副本多,每个使用该静态库的程序,都要copy一份,浪费空间
  • 动态函数库和共享库是一个东西。linux叫共享对象库.so,Windows叫动态加载函数库.dll
    • 编译器在运行代码的时候,编译器/链接器 会检查应用程序是否在共享库中,但不会从程序运行之前就加入到目标程序中
    • 在内存中只加载一个代码副本,所有可执行程序共用一份,相对可执行文件小一点+几个动态库(共享库)
    • 运行时加载,所以load会慢一点
  • 总结
    • 静态库,executable大,在程序运行就加载,load小,memory use 大
    • 动态库,executable小,在运行时加载,load大,memory use小

如何生成一个组件

定义一个组件,意味着使用GN的组件模板代替共享库,static library,模板会创建一个shared library

对象依赖

当一个组件间接/直接依赖于一个 Static library,静态库会被link到该组件上。如果同时有其他组件也是如此的依赖了该Static library,那么这个静态库会被复制一份新的

意思是指,当component template生成shared library时,如果静态库的代码被多个动态库引用,那就会产生多套静态代码

Component granularity(组件粒度)

不建议创建过多的组件,因为对象依赖有可能会生成太多重复static library,shared library过多,也会导致load time get worse。 当shared library过多,就违背了component build的初衷

Exporting and importing symbols

When a shared library or executable uses a symbol from a shared library, it is “imported” by the user of the symbol, and “exported” from the shared library that defines the symbol. Don’t confuse exported symbols with the public API of a component. For example, unit tests will often require implementation details to be exported. Export symbols to make the build link the way you need it, and use GN’s public headers and visibility restrictions to define your public API. 不清楚symbol的作用,export symbol的作用是什么?不懂public API和export symbol有什么关联和区别

Component library headers can use the COMPONENT_EXPORT() macro defined in base/component_export.h to annotate symbols which should be exported by the component. This macro takes a globally unique component name as an argument:

当一个共享库或者executable可执行文件使用了一个symbol from a shard library,由symbol的使用者导入,最后到处到shared library。不要混淆 export symbol和public API。举个例子,单元测试会要更详细到细节,export symbol可以自定义build link

后面的内容实践部分太多,不适合现在看,放着以后来看

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值