diff options
| author | ruki <[email protected]> | 2024-03-25 13:25:27 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-25 13:25:27 +0800 |
| commit | 87713d5f53292bc88bc34500eb8239f44436dcf0 (patch) | |
| tree | 1e1913abb4fb6f9b046f4be808725b3a4a706849 /xmake/modules | |
| parent | dc77268912c466e205b409f07fa5b22b4d877bcc (diff) | |
| parent | 76a093f12a740f2b2e35a1bae3bb8e6644100d80 (diff) | |
Merge pull request #4874 from xmake-io/harmony
Add Harmony SDK support
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/detect/sdks/find_hdk.lua | 111 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_ndk.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/detect/find_platform.lua | 2 |
3 files changed, 114 insertions, 7 deletions
diff --git a/xmake/modules/detect/sdks/find_hdk.lua b/xmake/modules/detect/sdks/find_hdk.lua new file mode 100644 index 000000000..99a9ad60b --- /dev/null +++ b/xmake/modules/detect/sdks/find_hdk.lua @@ -0,0 +1,111 @@ +--!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 ruki +-- @file find_hdk.lua +-- + +-- imports +import("core.base.option") +import("core.base.global") +import("core.project.config") +import("core.cache.detectcache") +import("lib.detect.find_directory") + +-- find hdk directory +function _find_hdkdir(sdkdir) + + -- get hdk directory + if not sdkdir then + if not sdkdir then + if is_host("macosx") then + sdkdir = find_directory("native", "~/Library/Huawei/Sdk/*/*") + elseif is_host("windows") then + sdkdir = find_directory("native", "~/Huawei/Sdk/*/*") + end + end + end + + -- get hdk directory + if sdkdir and os.isdir(sdkdir) then + return path.translate(sdkdir) + end +end + +-- find the hdk toolchain +function _find_hdk(sdkdir) + + -- find hdk root directory + sdkdir = _find_hdkdir(sdkdir) + if not sdkdir then + return + end + + -- get the binary directory + local bindir = path.join(sdkdir, "llvm", "bin") + if not os.isdir(bindir) then + return + end + + local sysroot = path.join(sdkdir, "sysroot") + return {sdkdir = sdkdir, + bindir = bindir, + sysroot = sysroot} +end + +-- find hdk toolchains +-- +-- @param sdkdir the hdk directory +-- @param opt the argument options +-- e.g. {verbose = true, force = false} +-- +-- @return the hdk toolchains. e.g. {bindir = .., cross = ..} +-- +-- @code +-- +-- local toolchain = find_hdk("/xxx/android-hdk-r10e") +-- +-- @endcode +-- +function main(sdkdir, opt) + opt = opt or {} + + -- attempt to load cache first + local key = "detect.sdks.find_hdk" + local cacheinfo = detectcache:get(key) or {} + if not opt.force and cacheinfo.hdk and cacheinfo.hdk.sdkdir and os.isdir(cacheinfo.hdk.sdkdir) then + return cacheinfo.hdk + end + + -- find hdk + local hdk = _find_hdk(sdkdir or config.get("sdk") or global.get("sdk")) + if hdk and hdk.sdkdir then + config.set("hdk", hdk.sdkdir, {force = true, readonly = true}) + if opt.verbose or option.get("verbose") then + cprint("checking for Harmony SDK directory ... ${color.success}%s", hdk.sdkdir) + end + else + if opt.verbose or option.get("verbose") then + cprint("checking for Harmony SDK directory ... ${color.nothing}${text.nothing}") + end + end + + -- save to cache + cacheinfo.hdk = hdk or false + detectcache:set(key, cacheinfo) + detectcache:save() + return hdk +end diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index ac412bce0..f5c06f317 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -275,26 +275,20 @@ function main(sdkdir, opt) end -- get arch - local arch = opt.arch or config.get("arch") or "armv7-a" + local arch = opt.arch or config.get("arch") or "armeabi-v7a" -- find ndk local ndk = _find_ndk(sdkdir or config.get("ndk") or global.get("ndk"), arch, opt.sdkver or config.get("ndk_sdkver"), opt.toolchains_ver or config.get("ndk_toolchains_ver")) if ndk and ndk.sdkdir then - - -- save to config config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) config.set("ndkver", ndk.ndkver, {force = true, readonly = true}) config.set("ndk_sdkver", ndk.sdkver, {force = true, readonly = true}) config.set("ndk_toolchains_ver", ndk.toolchains_ver, {force = true, readonly = true}) - - -- trace if opt.verbose or option.get("verbose") then cprint("checking for NDK directory ... ${color.success}%s", ndk.sdkdir) cprint("checking for SDK version of NDK ... ${color.success}%s", ndk.sdkver) end else - - -- trace if opt.verbose or option.get("verbose") then cprint("checking for NDK directory ... ${color.nothing}${text.nothing}") end diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index e4308a90e..0fa17e567 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -112,6 +112,8 @@ function _find_arch(plat, arch) else arch = "x86_64" end + elseif plat == "harmony" then + arch = "arm64-v8a" elseif plat == "cross" then arch = _find_arch_from_cross() else |
