summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-05-09 22:39:58 +0800
committerruki <[email protected]>2026-05-09 22:39:58 +0800
commitb9f0814d18eced256d4a88018275daf4b697beb6 (patch)
tree59898cdc5a1b79ccddc92fb7cb151a9efaa8dfe5
parentfa807b737b4b6b3004cccafc0dfdfdd66fcdce2d (diff)
improve ascend rules
-rw-r--r--xmake/languages/ascendc/xmake.lua6
-rw-r--r--xmake/modules/core/tools/bisheng.lua5
-rw-r--r--xmake/rules/ascendc/config/basic.lua34
-rw-r--r--xmake/rules/ascendc/config/main.lua29
-rw-r--r--xmake/rules/ascendc/xmake.lua27
5 files changed, 81 insertions, 20 deletions
diff --git a/xmake/languages/ascendc/xmake.lua b/xmake/languages/ascendc/xmake.lua
index 27774c16a..053be74df 100644
--- a/xmake/languages/ascendc/xmake.lua
+++ b/xmake/languages/ascendc/xmake.lua
@@ -42,9 +42,11 @@ language("ascendc")
, "target.includedirs"
, "target.defines"
, "target.undefines"
+ , "target.ascnpuarchs"
, "toolchain.includedirs"
, "toolchain.defines"
, "toolchain.undefines"
+ , "toolchain.ascnpuarchs"
, "target.sysincludedirs"
, "toolchain.sysincludedirs"
}
@@ -56,8 +58,10 @@ language("ascendc")
, "target.strip"
, "target.symbols"
, "target.optimize:check"
+ , "target.ascnpuarchs"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
+ , "toolchain.ascnpuarchs"
, "config.links"
-- move it before target.links to keep package/dependency order correct
, "target.linkgroups"
@@ -75,8 +79,10 @@ language("ascendc")
, "target.strip"
, "target.symbols"
, "target.optimize:check"
+ , "target.ascnpuarchs"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
+ , "toolchain.ascnpuarchs"
, "config.links"
, "target.links"
, "target.linkgroups"
diff --git a/xmake/modules/core/tools/bisheng.lua b/xmake/modules/core/tools/bisheng.lua
index 5d3726e66..9eef884b3 100644
--- a/xmake/modules/core/tools/bisheng.lua
+++ b/xmake/modules/core/tools/bisheng.lua
@@ -29,6 +29,11 @@ function init(self)
self:set("ascshflags", "-shared")
end
+-- make the npu-arch flag
+function nf_ascnpuarch(self, arch)
+ return "--npu-arch=" .. arch
+end
+
-- make the language flag
function nf_language(self, stdname)
if _g.cxxmaps == nil then
diff --git a/xmake/rules/ascendc/config/basic.lua b/xmake/rules/ascendc/config/basic.lua
new file mode 100644
index 000000000..79c4f4251
--- /dev/null
+++ b/xmake/rules/ascendc/config/basic.lua
@@ -0,0 +1,34 @@
+--!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 basic.lua
+--
+
+-- main entry
+function main(target, sourcekind)
+ -- set default c++ language if user has not set one
+ local has_cxx = false
+ for _, lang in ipairs(target:get("languages")) do
+ if lang:startswith("c++") or lang:startswith("cxx") then
+ has_cxx = true
+ break
+ end
+ end
+ if not has_cxx then
+ target:add("languages", "c++17")
+ end
+end
diff --git a/xmake/rules/ascendc/config/main.lua b/xmake/rules/ascendc/config/main.lua
new file mode 100644
index 000000000..d787a20ae
--- /dev/null
+++ b/xmake/rules/ascendc/config/main.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, Xmake Open Source Community.
+--
+-- @author wuzhenqing
+-- @file main.lua
+--
+
+-- imports
+import("rules.ascendc.config.basic", {rootdir = os.programdir(), alias = "config_basic"})
+
+-- main entry
+function main(target, sourcekind)
+
+ -- config basic configs
+ config_basic(target, sourcekind)
+end
diff --git a/xmake/rules/ascendc/xmake.lua b/xmake/rules/ascendc/xmake.lua
index 312230b07..2bd914d0d 100644
--- a/xmake/rules/ascendc/xmake.lua
+++ b/xmake/rules/ascendc/xmake.lua
@@ -18,36 +18,23 @@
-- @file xmake.lua
--
--- define rule: ascendc.env
-rule("ascendc.env")
- after_load(function (target)
- -- set default C++ standard (user can override via set_languages)
- target:add("languages", "c++17")
- end)
-
--- define rule: ascendc.npuarchs
-rule("ascendc.npuarchs")
- on_config(function (target)
- for _, arch in ipairs(table.unique(table.wrap(target:get("ascnpuarchs")))) do
- target:add("ascflags", "--npu-arch=" .. arch)
- target:add("shflags", "--npu-arch=" .. arch)
- target:add("ldflags", "--npu-arch=" .. arch)
- end
- end)
-
-- define rule: ascendc.build.asc
rule("ascendc.build.asc")
set_sourcekinds("asc")
- add_deps("ascendc.npuarchs")
+ on_config(function (target)
+ import("config")(target, "asc")
+ end)
on_build_files("private.action.build.object", {jobgraph = true, batch = true})
-- define rule: ascendc.build.aicpu
rule("ascendc.build.aicpu")
set_sourcekinds("aicpu")
- add_deps("ascendc.npuarchs")
+ on_config(function (target)
+ import("config")(target, "aicpu")
+ end)
on_build_files("private.action.build.object", {jobgraph = true, batch = true})
-- define rule: ascendc
rule("ascendc")
- add_deps("ascendc.env", "ascendc.build.asc", "ascendc.build.aicpu")
+ add_deps("ascendc.build.asc", "ascendc.build.aicpu")
add_deps("utils.inherit.links")