diff options
| author | ruki <[email protected]> | 2026-03-14 00:04:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-14 00:11:43 +0800 |
| commit | a86bde866d5f65d5fbd31f1474190dcc40aa2876 (patch) | |
| tree | a043c2be4830b300a59543f8d10bcfddced70f4f /xmake/modules/core | |
| parent | 4b56123d797578f1abec0c3d507282d9e5bc8f3b (diff) | |
improve csharp support
Diffstat (limited to 'xmake/modules/core')
| -rw-r--r-- | xmake/modules/core/tools/dotnet.lua | 88 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dotnet/has_flags.lua | 50 |
2 files changed, 138 insertions, 0 deletions
diff --git a/xmake/modules/core/tools/dotnet.lua b/xmake/modules/core/tools/dotnet.lua new file mode 100644 index 000000000..4cc96e317 --- /dev/null +++ b/xmake/modules/core/tools/dotnet.lua @@ -0,0 +1,88 @@ +--!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 ruki +-- @file dotnet.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.language.language") + +-- init it +function init(self) +end + +-- make the define flag +function nf_define(self, macro) + return {"-p:DefineConstants=" .. macro} +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = { + none = "-p:Optimize=false" + , fast = "-p:Optimize=true" + , faster = "-p:Optimize=true" + , fastest = "-p:Optimize=true" + , smallest = "-p:Optimize=true" + , aggressive = "-p:Optimize=true" + } + return maps[level] +end + +-- make the symbol flag +function nf_symbol(self, level) + local maps = { + debug = {"-p:DebugType=full", "-p:DebugSymbols=true"} + , hidden = {"-p:DebugType=pdbonly", "-p:DebugSymbols=true"} + } + return maps[level] +end + +-- make the warning flag +function nf_warning(self, level) + local maps = { + none = "-p:WarningLevel=0" + , less = "-p:WarningLevel=1" + , more = "-p:WarningLevel=3" + , all = "-p:WarningLevel=5" + , allextra = "-p:WarningLevel=9999" + , error = {"-p:WarningLevel=5", "-p:TreatWarningsAsErrors=true"} + } + return maps[level] +end + +-- make the build arguments list +function buildargv(self, sourcefiles, targetkind, targetfile, flags) + local argv = {"build"} + if flags then + table.join2(argv, flags) + end + table.insert(argv, "--output") + table.insert(argv, path.directory(targetfile)) + table.join2(argv, sourcefiles) + return self:program(), argv +end + +-- build the target file +function build(self, sourcefiles, targetkind, targetfile, flags) + os.mkdir(path.directory(targetfile)) + local program, argv = buildargv(self, sourcefiles, targetkind, targetfile, flags) + os.runv(program, argv, {envs = self:runenvs()}) +end diff --git a/xmake/modules/core/tools/dotnet/has_flags.lua b/xmake/modules/core/tools/dotnet/has_flags.lua new file mode 100644 index 000000000..eaffa7e88 --- /dev/null +++ b/xmake/modules/core/tools/dotnet/has_flags.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 ruki +-- @file has_flags.lua +-- + +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt) + local flag = flags[1] + -- dotnet MSBuild properties + if flag:startswith("-p:") or flag:startswith("/p:") then + return true + end + -- dotnet CLI options + if flag:startswith("--") then + return true + end + -- common csflags patterns + if flag:startswith("-") or flag:startswith("/") then + return true + end +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cs|csld|cssh]"} +-- +-- @return true or false +-- +function main(flags, opt) + opt = opt or {} + if _check_from_knownargs(flags, opt) then + return true + end + return false +end |
