diff options
| author | ruki <[email protected]> | 2026-05-11 13:57:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-05-11 13:57:30 +0800 |
| commit | fe5d4800ea9c524c06cc54c52afa3955da2612f1 (patch) | |
| tree | f72fe3c09ea76809ada5f98bee28cf6e1911d30e /xmake/toolchains | |
| parent | c14b01fd77d4d31376f03263e9833deadb998e4e (diff) | |
| parent | 70f6ecdc9aeecabeee5727867b3dae13d006c82f (diff) | |
Merge pull request #7535 from xmake-io/ascend
Add Huawei Ascend C toolchain support
Diffstat (limited to 'xmake/toolchains')
| -rw-r--r-- | xmake/toolchains/ascendc/check.lua | 59 | ||||
| -rw-r--r-- | xmake/toolchains/ascendc/load.lua | 50 | ||||
| -rw-r--r-- | xmake/toolchains/ascendc/xmake.lua | 46 |
3 files changed, 155 insertions, 0 deletions
diff --git a/xmake/toolchains/ascendc/check.lua b/xmake/toolchains/ascendc/check.lua new file mode 100644 index 000000000..65d79834b --- /dev/null +++ b/xmake/toolchains/ascendc/check.lua @@ -0,0 +1,59 @@ +--!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, Xmake Open Source Community. +-- +-- @author wuzhenqing +-- @file check.lua +-- + +-- imports +import("lib.detect.find_tool") +import("detect.sdks.find_ascend") + +-- check the ascendc toolchain +function main(toolchain) + if not toolchain:is_plat("linux") then + return false + end + + -- locate the Ascend SDK and derive its host layout + local ascend = find_ascend(toolchain:sdkdir()) + if not ascend then + return false + end + + -- llvm-ar must sit next to bisheng (used as the static linker) + if not os.isexec(path.join(ascend.bindir, "llvm-ar")) then + return false + end + + -- probe bisheng to confirm it actually runs (catches broken installs). + -- pass bindir via paths and inject LD_LIBRARY_PATH so bisheng can load + -- its own shared libraries during the version probe. + local ld = os.getenv("LD_LIBRARY_PATH") or "" + local result = find_tool("bisheng", { + paths = {ascend.bindir}, + envs = {LD_LIBRARY_PATH = ld ~= "" and (ascend.libdir .. path.envsep() .. ld) or ascend.libdir}, + version = true}) + if not result or not result.program then + return false + end + + toolchain:config_set("sdkdir", ascend.sdkdir) + toolchain:config_set("bindir", ascend.bindir) + toolchain:config_set("hostroot", ascend.hostroot) + cprint("checking for Huawei Ascend C Toolchain (host: %s) ... ${color.success}${text.success}", ascend.host_archdir) + return true +end diff --git a/xmake/toolchains/ascendc/load.lua b/xmake/toolchains/ascendc/load.lua new file mode 100644 index 000000000..451cc136d --- /dev/null +++ b/xmake/toolchains/ascendc/load.lua @@ -0,0 +1,50 @@ +--!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, Xmake Open Source Community. +-- +-- @author wuzhenqing +-- @file load.lua +-- + +function main(toolchain) + local sdkdir = toolchain:config("sdkdir") + local hostroot = toolchain:config("hostroot") + if not sdkdir or not hostroot then + raise("ascendc toolchain not checked") + end + + -- add run environments + toolchain:add("runenvs", "LD_LIBRARY_PATH", path.join(hostroot, "lib64")) + + -- add toolchain-level search paths (picked up by language nameflags) + toolchain:add("includedirs", path.join(hostroot, "include")) + toolchain:add("includedirs", path.join(hostroot, "asc", "include")) + toolchain:add("includedirs", path.join(hostroot, "asc", "include", "aicpu_api")) + toolchain:add("includedirs", path.join(sdkdir, "include")) + toolchain:add("linkdirs", path.join(hostroot, "lib64")) + toolchain:add("linkdirs", path.join(hostroot, "devlib")) + toolchain:add("linkdirs", path.join(sdkdir, "lib64")) + toolchain:add("rpathdirs", path.join(hostroot, "lib64")) + toolchain:add("rpathdirs", path.join(hostroot, "devlib")) + toolchain:add("rpathdirs", path.join(sdkdir, "lib64")) + toolchain:add("syslinks", "ascendcl", "acl_rt", "dl") + + -- aicpu-specific compiler flags (SDK-path-dependent) + toolchain:add("aicpuflags", "-D_AICPU_DEVICE_") + toolchain:add("aicpuflags", "--cce-aicpu-L" .. path.join(hostroot, "lib64", "device", "lib64")) + toolchain:add("aicpuflags", "--cce-aicpu-laicpu_api") + toolchain:add("aicpuflags", "--cce-aicpu-toolkit-path=" .. path.join(sdkdir, "toolkit", "toolchain", "hcc", "bin")) + toolchain:add("aicpuflags", "--cce-aicpu-sysroot=" .. path.join(sdkdir, "toolkit", "toolchain", "hcc", "sysroot")) +end diff --git a/xmake/toolchains/ascendc/xmake.lua b/xmake/toolchains/ascendc/xmake.lua new file mode 100644 index 000000000..6071a6840 --- /dev/null +++ b/xmake/toolchains/ascendc/xmake.lua @@ -0,0 +1,46 @@ +--!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, Xmake Open Source Community. +-- +-- @author wuzhenqing +-- @file xmake.lua +-- + +-- Huawei Ascend C / bisheng toolchain +-- +-- @code +-- target("example") +-- set_toolchains("ascendc") +-- add_ascnpuarchs("dav-2201") +-- @endcode +-- +toolchain("ascendc") + + -- set homepage + set_homepage("https://www.hiascend.com/") + set_description("Huawei Ascend C (bisheng compiler driver)") + + -- set toolset + set_toolset("asc", "bisheng") + set_toolset("aicpu", "bisheng") + set_toolset("ascld", "bisheng") + set_toolset("ascsh", "bisheng") + set_toolset("ar", "llvm-ar", "ar") + + -- check toolchain + on_check("check") + + -- on load + on_load("load") |
