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 | |
| parent | dc77268912c466e205b409f07fa5b22b4d877bcc (diff) | |
| parent | 76a093f12a740f2b2e35a1bae3bb8e6644100d80 (diff) | |
Merge pull request #4874 from xmake-io/harmony
Add Harmony SDK support
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | README_zh.md | 2 | ||||
| -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 | ||||
| -rw-r--r-- | xmake/platforms/harmony/xmake.lua | 35 | ||||
| -rw-r--r-- | xmake/toolchains/hdk/check.lua | 59 | ||||
| -rw-r--r-- | xmake/toolchains/hdk/load.lua | 86 | ||||
| -rw-r--r-- | xmake/toolchains/hdk/xmake.lua | 29 |
9 files changed, 328 insertions, 7 deletions
@@ -193,6 +193,8 @@ $ xmake f --menu * MinGW (i386, x86_64, arm, arm64) * Cygwin (i386, x86_64) * Wasm (wasm32, wasm64) +* Haiku (i386, x86_64) +* Harmony (x86_64, armeabi-v7a, arm64-v8a) * Cross (cross-toolchains ..) ## Supported toolchains @@ -242,6 +244,7 @@ masm32 The MASM32 SDK iverilog Icarus Verilog verilator Verilator open-source SystemVerilog simulator and lint system cosmocc build-once run-anywhere +hdk Harmony SDK ``` ## Supported languages diff --git a/README_zh.md b/README_zh.md index 20eab35bb..ad20aa0b8 100644 --- a/README_zh.md +++ b/README_zh.md @@ -255,6 +255,7 @@ $ xmake f --menu * Cygwin (i386, x86_64) * Wasm (wasm32, wasm64) * Haiku (i386, x86_64) +* Harmony (x86_64, armeabi-v7a, arm64-v8a) * Cross (cross-toolchains ..) ## 支持工具链 @@ -304,6 +305,7 @@ masm32 The MASM32 SDK iverilog Icarus Verilog verilator Verilator open-source SystemVerilog simulator and lint system cosmocc build-once run-anywhere +hdk Harmony SDK ``` ## 支持语言 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 diff --git a/xmake/platforms/harmony/xmake.lua b/xmake/platforms/harmony/xmake.lua new file mode 100644 index 000000000..ccfbacc1f --- /dev/null +++ b/xmake/platforms/harmony/xmake.lua @@ -0,0 +1,35 @@ +--!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 xmake.lua +-- + +platform("harmony") + set_os("harmony") + set_hosts("macosx", "linux", "windows") + set_archs("armeabi-v7a", "arm64-v8a", "x86", "x86_64") + + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") + + set_toolchains("envs", "hdk") + + + + diff --git a/xmake/toolchains/hdk/check.lua b/xmake/toolchains/hdk/check.lua new file mode 100644 index 000000000..dd18394a1 --- /dev/null +++ b/xmake/toolchains/hdk/check.lua @@ -0,0 +1,59 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_hdk") + +-- check the hdk toolchain +function _check_hdk(toolchain) + local hdk + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir and os.isdir(installdir) then + hdk = find_hdk(installdir, {force = true, verbose = option.get("verbose")}) + if hdk then + break + end + end + end + if not hdk then + hdk = find_hdk(toolchain:config("hdk") or config.get("sdk"), {force = true, verbose = true}) + end + if hdk then + toolchain:config_set("sdkdir", hdk.sdkdir) + toolchain:config_set("bindir", hdk.bindir) + toolchain:config_set("sysroot", hdk.sysroot) + toolchain:configs_save() + return true + else + --[[TODO we also need to add this tips when use remote hdk toolchain + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --hdk=xxx") + cprint("or - xmake global --hdk=xxx") + raise()]] + end +end + +function main(toolchain) + return _check_hdk(toolchain) +end diff --git a/xmake/toolchains/hdk/load.lua b/xmake/toolchains/hdk/load.lua new file mode 100644 index 000000000..0b33f63c3 --- /dev/null +++ b/xmake/toolchains/hdk/load.lua @@ -0,0 +1,86 @@ +--!A cross-toolchain 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 load.lua +-- + +-- imports +import("core.base.hashset") +import("core.project.config") + +-- get target +function _get_target(arch) + local targets = { + ["armeabi-v7a"] = "armv7-linux-ohos" + , ["arm64-v8a"] = "aarch64-linux-ohos" + , ["x86_64"] = "x86_64-linux-ohos" + } + assert(targets[arch], "unknown arch(%s) for harmony!", arch) + return targets[arch] +end + +-- load hdk toolchain +function main(toolchain) + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = toolchain:config("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- get sdk directory + local sdkdir = toolchain:sdkdir() + + -- set toolset + toolchain:set("toolset", "cc", "clang") + toolchain:set("toolset", "cxx", "clang++") + toolchain:set("toolset", "cpp", "clang -E") + toolchain:set("toolset", "as", "clang") + toolchain:set("toolset", "ld", "clang++", "clang") + toolchain:set("toolset", "sh", "clang++", "clang") + toolchain:set("toolset", "ar", "llvm-ar") + toolchain:set("toolset", "ranlib", "llvm-ranlib") + toolchain:set("toolset", "strip", "llvm-strip") + + -- add hdk target + local arch = toolchain:arch() + local target = _get_target(arch) + toolchain:add("cxflags", "--target=" .. target) + toolchain:add("asflags", "--target=" .. target) + toolchain:add("ldflags", "--target=" .. target) + toolchain:add("shflags", "--target=" .. target) + + -- add sysroot + local sysroot = toolchain:config("sysroot") + if sysroot then + toolchain:add("cxflags", "--sysroot=" .. sysroot) + toolchain:add("asflags", "--sysroot=" .. sysroot) + toolchain:add("ldflags", "--sysroot=" .. sysroot) + toolchain:add("shflags", "--sysroot=" .. sysroot) + end + + -- init cxflags for the target kind: binary + toolchain:add("binary.cxflags", "-fPIE", "-pie") + + -- add "-fPIE -pie" to ldflags + toolchain:add("ldflags", "-fPIE") + toolchain:add("ldflags", "-pie") + + -- add some builtin flags + toolchain:add("cxflags", "-D__MUSL__") +end diff --git a/xmake/toolchains/hdk/xmake.lua b/xmake/toolchains/hdk/xmake.lua new file mode 100644 index 000000000..16adb013f --- /dev/null +++ b/xmake/toolchains/hdk/xmake.lua @@ -0,0 +1,29 @@ +--!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 xmake.lua +-- + +-- harmony sdk toolchain +toolchain("hdk") + set_kind("standalone") + set_homepage("https://developer.harmonyos.com/cn/develop/") + set_description("Harmony SDK") + set_runtimes("c++_static", "c++_shared") + + on_check("check") + on_load("load") |
