summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-20 23:09:16 +0800
committerruki <[email protected]>2021-12-20 23:09:16 +0800
commit6447e8ff1bdd11274049997f3f21b1430546e4f0 (patch)
tree874f5ae105ffb4ceb23891c87e340bb13be52842
parent4b139c33e84d6f2261bea3ec07ec889b44cebd96 (diff)
impl vcpkg manifest
-rw-r--r--tests/projects/package/vcpkg_manifest/xmake.lua6
-rw-r--r--xmake/modules/package/manager/vcpkg/configurations.lua48
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua22
-rw-r--r--xmake/modules/package/manager/vcpkg/install_package.lua106
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua1
5 files changed, 138 insertions, 45 deletions
diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua
index a10ec2347..d7150718c 100644
--- a/tests/projects/package/vcpkg_manifest/xmake.lua
+++ b/tests/projects/package/vcpkg_manifest/xmake.lua
@@ -1,8 +1,8 @@
-add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1")
---add_requires("vcpkg::boost", {alias = "boost", {configs = {}}})
+--add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1")
+add_requires("vcpkg::arrow", {configs = {features = {"json"}}})
target("test")
set_kind("binary")
add_files("src/*.cpp")
- add_packages("vcpkg::zlib", "vcpkg::fmt", "boost")
+ add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::arrow")
diff --git a/xmake/modules/package/manager/vcpkg/configurations.lua b/xmake/modules/package/manager/vcpkg/configurations.lua
new file mode 100644
index 000000000..9021edff0
--- /dev/null
+++ b/xmake/modules/package/manager/vcpkg/configurations.lua
@@ -0,0 +1,48 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file configurations.lua
+--
+
+-- get architecture for vcpkg
+function arch(arch)
+ local archs = {
+ x86_64 = "x64",
+ i386 = "x86",
+
+ -- 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",
+
+ -- ios: arm64 armv7 armv7s i386
+ armv7 = "arm",
+ armv7s = "arm",
+ arm64 = "arm64",
+ }
+ return archs[arch] or arch
+end
+
+-- get configurations
+function main()
+ return {
+ baseline = {description = "set the builtin baseline."},
+ features = {description = "set the features of dependency."},
+ default_features = {description = "enables or disables any defaults provided by the dependency.", default = true}
+ }
+end
+
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index 24500cc2a..e84833958 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -25,6 +25,7 @@ import("core.base.option")
import("core.project.config")
import("core.project.target")
import("detect.sdks.find_vcpkgdir")
+import("package.manager.vcpkg.configurations")
-- find package from the vcpkg package manager
--
@@ -50,29 +51,10 @@ function main(name, opt)
local arch = opt.arch
local plat = opt.plat
local mode = opt.mode
-
- -- mapping plat
if plat == "macosx" then
plat = "osx"
end
-
- -- archs mapping for vcpkg
- local archs = {
- x86_64 = "x64",
- i386 = "x86",
-
- -- 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",
-
- -- ios: arm64 armv7 armv7s i386
- armv7 = "arm",
- armv7s = "arm",
- arm64 = "arm64",
- }
- -- mapping arch
- arch = archs[arch] or arch
+ arch = configurations.arch(arch)
-- get the vcpkg installed directory
local installdir = path.join(vcpkgdir, "installed")
diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua
index 071eec03b..de707d0d1 100644
--- a/xmake/modules/package/manager/vcpkg/install_package.lua
+++ b/xmake/modules/package/manager/vcpkg/install_package.lua
@@ -20,11 +20,21 @@
-- imports
import("core.base.option")
+import("core.base.json")
+import("core.base.semver")
import("lib.detect.find_tool")
+import("package.manager.vcpkg.configurations")
-- need manifest mode?
function _need_manifest(opt)
--- print("_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 or configs.baseline) then
+ return true
+ end
end
-- install for classic mode
@@ -34,29 +44,10 @@ function _install_for_classic(vcpkg, name, opt)
local arch = opt.arch
local plat = opt.plat
local mode = opt.mode
-
- -- mapping plat
if plat == "macosx" then
plat = "osx"
end
-
- -- archs mapping for vcpkg
- local archs = {
- x86_64 = "x64",
- i386 = "x86",
-
- -- 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",
-
- -- ios: arm64 armv7 armv7s i386
- armv7 = "arm",
- armv7s = "arm",
- arm64 = "arm64",
- }
- -- mapping arch
- arch = archs[arch] or arch
+ arch = configurations.arch(arch)
-- init triplet
local triplet = arch .. "-" .. plat
@@ -77,6 +68,78 @@ function _install_for_classic(vcpkg, name, opt)
os.vrunv(vcpkg, argv)
end
+-- install for manifest mode
+function _install_for_manifest(vcpkg, name, opt)
+
+ -- get configs
+ local configs = opt.configs or {}
+
+ --[[
+ -- get arch, plat and mode
+
+ -- 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 = {"--feature-flags=\"versions\"", "install"}
+ if option.get("diagnosis") then
+ table.insert(argv, "--debug")
+ end
+
+ -- generate platform
+ local arch = opt.arch
+ local plat = opt.plat
+ if plat == "macosx" then
+ plat = "osx"
+ end
+ arch = configurations.arch(arch)
+ 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 tmpdir = os.tmpfile() .. ".dir"
+ json.savefile(path.join(tmpdir, "vcpkg.json"), manifest)
+
+ -- install package
+ os.vrunv(vcpkg, argv, {curdir = tmpdir})
+ os.tryrm(tmpdir)
+end
+
-- install package
--
-- @param name the package name, e.g. pcre2, pcre2/libpcre2-8
@@ -93,6 +156,7 @@ function main(name, opt)
end
-- do install
+ opt = opt or {}
if _need_manifest(opt) then
_install_for_manifest(vcpkg.program, name, opt)
else
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index c1d9b4791..f62a0fb52 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -285,7 +285,6 @@ function _install_packages(packages_install, packages_download, installdeps)
-- fetch a new package
local instance = nil
while instance == nil and #packages_pending > 0 do
- print("packages_pending", #packages_pending)
for idx, pkg in ipairs(packages_pending) do
-- all dependences has been installed? we install it now