summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-10 00:37:49 +0800
committerruki <[email protected]>2026-01-10 00:37:49 +0800
commite5a5d09e47bdc7e33f805b23634b9f7115eb1f36 (patch)
treec3ac7d3a55df99fba1992eaf08e10a2fe1e1f079
parent4542ea8937bcaa68eb3d3bfad3dd7fa1616cac4b (diff)
rewrite precompile artifacts
-rw-r--r--tests/projects/package/schemes/port/xmake.lua2
-rw-r--r--xmake/core/package/package.lua123
-rw-r--r--xmake/core/package/scheme.lua16
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua3
-rw-r--r--xmake/modules/private/action/require/impl/package.lua2
-rw-r--r--xmake/modules/private/action/require/info.lua37
6 files changed, 93 insertions, 90 deletions
diff --git a/tests/projects/package/schemes/port/xmake.lua b/tests/projects/package/schemes/port/xmake.lua
index 92fb39f74..fe667a954 100644
--- a/tests/projects/package/schemes/port/xmake.lua
+++ b/tests/projects/package/schemes/port/xmake.lua
@@ -57,7 +57,7 @@ target("libninja")
target:add("files", "src/jobserver.cc")
target:add("files", "src/real_command_runner.cc")
target:add("files", "src/status_printer.cc")
- if target:is_plat("windows", "mingw", "msys2") then
+ if target:is_plat("windows", "mingw", "msys") then
target:add("files", "src/jobserver-win32.cc")
else
target:add("files", "src/jobserver-posix.cc")
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 9ca0a692f..a21bf81bf 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -363,63 +363,62 @@ function _instance:url_http_headers(url)
return self:current_scheme():url_http_headers(url)
end
--- set artifacts info
-function _instance:artifacts_set(artifacts_info)
- local versions = self:_versions_list()
- if versions then
- -- backup previous package configuration
- self._ARTIFACTS_BACKUP = {
- urls = table.copy(self:urls()),
- versions = table.copy(versions),
- install = self:script("install")} -- self:get() will get a table, it will be broken when call self:set()
+-- install the precompiled artifacts first
+function _instance:use_precompiled_artifacts(artifacts_info)
- -- we switch to urls of the precompiled artifacts
- self:urls_set(table.wrap(artifacts_info.urls))
- versions[self:version_str()] = artifacts_info.sha256
- self:set("install", function (package)
- sandbox_module.import("lib.detect.find_path")
- local rootdir = find_path("manifest.txt", path.join(os.curdir(), "*", "*", "*"))
- if not rootdir then
- os.raise("package(%s): manifest.txt not found when installing artifacts!", package:displayname())
- end
- os.cp(path.join(rootdir, "*"), package:installdir(), {symlink = true})
- local manifest = package:manifest_load()
- if not manifest then
- os.raise("package(%s): load manifest.txt failed when installing artifacts!", package:displayname())
- end
- if manifest.vars then
- for k, v in pairs(manifest.vars) do
- package:set(k, v)
- end
+ -- init the precompiled scheme
+ local precompiled_scheme = scheme.new("__precompiled__", {package = self})
+ precompiled_scheme:urls_set(table.wrap(artifacts_info.urls))
+ local versions_list = table.clone(self:_versions_list())
+ versions_list[self:version_str()] = artifacts_info.sha256
+ precompiled_scheme:_versions_list_set(versions_list)
+
+ precompiled_scheme:set("install", function (package)
+ sandbox_module.import("lib.detect.find_path")
+ local rootdir = find_path("manifest.txt", path.join(os.curdir(), "*", "*", "*"))
+ if not rootdir then
+ os.raise("package(%s): manifest.txt not found when installing artifacts!", package:displayname())
+ end
+ os.cp(path.join(rootdir, "*"), package:installdir(), {symlink = true})
+ local manifest = package:manifest_load()
+ if not manifest then
+ os.raise("package(%s): load manifest.txt failed when installing artifacts!", package:displayname())
+ end
+ if manifest.vars then
+ for k, v in pairs(manifest.vars) do
+ package:set(k, v)
end
- if manifest.components then
- local vars = manifest.components.vars
- if vars then
- for component_name, component_vars in pairs(vars) do
- local comp = package:component(component_name)
- if comp then
- for k, v in pairs(component_vars) do
- comp:set(k, v)
- end
+ end
+ if manifest.components then
+ local vars = manifest.components.vars
+ if vars then
+ for component_name, component_vars in pairs(vars) do
+ local comp = package:component(component_name)
+ if comp then
+ for k, v in pairs(component_vars) do
+ comp:set(k, v)
end
end
end
end
- if manifest.envs then
- local envs = self:_rawenvs()
- for k, v in pairs(manifest.envs) do
- envs[k] = v
- end
+ end
+ if manifest.envs then
+ local envs = self:_rawenvs()
+ for k, v in pairs(manifest.envs) do
+ envs[k] = v
end
- -- save the remote install directory to fix the install path in .cmake/.pc files for precompiled artifacts
- --
- -- @see https://github.com/xmake-io/xmake/issues/2210
- --
- manifest.artifacts = manifest.artifacts or {}
- manifest.artifacts.remotedir = manifest.artifacts.installdir
- end)
- self._IS_PRECOMPILED = true
- end
+ end
+ -- save the remote install directory to fix the install path in .cmake/.pc files for precompiled artifacts
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/2210
+ --
+ manifest.artifacts = manifest.artifacts or {}
+ manifest.artifacts.remotedir = manifest.artifacts.installdir
+ end)
+
+ -- add the precompiled scheme
+ table.insert(self:schemes_orderlist(), 1, precompiled_scheme)
+ self:schemes()[precompiled_scheme:name()] = precompiled_scheme
end
-- is this package built?
@@ -429,27 +428,7 @@ end
-- is this package precompiled?
function _instance:is_precompiled()
- return self._IS_PRECOMPILED
-end
-
--- fallback to source code build
-function _instance:fallback_build()
- if self:is_precompiled() then
- local artifacts_backup = self._ARTIFACTS_BACKUP
- if artifacts_backup then
- if artifacts_backup.urls then
- self:urls_set(artifacts_backup.urls)
- end
- if artifacts_backup.versions then
- self._INFO:apival_set("versions", artifacts_backup.versions)
- end
- if artifacts_backup.install then
- self._INFO:apival_set("install", artifacts_backup.install)
- end
- self._MANIFEST = nil
- end
- self._IS_PRECOMPILED = false
- end
+ return self:current_scheme():is_precompiled()
end
-- get the given dependent package
@@ -1772,7 +1751,7 @@ end
function _instance:script(name, generic)
-- get script
- local script = self:get(name)
+ local script = self:current_scheme():get(name) or self:get(name)
local result = select_script(script, {plat = self:plat(), arch = self:arch()}) or generic
-- imports some modules first
diff --git a/xmake/core/package/scheme.lua b/xmake/core/package/scheme.lua
index 94a2a7d02..d03cce0a9 100644
--- a/xmake/core/package/scheme.lua
+++ b/xmake/core/package/scheme.lua
@@ -65,6 +65,11 @@ function _instance:is_default()
return self:name() == "__default__"
end
+-- is precompiled scheme?
+function _instance:is_precompiled()
+ return self:name() == "__precompiled__"
+end
+
-- get the it's package
function _instance:package()
return self._PACKAGE
@@ -211,6 +216,11 @@ function _instance:_versions_list()
return self._VERSIONS_LIST
end
+-- set versions list
+function _instance:_versions_list_set(versions_list)
+ self._VERSIONS_LIST = versions_list
+end
+
-- get version
function _instance:version()
return self._VERSION
@@ -397,6 +407,12 @@ function scheme.apis()
-- scheme.add_xxx
"scheme.add_urls"
},
+ script = {
+ -- scheme.on_xxx
+ "scheme.on_download"
+ , "scheme.on_install"
+ , "scheme.on_test"
+ },
keyvalues = {
-- scheme.add_xxx
"scheme.add_patches"
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 614820ebc..8a2514e1a 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -428,6 +428,9 @@ function _get_package_tipname(package)
end
if current_scheme and not current_scheme:is_default() then
local scheme_name = current_scheme:name()
+ if current_scheme:is_precompiled() then
+ scheme_name = "the precompiled artifacts"
+ end
package_tipname = package_tipname .. " from " .. scheme_name
end
return package_tipname
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 2c1cf98fb..017b45482 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -815,7 +815,7 @@ function _select_artifacts(package, artifacts_manifest)
artifacts_info = _select_artifacts_for_generic(package, artifacts_manifest)
end
if artifacts_info then
- package:artifacts_set(artifacts_info)
+ package:use_precompiled_artifacts(artifacts_info)
end
end
diff --git a/xmake/modules/private/action/require/info.lua b/xmake/modules/private/action/require/info.lua
index d065388d2..f1be7a01b 100644
--- a/xmake/modules/private/action/require/info.lua
+++ b/xmake/modules/private/action/require/info.lua
@@ -111,24 +111,29 @@ function main(requires_raw)
-- show urls
local urls = instance:urls()
- if instance:is_precompiled() then
- instance:fallback_build()
- local urls_raw = instance:urls()
- if urls_raw then
- urls = table.join(urls, urls_raw)
- end
- end
if urls and #urls > 0 then
cprint(" -> ${color.dump.string_quote}urls${clear}:")
- for _, url in ipairs(urls) do
- print(" -> %s", filter.handle(url, instance))
- if git.asgiturl(url) then
- local url_alias = instance:url_alias(url)
- cprint(" -> ${yellow}%s", instance:revision(url_alias) or instance:tag() or instance:version_str())
- else
- local sourcehash = instance:sourcehash(instance:url_alias(url))
- if sourcehash then
- cprint(" -> ${yellow}%s", sourcehash)
+ local schemes = instance:schemes_orderlist()
+ if schemes then
+ for _, scheme in ipairs(schemes) do
+ if not scheme:is_precompiled() then
+ local urls = scheme:urls()
+ if urls and #urls > 0 then
+ local scheme_name = scheme:is_default() and "default" or scheme:name()
+ cprint(" -> ${magenta}%s${clear}:", scheme_name)
+ for _, url in ipairs(urls) do
+ print(" -> %s", filter.handle(url, instance))
+ if git.asgiturl(url) then
+ local url_alias = scheme:url_alias(url)
+ cprint(" -> ${yellow}%s", scheme:revision(url_alias) or scheme:tag() or scheme:version_str())
+ else
+ local sourcehash = scheme:sourcehash(scheme:url_alias(url))
+ if sourcehash then
+ cprint(" -> ${yellow}%s", sourcehash)
+ end
+ end
+ end
+ end
end
end
end