diff options
| -rw-r--r-- | xmake/modules/package/manager/cargo/install_package.lua | 22 |
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") |
