Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add naive csharp project support for vsxmake #4510

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions xmake/languages/csharp/check_main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--!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 Kethers
-- @file check_main.lua
--


-- check it
function main(sourcefile)

-- load source code
local sourcecode = io.readfile(sourcefile)

-- remove comment first
sourcecode = sourcecode:gsub("/%*.-%*/", "")
sourcecode = sourcecode:gsub("//.-\n", "\n")

-- find static void Main(string[] args) {}
if sourcecode:find("%s+Main%s*%(.-%)") then
return true
end

-- no main function
return false
end


92 changes: 92 additions & 0 deletions xmake/languages/csharp/load.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
--!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 load.lua
--

-- get apis
function _get_apis()
local apis = {}
apis.values = {
-- target.add_xxx
"target.add_links"
, "target.add_syslinks"
, "target.add_ldflags"
, "target.add_arflags"
, "target.add_shflags"
, "target.add_defines"
, "target.add_undefines"
, "target.add_frameworks"
, "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
, "target.add_forceincludes"
-- option.add_xxx
, "option.add_links"
, "option.add_syslinks"
, "option.add_ldflags"
, "option.add_arflags"
, "option.add_shflags"
, "option.add_defines"
, "option.add_undefines"
, "option.add_frameworks"
, "option.add_rpathdirs"
-- toolchain.add_xxx
, "toolchain.add_links"
, "toolchain.add_syslinks"
, "toolchain.add_ldflags"
, "toolchain.add_arflags"
, "toolchain.add_shflags"
, "toolchain.add_defines"
, "toolchain.add_undefines"
, "toolchain.add_frameworks"
, "toolchain.add_rpathdirs"
, "toolchain.add_linkdirs"
, "toolchain.add_includedirs"
, "toolchain.add_sysincludedirs"
, "toolchain.add_frameworkdirs"
}
apis.groups = {
-- target.add_xxx
"target.add_linkorders"
, "target.add_linkgroups"
-- package.add_xxx
, "package.add_linkorders"
, "package.add_linkgroups"
}
apis.paths = {
-- target.set_xxx
"target.set_pcheader"
, "target.set_pcxxheader"
-- target.add_xxx
, "target.add_headerfiles"
, "target.add_linkdirs"
, "target.add_includedirs"
, "target.add_sysincludedirs"
, "target.add_frameworkdirs"
-- option.add_xxx
, "option.add_linkdirs"
, "option.add_includedirs"
, "option.add_sysincludedirs"
, "option.add_frameworkdirs"
}
return apis
end

function main()
return {apis = _get_apis()}
end


145 changes: 145 additions & 0 deletions xmake/languages/csharp/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
--!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 Kethers
-- @file xmake.lua
--

language("csharp")
add_rules("csharp")
set_sourcekinds {cs = {".cs"}}
Copy link
Member

@waruqi waruqi Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add set_sourceflags {cs = {"csflags"}}

set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
set_langkinds {cs = "cs"}
set_mixingkinds("cs")

on_load("load")
-- may not have main function entry when used as scripting language
-- on_check_main("check_main")

set_nameflags {
object = {
"config.includedirs"
, "config.frameworkdirs"
, "config.frameworks"
, "target.symbols"
, "target.warnings"
, "target.fpmodels"
, "target.optimize:check"
, "target.vectorexts:check"
, "target.languages"
, "target.runtimes"
, "target.includedirs"
, "target.defines"
, "target.undefines"
, "target.frameworkdirs"
, "target.frameworks"
, "target.exceptions"
, "target.encodings"
, "target.pcheader"
, "target.pcxxheader"
, "target.forceincludes"
, "toolchain.includedirs"
, "toolchain.defines"
, "toolchain.undefines"
, "toolchain.frameworkdirs"
, "toolchain.frameworks"
, "target.sysincludedirs"
, "toolchain.sysincludedirs"
}
, binary = {
"config.linkdirs"
, "config.frameworkdirs"
, "target.linkdirs"
, "target.frameworkdirs"
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
, "target.optimize:check"
, "target.runtimes"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
, "toolchain.frameworkdirs"
, "config.links"
, "target.linkgroups" -- we must move it before target.links, because we need sort correct order for package and its deps
, "target.links"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
, "toolchain.frameworks"
, "config.syslinks"
, "target.syslinks"
, "toolchain.syslinks"
}
, shared = {
"config.linkdirs"
, "config.frameworkdirs"
, "target.linkdirs"
, "target.frameworkdirs"
, "target.rpathdirs"
, "target.strip"
, "target.symbols"
, "target.optimize:check"
, "target.runtimes"
, "toolchain.linkdirs"
, "toolchain.rpathdirs"
, "toolchain.frameworkdirs"
, "config.links"
, "target.links"
, "target.linkgroups"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
, "toolchain.frameworks"
, "config.syslinks"
, "target.syslinks"
, "toolchain.syslinks"
}
, static = {
"target.strip"
, "target.symbols"
}
}

set_menu {
config =
{
{category = "Cross Complation Configuration/Linker Configuration" }
, {nil, "ld", "kv", nil, "The Linker" }
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "sh", "kv", nil, "The Shared Library Linker" }
, {nil, "ranlib", "kv", nil, "The Static Library Index Generator" }

, {category = "Cross Complation Configuration/Linker Flags Configuration" }
, {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
, {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
, {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" }

, {category = "Cross Complation Configuration/Builtin Flags Configuration" }
, {nil, "links", "kv", nil, "The Link Libraries" }
, {nil, "syslinks", "kv", nil, "The System Link Libraries" }
, {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
, {nil, "includedirs", "kv", nil, "The Include Search Directories" }
, {nil, "frameworks", "kv", nil, "The Frameworks" }
, {nil, "frameworkdirs", "kv", nil, "The Frameworks Search Directories" }
}
}






Loading