Skip to content

Commit c3629a2

Browse files
committed
Initial support for building under .NET Core.
1 parent 7e3fbc1 commit c3629a2

File tree

12 files changed

+128
-37
lines changed

12 files changed

+128
-37
lines changed

build/Helpers.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ newoption {
66
allowed = {
77
{ "x86", "x86 32-bits" },
88
{ "x64", "x64 64-bits" },
9+
{ "AnyCPU", "Any CPU (.NET)" },
910
}
1011
}
1112

@@ -23,6 +24,10 @@ function is_64_bits_mono_runtime()
2324
end
2425

2526
function target_architecture()
27+
if _ACTION == "netcore" then
28+
return "AnyCPU"
29+
end
30+
2631
-- Default to 32-bit on Windows and Mono architecture otherwise.
2732
if explicit_target_architecture ~= nil then
2833
return explicit_target_architecture
@@ -50,8 +55,14 @@ if _ARGS[1] then
5055
builddir = path.getabsolute("./" .. _ARGS[1]);
5156
end
5257

53-
objsdir = path.join(builddir, "obj", "%{cfg.buildcfg}_%{cfg.platform}");
54-
libdir = path.join(builddir, "lib", "%{cfg.buildcfg}_%{cfg.platform}");
58+
if _ACTION ~= "netcore" then
59+
objsdir = path.join(builddir, "obj", "%{cfg.buildcfg}_%{cfg.platform}");
60+
libdir = path.join(builddir, "lib", "%{cfg.buildcfg}_%{cfg.platform}");
61+
else
62+
objsdir = path.join(builddir, "obj", "%{cfg.buildcfg}");
63+
libdir = path.join(builddir, "lib", "%{cfg.buildcfg}");
64+
end
65+
5566
gendir = path.join(builddir, "gen");
5667

5768
msvc_buildflags = { "/wd4267" }
@@ -121,11 +132,14 @@ function SetupManagedProject()
121132
dotnetframework "4.6"
122133

123134
if not os.istarget("macosx") then
124-
filter { "action:vs*" }
135+
filter { "action:vs* or netcore" }
125136
location "."
126137
filter {}
127138
end
128139

140+
filter { "action:netcore" }
141+
dotnetframework "netstandard2.0"
142+
129143
filter { "action:vs2013" }
130144
dotnetframework "4.5"
131145

@@ -196,4 +210,16 @@ function UseCxx11ABI()
196210
return true
197211
end
198212
return false
199-
end
213+
end
214+
215+
function EnableNativeProjects()
216+
if _ACTION == "netcore" then
217+
return false
218+
end
219+
220+
if string.starts(_ACTION, "vs") and not os.ishost("windows") then
221+
return false
222+
end
223+
224+
return true
225+
end

build/Tests.lua

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function SetupTestGeneratorProject(name, depends)
5555
dependson { name .. ".Native" }
5656

5757
linktable = {
58-
"System",
59-
"System.Core",
6058
"CppSharp",
6159
"CppSharp.AST",
6260
"CppSharp.Generator",
@@ -71,6 +69,16 @@ function SetupTestGeneratorProject(name, depends)
7169
links(linktable)
7270

7371
SetupParser()
72+
73+
filter { "action:netcore" }
74+
dotnetframework "netcoreapp2.0"
75+
76+
filter { "action:not netcore" }
77+
links
78+
{
79+
"System",
80+
"System.Core"
81+
}
7482
end
7583

7684
local function get_mono_exe()
@@ -82,6 +90,9 @@ local function get_mono_exe()
8290
end
8391

8492
function SetupTestGeneratorBuildEvent(name)
93+
if _ACTION == "netcore" then
94+
return
95+
end
8596
local monoExe = get_mono_exe()
8697
local runtimeExe = os.ishost("windows") and "" or monoExe .. " --debug "
8798
if string.starts(action, "vs") then
@@ -94,7 +105,7 @@ function SetupTestGeneratorBuildEvent(name)
94105
end
95106

96107
function SetupTestNativeProject(name, depends)
97-
if string.starts(action, "vs") and not os.ishost("windows") then
108+
if not EnableNativeProjects() then
98109
return
99110
end
100111

@@ -114,17 +125,29 @@ function SetupTestNativeProject(name, depends)
114125
end
115126

116127
function LinkNUnit()
117-
libdirs
118-
{
119-
depsdir .. "/NUnit",
120-
depsdir .. "/NSubstitute"
121-
}
128+
local c = filter()
129+
130+
filter { "action:not netcore"}
131+
libdirs
132+
{
133+
depsdir .. "/NUnit",
134+
depsdir .. "/NSubstitute"
135+
}
122136

123-
links
124-
{
125-
"nunit.framework",
126-
"NSubstitute"
127-
}
137+
links
138+
{
139+
"nunit.framework",
140+
"NSubstitute"
141+
}
142+
143+
filter { "action:netcore"}
144+
nuget
145+
{
146+
"NUnit:3.11.0",
147+
"NSubstitute:4.0.0-rc1"
148+
}
149+
150+
filter(c)
128151
end
129152

130153
function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
@@ -170,7 +193,7 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
170193
end
171194

172195
function SetupTestProjectsCLI(name, extraFiles, suffix)
173-
if not os.ishost("windows") then
196+
if (not os.ishost("windows")) or (_ACTION == "netcore") then
174197
return
175198
end
176199

src/AST/premake5.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ project "CppSharp.AST"
88
files { "*.cs" }
99
vpaths { ["*"] = "*" }
1010

11-
links { "System", "System.Core" }
11+
filter { "action:not netcore"}
12+
links { "System", "System.Core" }

src/CLI/premake5.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ project "CppSharp.CLI"
1010

1111
links
1212
{
13-
"System",
14-
"System.Core",
1513
"CppSharp",
1614
"CppSharp.AST",
1715
"CppSharp.Generator",
1816
"CppSharp.Parser"
1917
}
2018

2119
SetupParser()
20+
21+
filter { "action:not netcore"}
22+
links
23+
{
24+
"System",
25+
"System.Core"
26+
}
27+
28+
filter { "action:netcore" }
29+
dotnetframework "netcoreapp2.0"

src/Core/premake5.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ project "CppSharp"
1111

1212
links
1313
{
14-
"System",
15-
"System.Core",
1614
depsdir .. "/vs2017/Microsoft.VisualStudio.Setup.Configuration.Interop"
1715
}
16+
17+
filter { "action:netcore" }
18+
nuget { "Microsoft.Win32.Registry:4.5.0" }
19+
20+
filter { "action:not netcore"}
21+
links { "System", "System.Core" }

src/CppParser/Bindings/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include ("CSharp")
22

3-
if string.starts(action, "vs") and os.ishost("windows") then
3+
if EnableNativeProjects() and os.ishost("windows") then
44

55
include ("CLI")
66

src/CppParser/ParserGen/premake5.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ project "CppSharp.Parser.Gen"
1414
"CppSharp.AST",
1515
"CppSharp.Generator",
1616
"CppSharp.Parser",
17-
"System.Core"
1817
}
1918

20-
SetupParser()
19+
SetupParser()
20+
21+
filter { "action:not netcore"}
22+
links { "System.Core" }

src/CppParser/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ clang_msvc_flags =
66
"/wd4141", -- 'inline' : used more than once
77
}
88

9-
if not (string.starts(action, "vs") and not os.ishost("windows")) then
9+
if EnableNativeProjects() then
1010

1111
project "CppSharp.CppParser"
1212

src/Generator.Tests/premake5.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,25 @@ project "CppSharp.Generator.Tests"
2121

2222
links
2323
{
24-
"System",
25-
"System.Core",
2624
"CppSharp",
2725
"CppSharp.AST",
2826
"CppSharp.Generator",
2927
"CppSharp.Parser",
30-
"nunit.framework",
31-
"NSubstitute"
3228
}
29+
30+
filter { "action:netcore"}
31+
nuget
32+
{
33+
"NUnit:3.11.0",
34+
"NSubstitute:4.0.0-rc1"
35+
}
36+
37+
filter { "action:not netcore"}
38+
links
39+
{
40+
"System",
41+
"System.Core",
42+
"Microsoft.CSharp",
43+
"nunit.framework",
44+
"NSubstitute"
45+
}

src/Generator/premake5.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,28 @@ project "CppSharp.Generator"
1313

1414
links
1515
{
16-
"System",
17-
"System.Core",
18-
"Microsoft.CSharp",
1916
"CppSharp",
2017
"CppSharp.AST",
2118
"CppSharp.Parser"
2219
}
2320

2421
SetupParser()
2522

23+
filter { "action:netcore"}
24+
nuget
25+
{
26+
"System.CodeDom:4.5.0",
27+
"Microsoft.CSharp:4.5.0"
28+
}
29+
30+
filter { "action:not netcore"}
31+
links
32+
{
33+
"System",
34+
"System.Core",
35+
"Microsoft.CSharp"
36+
}
37+
2638
filter { 'files:**verbs.txt' }
2739
buildaction "Embed"
2840

src/Parser/premake5.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ project "CppSharp.Parser"
3636

3737
links
3838
{
39-
"System",
40-
"System.Core",
4139
"CppSharp",
4240
"CppSharp.AST",
4341
"CppSharp.Runtime"
4442
}
4543

4644
SetupParser()
45+
46+
filter { "action:not netcore"}
47+
links { "System", "System.Core" }

src/Runtime/premake5.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ project "CppSharp.Runtime"
88
files { "**.cs" }
99
vpaths { ["*"] = "*" }
1010

11-
links { "System" }
11+
filter { "action:not netcore"}
12+
links { "System" }
1213

1314
filter { "action:vs*" }
1415
defines { "MSVC" }

0 commit comments

Comments
 (0)