diff options
| author | ruki <[email protected]> | 2021-11-13 13:03:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-11-13 13:03:38 +0800 |
| commit | daef54e8a91ae742e18057756fcaa7548bc83930 (patch) | |
| tree | e2d2739ce79c59c895aeaca050409392d6cd3008 | |
| parent | 7625d0368ebf5dd461566b802ebb464cda2b1c9d (diff) | |
install cargo deps
| -rw-r--r-- | tests/projects/rust/cargo_deps/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/manager/cargo/install_package.lua | 61 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 2 |
4 files changed, 63 insertions, 7 deletions
diff --git a/tests/projects/rust/cargo_deps/xmake.lua b/tests/projects/rust/cargo_deps/xmake.lua index e8a06699b..73340dedf 100644 --- a/tests/projects/rust/cargo_deps/xmake.lua +++ b/tests/projects/rust/cargo_deps/xmake.lua @@ -1,7 +1,8 @@ add_rules("mode.release", "mode.debug") -add_requires("cargo::base64") +add_requires("cargo::base64 0.13.0") +add_requires("cargo::flate2 1.0.17", {configs = {features = "zlib"}}) target("test") set_kind("binary") add_files("src/main.rs") - add_packages("cargo::base64") + add_packages("cargo::base64", "cargo::flate2") diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 6b7f22a4e..d5d683741 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1867,6 +1867,8 @@ function package.load_from_system(packagename) opt.arch = pkg:arch() opt.require_version = pkg:version_str() opt.buildhash = pkg:buildhash() + opt.cachedir = pkg:cachedir() + opt.installdir = pkg:installdir() import("package.manager.install_package")(pkg:name(), opt) end diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua index cbf1df8f2..a500bb6a7 100644 --- a/xmake/modules/package/manager/cargo/install_package.lua +++ b/xmake/modules/package/manager/cargo/install_package.lua @@ -23,14 +23,23 @@ import("core.base.option") import("core.project.config") import("lib.detect.find_tool") +-- get configurations +function configurations() + return + { + features = {description = "set the features of dependency."}, + default_features = {description = "enables or disables any defaults provided by the dependency.", default = true}, + } +end + -- install package -- -- e.g. --- add_requires("cargo::zip") --- add_requires("cargo::zip >0.3") --- add_requires("cargo::zip 0.3.1") +-- add_requires("cargo::base64") +-- add_requires("cargo::base64 0.13.0") +-- add_requires("cargo::flate2 1.0.17", {configs = {features = {"zlib"}, ["default-features"] = false}}) -- --- @param name the package name, e.g. cargo::zip +-- @param name the package name, e.g. cargo::base64 -- @param opt the options, e.g. { verbose = true, mode = "release", plat = , arch = , require_version = "x.x.x"} -- -- @return true or false @@ -43,4 +52,48 @@ function main(name, opt) raise("cargo not found!") end + -- get required version + local require_version = assert(opt.require_version, "cargo::%s version not found!", name) + + -- build dependencies + local sourcedir = path.join(opt.cachedir, "source") + local cargotoml = path.join(sourcedir, "Cargo.toml") + os.tryrm(sourcedir) + local tomlfile = io.open(cargotoml, "w") + tomlfile:print("[package]") + tomlfile:print("name = \"cargodeps\"") + tomlfile:print("version = \"0.1.0\"") + tomlfile:print("edition = \"2018\"") + tomlfile:print("") + tomlfile:print("[dependencies]") + local features = opt.features + if features then + features = table.wrap(features) + tomlfile:print("%s = {version = \"%s\", features = [\"%s\"], default-features = %s}", name, require_version, table.concat(features, "\", \""), opt.default_features) + else + tomlfile:print("%s = \"%s\"", name, require_version) + end + tomlfile:close() + + -- generate main.rs + io.writefile(path.join(sourcedir, "src", "main.rs"), [[ +fn main() { + println!("Hello, world!"); +} + ]]) + + -- do build + local argv = {"build"} + if opt.mode ~= "debug" then + table.insert(argv, "--release") + end + if option.get("verbose") then + table.insert(argv, option.get("diagnosis") and "-vv" or "-v") + end + os.vrunv(cargo.program, argv, {curdir = sourcedir}) + + -- do install + local installdir = opt.installdir + os.tryrm(path.join(installdir, "lib")) + os.vcp(path.join(sourcedir, "target", opt.mode == "debug" and "debug" or "release", "deps"), path.join(installdir, "lib")) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 7a8502326..3bb12ac30 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -950,7 +950,7 @@ function get_configs_str(package) if type(v) == "boolean" then table.insert(configs, k .. ":" .. (v and "y" or "n")) else - table.insert(configs, k .. ":" .. v) + table.insert(configs, k .. ":" .. string.serialize(v, {strip = true, indent = false})) end end end |
