diff options
Diffstat (limited to 'xmake/modules/package/manager/vcpkg/install_package.lua')
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/install_package.lua | 147 |
1 files changed, 115 insertions, 32 deletions
diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index eaf28710e..9b7ded261 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -20,52 +20,67 @@ -- imports import("core.base.option") +import("core.base.json") +import("core.base.semver") import("lib.detect.find_tool") +import("package.manager.vcpkg.configurations") --- install package --- --- @param name the package name, e.g. pcre2, pcre2/libpcre2-8 --- @param opt the options, e.g. {verbose = true} --- --- @return true or false --- -function main(name, opt) - - -- attempt to find vcpkg - local vcpkg = find_tool("vcpkg") - if not vcpkg then - raise("vcpkg not found!") +-- need manifest mode? +function _need_manifest(opt) + local require_version = opt.require_version + if require_version ~= nil and require_version ~= "latest" then + return true end + local configs = opt.configs + if configs and (configs.features or configs.default_features == false or configs.baseline) then + return true + end +end + +-- install for classic mode +function _install_for_classic(vcpkg, name, opt) -- get arch, plat and mode local arch = opt.arch local plat = opt.plat local mode = opt.mode - - -- mapping plat if plat == "macosx" then plat = "osx" end + arch = configurations.arch(arch) - -- archs mapping for vcpkg - local archs = { - x86_64 = "x64", - i386 = "x86", + -- init triplet + local triplet = arch .. "-" .. plat + if opt.plat == "windows" and opt.shared ~= true then + triplet = triplet .. "-static" + if opt.vs_runtime and opt.vs_runtime:startswith("MD") then + triplet = triplet .. "-md" + end + end + + -- init argv + local argv = {"install", name .. ":" .. triplet} + if option.get("diagnosis") then + table.insert(argv, "--debug") + end + + -- install package + os.vrunv(vcpkg, argv) +end - -- android: armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64 - -- Offers a doc: https://github.com/microsoft/vcpkg/blob/master/docs/users/android.md - ["armeabi-v7a"] = "arm", - ["arm64-v8a"] = "arm64", +-- install for manifest mode +function _install_for_manifest(vcpkg, name, opt) - -- ios: arm64 armv7 armv7s i386 - armv7 = "arm", - armv7s = "arm", - arm64 = "arm64", - } - -- mapping arch - arch = archs[arch] or arch + -- get configs + local configs = opt.configs or {} -- init triplet + local arch = opt.arch + local plat = opt.plat + if plat == "macosx" then + plat = "osx" + end + arch = configurations.arch(arch) local triplet = arch .. "-" .. plat if opt.plat == "windows" and opt.shared ~= true then triplet = triplet .. "-static" @@ -75,11 +90,79 @@ function main(name, opt) end -- init argv - local argv = {"install", name .. ":" .. triplet} + local argv = {"--feature-flags=\"versions\"", "install", "--triplet", triplet} if option.get("diagnosis") then table.insert(argv, "--debug") end + -- generate platform + local platform = plat .. " & " .. arch + + -- generate dependencies + local require_version = opt.require_version + if require_version == "latest" then + require_version = nil + end + local minversion = require_version + if minversion and minversion:startswith(">=") then + minversion = minversion:sub(3) + end + local dependencies = {} + table.insert(dependencies, { + name = name, + ["version>="] = minversion, + platform = platform, + features = configs.features, + ["default-features"] = configs.default_features}) + + -- generate overrides to use fixed version + local overrides + if require_version and semver.is_valid(require_version) then + overrides = {{name = name, version = require_version}} + end + + -- generate manifest + local baseline = configs.baseline or "44d94c2edbd44f0c01d66c2ad95eb6982a9a61bc" -- 2021.04.30 + local manifest = { + name = "stub", + version = "1.0", + dependencies = dependencies, + ["builtin-baseline"] = baseline, + overrides = overrides} + local installdir = assert(opt.installdir, "installdir not found!") + json.savefile(path.join(installdir, "vcpkg.json"), manifest) + if not os.isdir(installdir) then + os.mkdir(installdir) + end + if option.get("diagnosis") then + vprint(path.join(installdir, "vcpkg.json")) + vprint(manifest) + end + -- install package - os.vrunv(vcpkg.program, argv) + os.vrunv(vcpkg, argv, {curdir = installdir}) +end + +-- install package +-- +-- @param name the package name, e.g. pcre2, pcre2/libpcre2-8 +-- @param opt the options, e.g. {verbose = true} +-- +-- @return true or false +-- +function main(name, opt) + + -- attempt to find vcpkg + local vcpkg = find_tool("vcpkg") + if not vcpkg then + raise("vcpkg not found!") + end + + -- do install + opt = opt or {} + if _need_manifest(opt) then + _install_for_manifest(vcpkg.program, name, opt) + else + _install_for_classic(vcpkg.program, name, opt) + end end |
