2311skia,本地惊心动魄的编译skia的x86版本

首先,感谢steampp,这样可以随时访问github.不然,根本干不了活.

第一步,学习并下载skia

正确编译skia,有人家的辛苦工作
借用github action编译skia方法
本地编译的1个教程
对我来说,这一步是完成不了的:

cd skia
python2 tools/git-sync-deps
//或者加上.exe变成
python2.exe tools/git-sync-deps

主要是py2的代码太难改.
这里是用py2下载依赖的方式
github的action编译

xmake的skia
能够访问github,就可借用xmake帮助编译skia.但我没试过.

窗口编译skia
谷哥的depot_tools位置
可借用gitee下载depot_tools/skia,
谷哥的skia位置

python2 tools/git-sync-deps

这一步自动下载skia依赖的三方库,会自动下载到skia/third_party/externals目录;以及用于生成项目文件的工具gn.exe.注意:externals存放依赖位置.而third_party下面一堆目录是相应的Build.gn存放位置.

简单介绍gn

gn.exe既要放在路径中,也要放在H:\cpp\skia\bin\目录中,还有编译的时候,不能仅用gn,而是要输入gn.exe全名.
depot_toolsskia的镜像,可用gitee帮助.

第二步,下载skia的依赖

skia依赖的第三方库,是最麻烦的.只有下载正确的依赖库,才能大大减轻编译skia的麻烦.因为不能正确使用python2.exe,所以不能像别人直接调用py2就可下载正确的依赖包.
skia/DEPS,最新的依赖包,有许多新依赖.
而文章中的依赖,有部分过时了.
即,先用前面文章中的DEPS复制替换到你的DEPS中,但要记得备份原DEPS.
这是原待下载路径:

https://github.com/GoogleDepends/EGL-Registry
https://github.com/GoogleDepends/OpenCL-Registry
https://github.com/GoogleDepends/OpenGL-Registry
https://github.com/GoogleDepends/SPIRV-Cross
https://github.com/GoogleDepends/SPIRV-Headers
https://github.com/GoogleDepends/SPIRV-Tools
https://github.com/GoogleDepends/angle2
https://github.com/GoogleDepends/buildtools
https://github.com/GoogleDepends/common
https://github.com/GoogleDepends/common-lib-amd-APPSDK-3.0
https://github.com/GoogleDepends/dawn
https://github.com/GoogleDepends/dng_sdk
https://github.com/GoogleDepends/expat
https://github.com/GoogleDepends/freetype2
https://github.com/GoogleDepends/glslang
https://github.com/GoogleDepends/harfbuzz
https://github.com/GoogleDepends/icu
https://github.com/GoogleDepends/imgui
https://github.com/GoogleDepends/jinja2
https://github.com/GoogleDepends/libgifcodec
https://github.com/GoogleDepends/libjpeg-turbo
https://github.com/GoogleDepends/libmicrohttpd
https://github.com/GoogleDepends/libpng
https://github.com/GoogleDepends/libwebp
https://github.com/GoogleDepends/lua
https://github.com/GoogleDepends/markupsafe
https://github.com/GoogleDepends/piex
https://github.com/GoogleDepends/sdl
https://github.com/GoogleDepends/sfntly
https://github.com/GoogleDepends/shaderc
https://github.com/GoogleDepends/swiftshader
https://github.com/GoogleDepends/wuffs
https://github.com/GoogleDepends/zlib

这里面,有几个需要是最新的,因为它的路径里面是旧版(2020年).

gn.exe,是从官网下载的win32版.前面说了,要放在两个地方,不然后面编译会出问题,而且输入命令时,要用gn.exe,而不光是gn(要出错).人家提醒要放进skia\bin了,但我没看见,后来才试错加进去.

第三步,写配置

下载完依赖后有三步动作:
1,改gn配置,然后用gn.exe gen out\Static生成ninja文件.
2,修改skia\out\Static\toolchain.ninja文件.
3,执行ninja -C out/Static编译命令,
因为toolchain.ninja有点小问题,每次更改配置后,都是这三步.

改配置,生成ninja文件

最新的DEPS有点大,我编译时,是用前面文章的替换了,还没下载有些最新依赖.
我是生成x86版的静态库.其他的可以类似.

gn.exe gen out/Static
//这样,在out/Static目录里面输出ninja文件.

这里ninja用的是,depot_tools里面的ninja.exe.

进入out/Static目录,在args.gn文件里面写入:

clang_win = "G:\LLVM"
//最新的LLVM为17版本,下载到此地
target_cpu = "x86"
//x86目标.
extra_cflags=["/MT"]
//静态库
win_vc = "C:\vs2022\VC"
//这是vs2022安装目录

然后是修改gn\BUILDCONFIG.gn文件,最上面空的,改为类似:

  cc = "clang"
  cxx = "clang++"
//cc与cxx工具.
  win_sdk = "C:\WindowsKits\10"
//一般正常中间有个空格为Windows Kits.
//这里临时去掉空格,等编译完再加上空格
  win_sdk_version = "10.0.22621.0"
//sdk版本
  win_vc = "C:\vs2022\VC"
//VC目录
  win_toolchain_version = "14.37.32822"
//VC版本,根据自身填写.

  clang_win = "G:\LLVM"
//用LLVM编译,skia更小,编译更快
  clang_win_version = "17"
//最新的为17版本,15版本,就要重新下载,

然后,就可执行如下命令了:

gn.exe gen out\Static

添加--ide="vs2017"--ide=vs,会生成sln,但我用sln编译不了,别人也不推荐这种方法.

改工具链生成文件.

主要是两个动作:
1,删掉类似下面这样的6句:

cmd /c C:/WindowsKits/10/bin/SetEnv.cmd /x86 &&

2,把微软的python3改为python.exe,因为python3下面并不存在什么东西,即不管用.要用python.exe,才能真正执行命令,当然python.exe要在路径上.

执行真正的编译

ninja -C out/static

然后,就开始编译了.

手动修改编译过程中问题

前面说了,上面的有些库过时了,不能用它,这些库有:harfbuzz/libexpat/libwebp/wuffs/libmicrohttpd/imgui/libjpeg-turbo,从各自的官网重新下载这些库进externals目录
各自官网如下:

https://github.com/libjpeg-turbo/libjpeg-turbo
//https://github.com/amusi/libjpeg-turbo-examples
//示例.libjpeg-turbo主要是比libjpeg快一些.
https://github.com/harfbuzz/harfbuzz
https://github.com/Karlson2k/libmicrohttpd
https://github.com/ocornut/imgui
https://github.com/webmproject/libwebp
https://github.com/libexpat/libexpat
https://github.com/google/wuffs

把上面的库下载到externals目录里面,最新的依赖更多,不过我不知道了,你也许可以试试单独官网下载,再编译.

turbo版的示例
编译时,出现:

build stopped: subcommand failed.

ninja是按一系列命令来构建,出现这个,代表该命令有问题,你要解决它.
简单介绍ninja,ninja官网

解决编译问题

1,没有gsubgpos-context.cc文件,从这里下载.

2,找不到jpeg_nbits_table.c,网上搜索,内容与jpeg_nbits_table.h差不多,其实只需要如下就行了.

#include "jpeg_nbits_table.h"

3,出现bin/SetEnv.cmd问题,就是前面没有删除toolchain的问题,因为根本就不应该有个SetEnv.cmd文件,有也算过时了.

4,这里前面的几个错误,及修改可能搞忘记了.开始未用笔记记着,所以,如果你遇见了,要靠自己解决了,应该能够搞定了,不是很难.

5,find_headers.py问题:

//find_headers.py
  print(gn_desc_cmd)//得知,要用`gn.exe`
  desc_json_txt = subprocess.check_output(gn_desc_cmd).decode('utf-8')

如下修改:

gn\toolchain\BUILD.gn,45行附近
dlsymutil_pool_depth = 8
//设置为8,

6,icudtl.dat复制问题,还是py的问题

icudtl.dat,cp.py==>

这是toolchain.ninja问题,把python3改成python.exe.

7,xmlparse.c问题,在前面加上一句:
xmlparse.c前面加上:

#include "expat_config.h"
#define XML_GE 1
//上面这一句.

8,py2版本问题,py3运行py2:
make_data_assembly.py,79行要改为:

split = [str(binascii.hexlify(input_data[i:i + 4][::step]),'ascii').upper().lstrip('0') for i in range(0, len(input_data), 4)]

9,imguilayer.h,imgui的兼容问题

    float availWidth = std::max(ImGui::GetContentRegionAvail().x, 1.0f);

把,Width改为如上的Avail().x.

10,Viewer.cpp,2589行:

if (fShowSlidePicker) {
    ImGui::SetNextTreeNodeOpen(true);//改为下面.
    ImGui::SetNextItemOpen(true);
}

同样是兼容问题.

11,compression_utils_portable.cc错误导入路径问题

#include "third_party/zlib/google/compression_utils_portable.h"
#include "compression_utils_portable.h"
|| ../../third_party/externals/zlib/google/compression_utils_portable.h(15,10): fatal error: 'third_party/zlib/zlib.h' file not found
#include "third_party/zlib/zlib.h",改为
#include "../zlib.h"
//把导入都改为类似,"../zlib.h"

12,不能生成:skia.h.这是最早的工具链问题,
toolchain.ninja里面.
user\...\python3改成python.exe.就是py的路径问题.

13,GetColorPalette找不着,libwebp中的build.gn中加上下面这句,主要可能是搞忘记了.

  "../externals/libwebp/src/utils/palette.c",
//加上上面这一行.
  "../externals/libwebp/src/utils/utils.c",
//这是最后一行

然后,再来一次流程:

gn.exe gen out/Static
改工具链的错误.
ninja -C out/static

14,再试试:
libwebp.ninjautil.c上方加上:

build obj/third_party/externals/libwebp/src/utils/libwebp.palette.obj: cc ../../third_party/externals/libwebp/src/utils/palette.c
  source_file_part = palette.c
  source_name_part = palette

15,LLVM,要下载最新的17版本.
16,libjpeg-turbo,jconfig.h,直接从jconfig.vc复制.

看看,编译skia,真是惊心动魄啊!

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