Parcourir la source

improve skia (#345)

* update skia

* remove print messages

* fix build on macosx

* improve xcode sysroot finding

* hotfix

* fix macos build again

* revert fix for linux

* try using oldenv

* fix skia

Co-authored-by: xq114 <[email protected]>
ruki il y a 4 ans
Parent
commit
07a6f5e8d4

+ 2 - 1
packages/f/fontconfig/xmake.lua

@@ -5,8 +5,9 @@ package("fontconfig")
 
     set_urls("https://www.freedesktop.org/software/fontconfig/release/fontconfig-$(version).tar.gz")
     add_versions("2.13.1", "9f0d852b39d75fc655f9f53850eb32555394f36104a044bb2b2fc9e66dbbfa7f")
+    add_versions("2.13.93", "0f302a18ee52dde0793fe38b266bf269dfe6e0c0ae140e30d72c6cca5dc08db5")
 
-    add_deps("pkg-config", "freetype >= 2.9", "expat")
+    add_deps("pkg-config", "freetype >=2.9", "expat")
     if is_plat("macosx") then
         add_deps("gettext")
     else

+ 1 - 1
packages/l/libpng/xmake.lua

@@ -23,7 +23,7 @@ package("libpng")
             add_requires("zlib")
             target("png")
                 set_kind("$(kind)")
-                add_files("*.c|example.c")
+                add_files("*.c|example.c|pngtest.c")
                 if is_arch("x86", "x64", "i386", "x86_64") then
                     add_files("intel/*.c")
                     add_defines("PNG_INTEL_SSE_OPT=1")

+ 3 - 1
packages/n/ninja/xmake.lua

@@ -35,7 +35,9 @@ package("ninja")
     end)
 
     on_install("@linux", function (package)
-        os.vrun("python configure.py --bootstrap")
+        import("lib.detect.find_tool")
+        local python = assert(find_tool("python"), "python not found!")
+        os.vrunv(python.program, {"configure.py", "--bootstrap"})
         os.cp("./ninja", package:installdir("bin"))
     end)
 

+ 121 - 56
packages/s/skia/xmake.lua

@@ -2,83 +2,148 @@ package("skia")
 
     set_homepage("https://skia.org/")
     set_description("A complete 2D graphic library for drawing Text, Geometries, and Images.")
+    set_license("BSD-3-Clause")
 
-    set_urls("https://skia.googlesource.com/skia.git",
-             "https://github.com/google/skia.git")
+    local commits = {["88"] = "158dc9d7d4cafb177b99b68c5dc502f8f4282092",
+                     ["89"] = "109bfc9052ce1bde7acf07321d605601d7b7ec24",
+                     ["90"] = "adbb69cd7fe4e1c321e1526420e30265655e809c"}
+    add_urls("https://github.com/google/skia/archive/$(version).zip", {version = function (version) return commits[tostring(version)] end})
+    add_versions("88", "3334fd7d0705e803fe2dd606a2a7d67cc428422a3e2ba512deff84a4bc5c48fa")
+    add_versions("89", "b4c8260ad7d1a60e0382422d76ea6174fc35ce781b01030068fcad08364dd334")
+    add_versions("90", "5201386a026d1dd55e662408acf9df6ff9d8c1df24ef6a5b3d51b006b516ac90")
 
-    add_versions("68046c", "68046cd7be837bd31bc8f0e821a2f82a02dda9cf")
+    add_deps("gn", "python", "ninja", {kind = "binary"})
 
-    add_deps("python2", "ninja", {kind = "binary"})
-
-    add_links("skia")
     add_includedirs("include")
-    add_includedirs("include/android")
-    add_includedirs("include/atlastext")
-    add_includedirs("include/c")
-    add_includedirs("include/codec")
-    add_includedirs("include/config")
-    add_includedirs("include/core")
-    add_includedirs("include/docs")
-    add_includedirs("include/effects")
-    add_includedirs("include/encode")
-    add_includedirs("include/gpu")
-    add_includedirs("include/pathops")
+    add_includedirs("include/..")
     add_includedirs("include/ports")
-    add_includedirs("include/private")
-    add_includedirs("include/svg")
-    add_includedirs("include/third_party")
-    add_includedirs("include/utils")
+    if is_plat("windows") then
+        add_syslinks("gdi32", "user32", "opengl32")
+    elseif is_plat("macosx") then
+        add_frameworks("CoreFoundation", "CoreGraphics", "CoreText", "CoreServices")
+    elseif is_plat("linux") then
+        add_deps("fontconfig", "freetype >=2.10")
+        add_syslinks("pthread", "GL", "dl", "rt")
+    end
+    add_links("skia")
+
+    local components = {"gpu", "pdf", "nvpr"}
+    for _, component in ipairs(components) do
+        add_configs(component, {description = "Enable " .. component .. " support.", default = true, type = "boolean"})
+    end
 
-    -- @note windows: only can build for vs2017 or vs2015 update 3
     on_install("macosx", "linux", "windows", function (package)
-        local pathes = os.getenv("PATH") or ""
-        pathes = pathes .. path.envsep() .. path.join(os.curdir(), "depot_tools")
-        pathes = pathes .. path.envsep() .. path.join(os.curdir(), "bin")
         local args = {is_official_build = false,
                       is_component_build = false,
                       is_debug = package:debug(),
-                      skia_enable_gpu = true,
-                      skia_enable_pdf = false,
-                      skia_enable_nvpr = false,
+                      is_shared_library = package:config("shared"),
                       skia_enable_tools = false,
                       skia_use_icu = false,
-                      skia_use_sfntly = false,
-                      skia_use_piex = false,
-                      skia_use_freetype = false,
-                      skia_use_harfbuzz = false,
-                      skia_use_libheif = false,
-                      skia_use_expat = false,
-                      skia_use_libjpeg_turbo = false,
-                      skia_use_libpng = false,
-                      skia_use_libwebp = false,
-                      skia_use_zlib = false}
-        args.cc  = package:build_getenv("cc")
-        args.cxx = package:build_getenv("cxx")
-        local argstr = ""
-        for k, v in pairs(args) do
-            if type(v) == "string" then
-                argstr = argstr .. ' ' .. k .. '=\"' .. v .. "\""
-            else
-                argstr = argstr .. ' ' .. k .. '=' .. tostring(v)
+                      skia_use_sfntly = true,
+                      skia_use_piex = true,
+                      skia_use_freetype = true,
+                      skia_use_system_freetype2 = package:is_plat("linux") and true or false,
+                      skia_use_harfbuzz = true,
+                      skia_use_libheif = true,
+                      skia_use_expat = true,
+                      skia_use_libjpeg_turbo_decode = true,
+                      skia_use_libjpeg_turbo_encode = true,
+                      skia_use_libpng_decode = true,
+                      skia_use_libpng_encode = true,
+                      skia_use_libwebp_decode = true,
+                      skia_use_libwebp_encode = true,
+                      skia_use_zlib = true}
+        for _, component in ipairs(components) do
+            args["skia_enable_" .. component] = package:config(component)
+        end
+        if package:is_arch("x86") then
+            args.target_cpu    = "x86"
+        elseif package:is_arch("x64") then
+            args.target_cpu    = "x64"
+        elseif package:is_arch("arm64") then
+            args.target_cpu    = "arm64"
+        end
+        if not package:is_plat("windows") then
+            args.cc            = package:build_getenv("cc")
+            args.cxx           = package:build_getenv("cxx")
+        else
+            args.extra_cflags  = {(package:config("vs_runtime"):startswith("MT") and "/MT" or "/MD")}
+        end
+        if package:is_plat("macosx") then
+            args.extra_ldflags = {"-lstdc++"}
+            local xcode = import("core.tool.toolchain").load("xcode", {plat = package:plat(), arch = package:arch()})
+            args.xcode_sysroot = xcode:config("xcode_sysroot")
+        end
+
+        -- fix symbol lookup error: /lib64/libk5crypto.so.3: undefined symbol: EVP_KDF_ctrl, version OPENSSL_1_1_1b
+        local LD_LIBRARY_PATH
+        if package:is_plat("linux") and linuxos.name() == "fedora" then
+            LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH")
+            if LD_LIBRARY_PATH then
+                local libdir = os.arch() == "x86_64" and "/usr/lib64" or "/usr/lib"
+                LD_LIBRARY_PATH = libdir .. ":" .. LD_LIBRARY_PATH
+            end
+        end
+
+        -- patches
+        io.replace("bin/fetch-gn", "import os\n", "import os\nimport ssl\nssl._create_default_https_context = ssl._create_unverified_context\n", {plain = true})
+        os.vrunv("python", {"tools/git-sync-deps"}, {envs = {LD_LIBRARY_PATH = LD_LIBRARY_PATH}})
+        io.replace("gn/BUILD.gn", "libs += [ \"pthread\" ]", "libs += [ \"pthread\", \"m\", \"stdc++\" ]", {plain = true})
+        io.replace("gn/toolchain/BUILD.gn", "$shell $win_sdk/bin/SetEnv.cmd /x86 && ", "", {plain = true})
+        io.replace("third_party/externals/dng_sdk/source/dng_pthread.cpp", "auto_ptr", "unique_ptr", {plain = true})
+        io.replace("BUILD.gn", 'executable%("skia_c_api_example"%) {.-}', "")
+
+        -- set deps flags
+        local cflags = {}
+        local ldflags = {}
+        if package:is_plat("linux") then
+            for _, depname in ipairs({"fontconfig", "freetype"}) do
+                local fetchinfo = package:dep(depname):fetch()
+                if fetchinfo then
+                    for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
+                        table.insert(cflags, "-I" .. includedir)
+                    end
+                    for _, linkdir in ipairs(fetchinfo.linkdirs) do
+                        table.insert(ldflags, "-L" .. linkdir)
+                    end
+                    for _, link in ipairs(fetchinfo.links) do
+                        table.insert(ldflags, "-l" .. link)
+                    end
+                end
             end
         end
-        os.vrun("python2 tools/git-sync-deps")
-        os.vrun("bin/gn gen build --args='%s'", argstr:trim())
-        os.vrun("ninja -C build")
-        os.cp("include", package:installdir())
-        os.cp("third_party/skcms/*.h", package:installdir("third_party/skcms"))
-        if is_plat("windows") then
-            os.cp("build/*.lib", package:installdir("lib"))
+        if #cflags > 0 then
+            io.replace("gn/BUILD.gn", "cflags = []", 'cflags = ["' .. table.concat(cflags, '", "') .. '"]', {plain = true})
+        end
+        if #ldflags > 0 then
+            io.replace("gn/BUILD.gn", "ldflags = []", 'ldflags = ["' .. table.concat(ldflags, '", "') .. '"]', {plain = true})
+        end
+
+        -- installation
+        import("package.tools.gn").build(package, args, {buildir = "out"})
+        os.mv("include", package:installdir())
+        os.cd("out")
+        os.rm("obj")
+        os.rm("*.ninja")
+        os.rm("*.ninja*")
+        os.rm("*.gn")
+        if package:is_plat("windows") then
+            os.mv("*.lib", package:installdir("lib"))
+            os.trymv("*.dll", package:installdir("bin"))
+            os.mv("*.exe", package:installdir("bin"))
         else
-            os.cp("build/*.a", package:installdir("lib"))
+            os.mv("*.a", package:installdir("lib"))
+            os.trymv("*.so", package:installdir("lib"))
+            os.trymv("*.dylib", package:installdir("lib"))
+            os.trymv("*", package:installdir("bin"))
         end
     end)
 
     on_test(function (package)
         assert(package:check_cxxsnippets({test = [[
-            static void test() {
+            void test() {
                 SkPaint paint;
                 paint.setStyle(SkPaint::kFill_Style);
             }
-        ]]}, {configs = {languages = "c++14"}, includes = "core/SkPaint.h", defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}))
+        ]]}, {configs = {languages = "c++14"}, includes = "core/SkPaint.h"}))
     end)