国内正确编译V8和Skia

V8是著名的JS引擎,Skia是著名的C++图形库,二者皆为google的开源项目,国内很难编译。啥用我就不介绍了,百度因有尽有。开学&高中课程紧,我可能没时间发博客了。

先是V8

首先,git是必须的。我们需要clone需要的全部代码(从NodeJS里面)

命令:PS:gitee是国内的,速度快

git clone https://gitee.com/mirrors/nodejs.git

为啥是nodejs呢?node是基于v8的项目,包含了v8的全部依赖和最新的v8源码。

然后得有python2.7和>=vs2017。

又是命令

cd nodejs
./vcbuild.bat Release x86 openssl-no-asm

注意:等到开始编译,立刻停止。这样,v8的工程生成好了,也没有编译任何node的代码(主要是我配置不够编译node,内存才4G)。

然后去tools\v8_gypfiles看看,是不是有vs的工程了?你可以从ide编译纯真的v8。

我是命令行编译的(开始菜单里面的vs2017命令行工具)

cd tools\v8_gypfiles
msbuild

至此,v8编译结束喽

Skia稍微有点复杂

git clone https://gitee.com/gitnow/skia.git

这个是我建立的gitee镜像。

然后需要改个文件

工程目录里的 DEPS 。改成我建立的镜像地址

我建立的镜像(和朋友干了半小时才搞定)

https://github.com/GoogleDepends/

我的DEPS内容

use_relative_paths = True

vars = {
  "checkout_chromium": False,
}

deps = {
  "buildtools"                            : "https://github.com/GoogleDepends/buildtools.git@505de88083136eefd056e5ee4ca0f01fe9b33de8",
  "common"                                : "https://github.com/GoogleDepends/common.git@9737551d7a52c3db3262db5856e6bcd62c462b92",
  "third_party/externals/angle2"          : "https://github.com/GoogleDepends/angle2.git@1cc49bb2e230555fb3dc33d3400a5f7a0cefe943",
  # Dawn requires jinja2 and markupsafe for the code generator, and glslang and shaderc for SPIRV compilation.
  # When the Dawn revision is updated these should be updated from the Dawn DEPS as well.
  "third_party/externals/dawn"            : "https://github.com/GoogleDepends/dawn.git@11652ff8f8b3c3104eb2627717fa652d432d5b84",
  "third_party/externals/glslang"         : "https://github.com/GoogleDepends/glslang@1f0fcbe5a30fdc9632a8bff36277103fabf0797c",
  "third_party/externals/jinja2"          : "https://github.com/GoogleDepends/jinja2@b41863e42637544c2941b574c7877d3e1f663e25",
  "third_party/externals/markupsafe"      : "https://github.com/GoogleDepends/markupsafe@8f45f5cfa0009d2a70589bcda0349b8cb2b72783",
  "third_party/externals/shaderc"         : "https://github.com/GoogleDepends/shaderc@362becca1ff2a841c21fd675ac3a9c1ee9bb5612",
  "third_party/externals/dng_sdk"         : "https://github.com/GoogleDepends/dng_sdk.git@c8d0c9b1d16bfda56f15165d39e0ffa360a11123",
  "third_party/externals/egl-registry"    : "https://github.com/GoogleDepends/EGL-Registry@a0bca08de07c7d7651047bedc0b653cfaaa4f2ae",
  "third_party/externals/expat"           : "https://github.com/GoogleDepends/expat.git@e5aa0a2cb0a5f759ef31c0819dc67d9b14246a4a",
  "third_party/externals/freetype"        : "https://github.com/GoogleDepends/freetype2.git@0a3d2bb99b45b72e1d45185ab054efa993d97210",
  "third_party/externals/harfbuzz"        : "https://github.com/GoogleDepends/harfbuzz.git@3a74ee528255cc027d84b204a87b5c25e47bff79",
  "third_party/externals/icu"             : "https://github.com/GoogleDepends/icu.git@dbd3825b31041d782c5b504c59dcfb5ac7dda08c",
  "third_party/externals/imgui"           : "https://github.com/GoogleDepends/imgui.git@d38d7c6628bebd02692cfdd6fa76b4d992a35b75",
  "third_party/externals/libgifcodec"     : "https://github.com/GoogleDepends/libgifcodec@d06d2a6d42baf6c0c91cacc28df2542a911d05fe",
  "third_party/externals/libjpeg-turbo"   : "https://github.com/GoogleDepends/libjpeg-turbo.git@574f3a772c96dc9db2c98ef24706feb3f6dbda9a",
  "third_party/externals/libpng"          : "https://github.com/GoogleDepends/libpng.git@386707c6d19b974ca2e3db7f5c61873813c6fe44",
  "third_party/externals/libwebp"         : "https://github.com/GoogleDepends/libwebp.git@0fe1a89dbf1930fc2554dbe76adad5d962054ead",
  "third_party/externals/lua"             : "https://github.com/GoogleDepends/lua.git@e354c6355e7f48e087678ec49e340ca0696725b1",
  "third_party/externals/microhttpd"      : "https://github.com/GoogleDepends/libmicrohttpd@748945ec6f1c67b7efc934ab0808e1d32f2fb98d",
  "third_party/externals/opencl-lib"      : "https://github.com/GoogleDepends/common-lib-amd-APPSDK-3.0@4e6d30e406d2e5a65e1d65e404fe6df5f772a32b",
  "third_party/externals/opencl-registry" : "https://github.com/GoogleDepends/OpenCL-Registry@932ed55c85f887041291cef8019e54280c033c35",
  "third_party/externals/opengl-registry" : "https://github.com/GoogleDepends/OpenGL-Registry@14b80ebeab022b2c78f84a573f01028c96075553",
  "third_party/externals/piex"            : "https://github.com/GoogleDepends/piex.git@bb217acdca1cc0c16b704669dd6f91a1b509c406",
  "third_party/externals/sdl"             : "https://github.com/GoogleDepends/sdl@5d7cfcca344034aff9327f77fc181ae3754e7a90",
  "third_party/externals/sfntly"          : "https://github.com/GoogleDepends/sfntly.git@b55ff303ea2f9e26702b514cf6a3196a2e3e2974",
  "third_party/externals/spirv-cross"     : "https://github.com/GoogleDepends/SPIRV-Cross@871c85d7f0edc6b613e3959bc51d13bfbc2fe2df",
  "third_party/externals/spirv-headers"   : "https://github.com/GoogleDepends/SPIRV-Headers.git@f8bf11a0253a32375c32cad92c841237b96696c0",
  "third_party/externals/spirv-tools"     : "https://github.com/GoogleDepends/SPIRV-Tools.git@1c8bda3721e6b9302f694b58c26d32eff341b126",
  "third_party/externals/swiftshader"     : "https://github.com/GoogleDepends/swiftshader@f99302c4efe6f32297a619d407b4410ec3ee6412",
  #"third_party/externals/v8"              : "https://chromium.googlesource.com/v8/v8.git@5f1ae66d5634e43563b2d25ea652dfb94c31a3b4",
  "third_party/externals/wuffs"           : "https://github.com/GoogleDepends/wuffs.git@4080840928c0b05a80cda0d14ac2e2615f679f1a",
  "third_party/externals/zlib"            : "https://github.com/GoogleDepends/zlib@47af7c547f8551bd25424e56354a2ae1e9062859",

  "../src": {
    "url": "https://chromium.googlesource.com/chromium/src.git@d086f1bdb67d4d54ba424d42d01eb256c9a3765f",
    "condition": "checkout_chromium",
  },
}

recursedeps = [
  "common",
  "../src",
]

gclient_gn_args_from = 'src'

然后得安装Python2.7。

然后命令 PS:需要能命令行里面执行git和Python命令

cd skia
python tools\git-sync-deps

可以看到依赖完美安装成功了。

然后是头疼的gn问题。我在github上下了个gn和ninja源码,编译了个32位的(为了兼容性),东西在csdn下载里面,暂时没审核结束呢。

之后解压到bin里面,依旧是命令

bin\gn gen out\Release
bin\gn args out\Release
# 然后设置你的参数,保存
bin\gn gen out\Release
bin\ninja -C out\Release
# 搞定。

有个啥official_build参数一定不能打开,否则编译必然失败。

如果找不到vs啥的,或者命令出错的,修改下out\Release\toolchain.ninja

cc 等的command,改成你的vc安装地。

比如我的toolchain.ninja

rule copy
  command = python "E:/SDK/skia/gn/cp.py" ${in} ${out}
  description = copy ${in} ${out}
rule cc
  command =   "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/cl.exe" /nologo  /FC ${defines} ${include_dirs} ${cflags}  ${cflags_c} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_c.pdb"
  description = compile ${in}
  deps = msvc
rule cxx
  command =   "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/cl.exe" /nologo  /FC ${defines} ${include_dirs} ${cflags}  ${cflags_cc} /c ${in} /Fo${out} /Fd"${target_out_dir}/${label_name}_c.pdb"
  description = compile ${in}
  deps = msvc
rule asm
  command =  "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/ml.exe" ${asmflags} /nologo /c /Fo ${out} ${in}
  description = assemble ${in}
rule stamp
  command = cmd.exe /c echo > ${out}
  description = stamp ${out}
rule alink
  command =  "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/lib.exe" /nologo /ignore:4221 ${arflags} /OUT:${out} @${out}.rsp
  description = link ${out}
  rspfile = ${out}.rsp
  rspfile_content = ${in_newline}
rule link
  command =  "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/link.exe" /nologo /OUT:${root_out_dir}/${target_output_name}${output_extension} /PDB:${root_out_dir}/${target_output_name}${output_extension}.pdb @${root_out_dir}/${target_output_name}${output_extension}.rsp
  description = link ${out}
  rspfile = ${root_out_dir}/${target_output_name}${output_extension}.rsp
  rspfile_content = ${in_newline} ${libs} ${solibs} ${ldflags}
rule solink
  command =  "E:\Program Files (x86)\Microsoft Visual Studio 2017\Community\VC/Tools/MSVC/14.16.27023/bin/HostX86/x86/link.exe" /nologo /IMPLIB:${output_dir}/${target_output_name}${output_extension}.lib /DLL /OUT:${output_dir}/${target_output_name}${output_extension} /PDB:${output_dir}/${target_output_name}${output_extension}.pdb @${output_dir}/${target_output_name}${output_extension}.rsp
  description = link ${out}
  rspfile = ${output_dir}/${target_output_name}${output_extension}.rsp
  rspfile_content = ${in_newline} ${libs} ${solibs} ${ldflags}
  restat = 1

subninja obj/HelloWorld.ninja
=================下面省略^_^============================

保存后重新ninja就行啦!

你可能感兴趣的:(skia,c++,google)