From 2f886d8133855895229d3ce958e17fbfa86d2bca Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 10 May 2025 07:40:01 +0200 Subject: Make rustc target_triple public from private.tools.rust.target_triple to core.tools.rustc.target_triple --- xmake/modules/core/tools/rustc/target_triple.lua | 96 ++++++++++++++++++++++ .../package/manager/cargo/install_package.lua | 2 +- xmake/modules/private/tools/rust/target_triple.lua | 96 ---------------------- xmake/toolchains/rust/xmake.lua | 2 +- 4 files changed, 98 insertions(+), 98 deletions(-) create mode 100644 xmake/modules/core/tools/rustc/target_triple.lua delete mode 100644 xmake/modules/private/tools/rust/target_triple.lua diff --git a/xmake/modules/core/tools/rustc/target_triple.lua b/xmake/modules/core/tools/rustc/target_triple.lua new file mode 100644 index 000000000..3a83aed7e --- /dev/null +++ b/xmake/modules/core/tools/rustc/target_triple.lua @@ -0,0 +1,96 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author SirLynix +-- @file target_triple.lua +-- + +-- get arch part +function _translate_arch(arch, opt) + local maps = + { + ["aarch64"] = "aarch64" + , ["arm"] = "arm" + , ["armv5te"] = "arm" + , ["armeabi"] = "arm" + , ["armeabi-v7a"] = "armv7" + , ["armv7-a"] = "armv7" + , ["arm64"] = "aarch64" + , ["arm64-v8a"] = "aarch64" + , ["i386"] = "i686" + , ["i686"] = "i686" + , ["x86"] = "i686" + , ["x86_64"] = "x86_64" + , ["x64"] = "x86_64" + , ["wasm32"] = "wasm32" + , ["wasm64"] = "wasm64" + } + return maps[arch] or arch +end + +-- get platform part +function _translate_plat(plat, arch, opt) + if plat == "windows" then + return "-pc-windows-msvc" + elseif plat == "mingw" then + return "-pc-windows-gnu" + elseif plat == "linux" then + return "-unknown-linux-gnu" + elseif plat == "macosx" then + return "-apple-darwin" + elseif plat == "android" then + if arch == "armeabi-v7a" or arch == "armeabi" or arch == "armv7-a" or arch == "armv5te" then + return "-linux-androideabi" + else + return "-linux-android" + end + elseif plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then + local suffix = opt and opt.apple_sim and "-sim" or "" + if plat == "iphoneos" then + return "-apple-ios" .. suffix + elseif plat == "appletvos" then + return "-apple-tvos" .. suffix + elseif plat == "watchos" then + return "-apple-watchos" .. suffix + end + elseif plat == "bsd" then + return "-unknown-freebsd" + elseif plat == "wasm" then + return "-unknown-unknown" + end +end + +-- gets the rustc compatible target triple (e.g. x86_64-pc-windows-msvc) for a set plat/arch +-- +-- @param plat the target plat, e.g. windows, android, macosx, ... +-- @param arch the target name, e.g. arm64, x86_64, wasm64, ... +-- @param opt the options, e.g. {apple_sim = true) +-- +-- @return a valid rustc triple if plat and arch are recognized, nil otherwise +function main(plat, arch, opt) + + local target_arch = _translate_arch(arch, opt) + if not target_arch then + return + end + + local target_plat = _translate_plat(plat, arch, opt) + if not target_plat then + return + end + + return target_arch .. target_plat +end diff --git a/xmake/modules/package/manager/cargo/install_package.lua b/xmake/modules/package/manager/cargo/install_package.lua index 9f5d069cb..a5fe7f423 100644 --- a/xmake/modules/package/manager/cargo/install_package.lua +++ b/xmake/modules/package/manager/cargo/install_package.lua @@ -21,9 +21,9 @@ -- imports import("core.base.option") import("core.project.config") +import("core.tools.rustc.target_triple") import("lib.detect.find_tool") import("private.tools.rust.check_target") -import("private.tools.rust.target_triple") -- translate local path in dependencies -- @see https://github.com/xmake-io/xmake/issues/4222 diff --git a/xmake/modules/private/tools/rust/target_triple.lua b/xmake/modules/private/tools/rust/target_triple.lua deleted file mode 100644 index 3a83aed7e..000000000 --- a/xmake/modules/private/tools/rust/target_triple.lua +++ /dev/null @@ -1,96 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author SirLynix --- @file target_triple.lua --- - --- get arch part -function _translate_arch(arch, opt) - local maps = - { - ["aarch64"] = "aarch64" - , ["arm"] = "arm" - , ["armv5te"] = "arm" - , ["armeabi"] = "arm" - , ["armeabi-v7a"] = "armv7" - , ["armv7-a"] = "armv7" - , ["arm64"] = "aarch64" - , ["arm64-v8a"] = "aarch64" - , ["i386"] = "i686" - , ["i686"] = "i686" - , ["x86"] = "i686" - , ["x86_64"] = "x86_64" - , ["x64"] = "x86_64" - , ["wasm32"] = "wasm32" - , ["wasm64"] = "wasm64" - } - return maps[arch] or arch -end - --- get platform part -function _translate_plat(plat, arch, opt) - if plat == "windows" then - return "-pc-windows-msvc" - elseif plat == "mingw" then - return "-pc-windows-gnu" - elseif plat == "linux" then - return "-unknown-linux-gnu" - elseif plat == "macosx" then - return "-apple-darwin" - elseif plat == "android" then - if arch == "armeabi-v7a" or arch == "armeabi" or arch == "armv7-a" or arch == "armv5te" then - return "-linux-androideabi" - else - return "-linux-android" - end - elseif plat == "iphoneos" or plat == "appletvos" or plat == "watchos" then - local suffix = opt and opt.apple_sim and "-sim" or "" - if plat == "iphoneos" then - return "-apple-ios" .. suffix - elseif plat == "appletvos" then - return "-apple-tvos" .. suffix - elseif plat == "watchos" then - return "-apple-watchos" .. suffix - end - elseif plat == "bsd" then - return "-unknown-freebsd" - elseif plat == "wasm" then - return "-unknown-unknown" - end -end - --- gets the rustc compatible target triple (e.g. x86_64-pc-windows-msvc) for a set plat/arch --- --- @param plat the target plat, e.g. windows, android, macosx, ... --- @param arch the target name, e.g. arm64, x86_64, wasm64, ... --- @param opt the options, e.g. {apple_sim = true) --- --- @return a valid rustc triple if plat and arch are recognized, nil otherwise -function main(plat, arch, opt) - - local target_arch = _translate_arch(arch, opt) - if not target_arch then - return - end - - local target_plat = _translate_plat(plat, arch, opt) - if not target_plat then - return - end - - return target_arch .. target_plat -end diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua index a17dc3517..95c0f189a 100644 --- a/xmake/toolchains/rust/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -28,7 +28,7 @@ toolchain("rust") set_toolset("rcar", "$(env RC)", "rustc") on_load(function (toolchain) - import("private.tools.rust.target_triple") + import("core.tools.rustc.target_triple") local opt = {} if toolchain:config("appledev") == "simulator" then -- cgit v1.3.1 From e0b4e4e69b752593f90e03ee1e857092143c712b Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 10 May 2025 07:54:18 +0200 Subject: rustc/target_triple: Handle msys and cross --- xmake/modules/core/tools/rustc/target_triple.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/rustc/target_triple.lua b/xmake/modules/core/tools/rustc/target_triple.lua index 3a83aed7e..ddbf052ea 100644 --- a/xmake/modules/core/tools/rustc/target_triple.lua +++ b/xmake/modules/core/tools/rustc/target_triple.lua @@ -45,9 +45,9 @@ end function _translate_plat(plat, arch, opt) if plat == "windows" then return "-pc-windows-msvc" - elseif plat == "mingw" then + elseif plat == "mingw" or plat == "msys" then return "-pc-windows-gnu" - elseif plat == "linux" then + elseif plat == "linux" or plat == "cross" then return "-unknown-linux-gnu" elseif plat == "macosx" then return "-apple-darwin" -- cgit v1.3.1