From 37c4fe2e8a818f925940a8355b59fc393de5ff4f Mon Sep 17 00:00:00 2001 From: dijunkun Date: Wed, 22 Jul 2026 17:23:35 +0800 Subject: [PATCH] build: install Rust toolchain for Slint --- thirdparty/rust/xmake.lua | 35 +++++++++++++++++++++++++++++++++++ thirdparty/slint/xmake.lua | 1 + thirdparty/xmake.lua | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 thirdparty/rust/xmake.lua diff --git a/thirdparty/rust/xmake.lua b/thirdparty/rust/xmake.lua new file mode 100644 index 0000000..58d296c --- /dev/null +++ b/thirdparty/rust/xmake.lua @@ -0,0 +1,35 @@ +package("rust") + set_kind("toolchain") + set_homepage("https://rust-lang.org") + set_description("Rust is a general-purpose programming language emphasizing performance, type safety, and concurrency.") + + add_versions("1.92.0", "") + + add_deps("ca-certificates", {host = true, private = true}) + add_deps("rustup", {host = true, private = true, system = false}) + + on_install(function(package) + import("core.tools.rustc.target_triple") + + local host_target = assert(target_triple(package:plat(), package:arch()), + "failed to determine the Rust host target triple") + local version = package:version():shortstr() + local toolchain_name = version .. "-" .. host_target + local rustup_home = assert(os.getenv("RUSTUP_HOME"), "cannot find rustup home") + + os.vrunv("rustup", {"install", "--no-self-update", toolchain_name}) + os.vmv(path.join(rustup_home, "toolchains", toolchain_name, "*"), package:installdir()) + + -- Keep the Xmake-managed toolchain isolated from rustup after installation. + os.vrm(path.join(rustup_home, "toolchains", toolchain_name)) + os.vrm(path.join(rustup_home, "update-hashes", toolchain_name)) + + package:addenv("RC", "bin/rustc" .. (is_host("windows") and ".exe" or "")) + package:mark_as_pathenv("RC") + end) + + on_test(function(package) + os.vrun("cargo --version") + os.vrun("rustc --version") + end) +package_end() diff --git a/thirdparty/slint/xmake.lua b/thirdparty/slint/xmake.lua index a2c5063..b4c19fc 100644 --- a/thirdparty/slint/xmake.lua +++ b/thirdparty/slint/xmake.lua @@ -10,6 +10,7 @@ package("slint") add_configs("shared", {description = "Build the Slint runtime as a shared library", default = true, type = "boolean", readonly = true}) add_deps("cmake") + add_deps("rust 1.92.0", {host = true, private = true, system = false}) on_load(function(package) package:add("includedirs", "include/slint") diff --git a/thirdparty/xmake.lua b/thirdparty/xmake.lua index e0a8563..e314aea 100644 --- a/thirdparty/xmake.lua +++ b/thirdparty/xmake.lua @@ -1 +1 @@ -includes("cpp-httplib", "slint") +includes("cpp-httplib", "rust", "slint")