summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-20 23:53:59 +0800
committerruki <[email protected]>2023-09-20 23:53:59 +0800
commit1ca0b3dc0d00d10ecc1d82aaa22c4b17d7285917 (patch)
treea2c558340185b03d55e36c7837ceb280ba1db4af
parent9ea992d663e636981ec3f0d38d125688f265e216 (diff)
fix local deps for cargo #4222
-rw-r--r--xmake/modules/package/manager/cargo/install_package.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua
index c7649ccde..ca9706643 100644
--- a/xmake/modules/package/manager/cargo/install_package.lua
+++ b/xmake/modules/package/manager/cargo/install_package.lua
@@ -24,6 +24,27 @@ import("core.project.config")
import("lib.detect.find_tool")
import("private.tools.rust.check_target")
+-- translate local path in dependencies
+-- @see https://github.com/xmake-io/xmake/issues/4222
+-- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html
+--
+-- e.g.
+-- [dependencies]
+-- hello_utils = { path = "./hello_utils", version = "0.1.0" }
+--
+-- [dependencies.my_lib]
+-- path = "../my_lib"
+function _translate_local_path_in_deps(cargotoml, rootdir)
+ local content = io.readfile(cargotoml)
+ content = content:gsub("path%s+=%s+\"(.-)\"", function (localpath)
+ if not path.is_absolute(localpath) then
+ localpath = path.absolute(localpath, rootdir)
+ end
+ return "path = \"" .. localpath .. "\""
+ end)
+ io.writefile(cargotoml, content)
+end
+
-- install package
--
-- e.g.
@@ -65,6 +86,7 @@ function main(name, opt)
if configs.cargo_toml then
assert(os.isfile(configs.cargo_toml), "%s not found!", configs.cargo_toml)
os.cp(configs.cargo_toml, cargotoml)
+ _translate_local_path_in_deps(cargotoml, path.directory(configs.cargo_toml))
-- we need add `[workspace]` to prevent cargo from searching up for a parent.
-- https://github.com/rust-lang/cargo/issues/10534#issuecomment-1087631050
local tomlfile = io.open(cargotoml, "a")