首页 CEF系列6:编译沙盒库
文章
取消

CEF系列6:编译沙盒库

开启沙盒后,sub-process will be terminated before it can do any harm

需要你的程序链接 cef_sandbox 静态库.

如何编译才能支持沙盒

一般使用官方的automate_git.py脚本

sandbox-specific configuration comes from the GetConfigArgsSandbox function in the gn_args.py 

最后通过make_distrib.py 工具 combines multiple lib files into a single cef_sandbox.lib

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
cd chromium\src\cef
set GN_DEFINES=is_official_build=true
python3 tools\gn_args.py
执行这个会输出
Platform: windows

out/Debug_GN_x64:

alternate_cdm_storage_id_key="968b47690*****28e859454"
clang_use_chrome_plugins=false
dcheck_always_on=true
disable_fieldtrial_testing_config=true
enable_background_mode=false
enable_basic_printing=true
enable_cdm_host_verification=true
enable_cdm_storage_id=true
enable_downgrade_processing=false
enable_nacl=false
enable_print_preview=true
enable_resource_allowlist_generation=false
enable_rlz=true
enable_widevine=true
is_component_build=false
is_debug=false
is_official_build=true
optimize_webui=true
target_cpu="x64"
v8_enable_sandbox=false
...

然后
cd chromium\src
autoninja -C out\Debug_GN_x64_sandbox cef_sandbox
cd chromium\src\cef\tools
make_distrib.bat --allow-partial --sandbox --ninja-build --x64-build --no-archive --no-symbols --no-docs 

其中
--allow-partial:allow creation of partial distributions
--sandbox:include only the cef_sandbox static library
--no-archive:don\'t create archives for output directories应该是不压缩
--no-symbols:don\'t create symbol files,可能就是pdb文件
--no-docs:don\'t create documentation

在一个单独的_sandbox目录下,如 Debug_GN_x64_sandbox

最终打包生成只生成了一个文件:cef\binary_distrib\cef_binary_*_windows64_sandbox\Debug\cef_sandbox.lib

如 cef_binary_121.0.0-master.2886+ga097b62+chromium-121.0.6167.0_windows64_sandbox\Release\cef_sandbox.lib

但之前的编译不使用autoninja -C out\Debug_GN_x64_sandbox cef_sandbox也能编译出cef_sandbox.lib库,暂不清楚2个库的区别,可能上面的是开启了一些额外的选项。

参考

https://bitbucket.org/chromiumembedded/cef/wiki/SandboxSetup.md

本文由作者按照 CC BY 4.0 进行授权