Skip to content

Commit 27bd61c

Browse files
committed
install csharp target
1 parent f48ca26 commit 27bd61c

File tree

4 files changed

+163
-2
lines changed

4 files changed

+163
-2
lines changed

xmake/modules/target/action/install/main.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ function _get_target_includedir(target, opt)
4949
return path.join(opt.installdir, opt.includedir)
5050
end
5151

52-
53-
5452
-- copy file with symlinks
5553
function _copy_file_with_symlinks(srcfile, outputdir)
5654
if os.islink(srcfile) then

xmake/rules/csharp/install.lua

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, Xmake Open Source Community.
16+
--
17+
-- @author ruki
18+
-- @file install.lua
19+
--
20+
21+
-- imports
22+
import("core.project.config")
23+
24+
-- get dotnet program
25+
function _get_dotnet(target)
26+
return target:tool("cs") or "dotnet"
27+
end
28+
29+
-- get build configuration from mode
30+
function _get_configuration()
31+
local mode = config.mode() or "release"
32+
if mode:lower() == "debug" then
33+
return "Debug"
34+
end
35+
return "Release"
36+
end
37+
38+
-- get output directory for dotnet publish
39+
function _get_outputdir(target)
40+
if target:is_binary() then
41+
return target:bindir()
42+
else
43+
return target:libdir()
44+
end
45+
end
46+
47+
-- install csharp target using dotnet publish
48+
function main(target)
49+
local installdir = target:installdir()
50+
if not installdir then
51+
return
52+
end
53+
54+
-- get output directory based on target kind
55+
local outputdir = _get_outputdir(target)
56+
if not outputdir then
57+
return
58+
end
59+
60+
-- run dotnet publish
61+
local csprojfile = target:data("csharp.csproj")
62+
local argv = {"publish"}
63+
if csprojfile then
64+
table.insert(argv, csprojfile)
65+
end
66+
table.join2(argv, {"--nologo", "--no-build",
67+
"--configuration", _get_configuration(),
68+
"--output", outputdir})
69+
local dotnet = _get_dotnet(target)
70+
os.vrunv(dotnet, argv)
71+
72+
-- install extra files (add_installfiles)
73+
local srcfiles, dstfiles = target:installfiles(installdir)
74+
if srcfiles and dstfiles then
75+
for idx, srcfile in ipairs(srcfiles) do
76+
os.vcp(srcfile, dstfiles[idx])
77+
end
78+
end
79+
end

xmake/rules/csharp/installcmd.lua

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, Xmake Open Source Community.
16+
--
17+
-- @author ruki
18+
-- @file installcmd.lua
19+
--
20+
21+
-- imports
22+
import("core.project.config")
23+
24+
-- get dotnet program
25+
function _get_dotnet(target)
26+
return target:tool("cs") or "dotnet"
27+
end
28+
29+
-- get build configuration from mode
30+
function _get_configuration()
31+
local mode = config.mode() or "release"
32+
if mode:lower() == "debug" then
33+
return "Debug"
34+
end
35+
return "Release"
36+
end
37+
38+
-- install csharp target for xpack using dotnet publish
39+
function main(target, batchcmds, opt)
40+
local package = opt.package
41+
if not package then
42+
return
43+
end
44+
45+
local installdir = package:installdir()
46+
if not installdir then
47+
return
48+
end
49+
50+
-- get output directory based on target kind
51+
local outputdir
52+
if target:is_binary() then
53+
outputdir = package:installdir("bin")
54+
else
55+
outputdir = package:installdir("lib")
56+
end
57+
58+
-- run dotnet publish to a temporary publish directory, then copy to install directory
59+
local publishdir = path.join(target:autogendir(), "rules", "csharp", "publish")
60+
local csprojfile = target:data("csharp.csproj")
61+
local argv = {"publish"}
62+
if csprojfile then
63+
table.insert(argv, csprojfile)
64+
end
65+
table.join2(argv, {"--nologo", "--no-build",
66+
"--configuration", _get_configuration(),
67+
"--output", publishdir})
68+
local dotnet = _get_dotnet(target)
69+
batchcmds:vrunv(dotnet, argv)
70+
71+
-- copy published files to output directory
72+
batchcmds:mkdir(outputdir)
73+
batchcmds:cp(path.join(publishdir, "**"), outputdir, {rootdir = publishdir})
74+
75+
-- install extra files (add_installfiles)
76+
local srcfiles, dstfiles = target:installfiles(installdir)
77+
if srcfiles and dstfiles then
78+
for idx, srcfile in ipairs(srcfiles) do
79+
batchcmds:cp(srcfile, dstfiles[idx])
80+
end
81+
end
82+
end

xmake/rules/csharp/xmake.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ rule("csharp.build")
116116
set_sourcekinds("cs")
117117
on_config("config")
118118
on_build("build")
119+
on_install("install")
120+
on_installcmd("installcmd")
119121

120122
rule("csharp")
121123
add_deps("csharp.build")

0 commit comments

Comments
 (0)