-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
232 lines (216 loc) · 7.13 KB
/
build.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#tool nuget:?package=GitVersion.CommandLine&version=4.0.0
#addin nuget:?package=Cake.CMake&version=0.2.2
#addin nuget:?package=Cake.Incubator&version=4.0.2
var target = Argument("target", "Default");
// Used for copyright and ownership information.
public const string CrispGroupName = "Crisp Thinking Group Ltd.";
public class Settings
{
public string DylibExt {get; set;}
public string Rid {get; set;}
public string DylibPrefix {get; set;}
};
public void Check(int exitCode)
{
if (exitCode != 0)
throw new Exception($"Process returned non-zero exit code '{exitCode}'");
}
// Cached settings for the current platform
Setup<Settings>(context =>
{
switch (context.Environment.Platform.Family)
{
case PlatformFamily.Linux:
return new Settings {
DylibExt = "so",
DylibPrefix = "lib",
Rid = "linux-x64",
};
case PlatformFamily.OSX:
return new Settings {
DylibExt = "dylib",
DylibPrefix = "lib",
Rid = "osx-x64",
};
case PlatformFamily.Windows:
return new Settings {
DylibExt = "dll",
DylibPrefix = string.Empty,
Rid = "win-x64",
};
default:
throw new Exception("Unknown platform!");
}
});
// Build the RE2 library
Task("BuildRe2")
.Does(() =>
{
if (Context.Environment.Platform.IsUnix())
{
var args = new ProcessArgumentBuilder()
.Append("obj/libre2.a")
.Append($"-j{Environment.ProcessorCount * 2}");
Check(StartProcess("make", new ProcessSettings {
Arguments = args,
WorkingDirectory = Directory("thirdparty/re2/"),
EnvironmentVariables = new Dictionary<string, string> {
["CXXFLAGS"] = "-fPIC -O3 -g",
}
}));
}
else
{
CreateDirectory("bin/re2/");
CMake("thirdparty/re2/", new CMakeSettings {
OutputPath = "bin/re2/",
Options = new [] { "-DBUILD_TESTING=OFF", "-DBUILD_SHARED_LIBS=OFF", "-DRE2_BUILD_TESTING=OFF", "-DCMAKE_GENERATOR_PLATFORM=x64" },
});
MSBuild("bin/re2/RE2.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
Configuration = "Release",
});
}
});
// Build the C FFI interface and link in RE2 statically
Task("BuildCre2")
.IsDependentOn("BuildRe2")
.Does<Settings>(s =>
{
var outFile = MakeAbsolute(File($"bin/contents/runtimes/{s.Rid}/native/{s.DylibPrefix}cre2.{s.DylibExt}"));
CreateDirectory(outFile.GetDirectory());
// For this build we just shell out to the platform's C++ compiler
if (Context.Environment.Platform.IsUnix())
{
Information("Building with Clang++");
Information(outFile);
// To compile CRE2 we shell out to `clang++` directly. It's only a single
// C++ file. We statically link in the RE2 build we produced earlier in
// the `BuildRe2` task.
var args = new ProcessArgumentBuilder()
.Append("--verbose")
// we're building a shared library
.Append("-shared")
.Append("-fpic")
// Uses C++ 11
.Append("-std=c++11")
// Release build please
.Append("-O3")
.Append("-g")
.Append("-DNDEBUG")
// Need to define the version number for the library
.Append("-Dcre2_VERSION_INTERFACE_CURRENT=0")
.Append("-Dcre2_VERSION_INTERFACE_REVISION=0")
.Append("-Dcre2_VERSION_INTERFACE_AGE=0")
.Append("-Dcre2_VERSION_INTERFACE_STRING=\\\"0.0.0\\\"")
// sources and static libraries to link in
.Append("-I../re2/")
.Append("src/cre2.cpp")
.Append("../re2/obj/libre2.a")
// output to our `bin/` folder
.Append($"-o{outFile}");
Check(StartProcess("clang++", new ProcessSettings {
Arguments = args,
WorkingDirectory = Directory("thirdparty/cre2/"),
}));
}
else
{
var args = new ProcessArgumentBuilder()
// C++ 14 dynamic library with exceptions
.Append("/EHsc")
.Append("/std:c++14")
.Append("/LD")
.Append("/MD")
// Release build
.Append("/O2")
.Append("/DNDEBUG")
// Need to define the version number for the library
.Append("/Dcre2_VERSION_INTERFACE_CURRENT=0")
.Append("/Dcre2_VERSION_INTERFACE_REVISION=0")
.Append("/Dcre2_VERSION_INTERFACE_AGE=0")
.Append("/Dcre2_VERSION_INTERFACE_STRING=\\\"0.0.0\\\"")
// Export the symbols from the DLL
.Append("/Dcre2_decl=__declspec(dllexport)")
// sources to use and location of object files
.Append("/I../re2/")
.Append("src/cre2.cpp")
.Append("/Fo.\\..\\..\\bin")
// Linker options. Include the RE2 static library and set the output
.Append("/link")
.Append("../../bin/re2/Release/re2.lib")
.Append($"/out:{outFile}");
Check(StartProcess("cl", new ProcessSettings {
Arguments = args,
WorkingDirectory = Directory("thirdparty/cre2/"),
}));
}
});
// Create the NuGet battery pack package for this platform
Task("Pack")
.IsDependentOn("BuildCre2")
.Does(() =>
{
CreateDirectory("bin/artifacts/");
var versionInfo = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfo = false,
NoFetch = true,
});
var contentsPath = MakeAbsolute(Directory("bin/contents")).ToString();
var contentFiles = GetFiles(contentsPath + "/**/*.*")
.Select(file => new NuSpecContent {
Source = file.FullPath,
Target = file.FullPath
.Replace(contentsPath, "")
.TrimStart(new [] { '\\', '/' })
})
.ToArray();
foreach (var file in contentFiles)
{
Information("including {0}", file.Dump());
}
NuGetPack(new NuGetPackSettings {
Id = $"IronRe2-Batteries.{Context.Environment.Platform.Family}",
Version = versionInfo.NuGetVersionV2,
Title = "IronRe2 Batteries",
Authors = new[] { CrispGroupName },
Owners = new[] { CrispGroupName },
Description = "platform-specific Nu-Get package containing RE2 and the cre2 wrapper",
Summary = "Native code dependency of IronRe2",
ProjectUrl = new Uri("https://github.com/crispthinking/IronRe2-Batteries/"),
LicenseUrl = new Uri("https://github.com/crispthinking/IronRe2-Batteries/blob/master/LICENSE"),
Copyright = $"{CrispGroupName} 2019",
Tags = new [] {"Regex", "Re2"},
Dependencies = new [] {
new NuSpecDependency {
Id = "NETStandard.Library",
Version = "1.6.1",
TargetFramework = ".NETStandard1.0",
}
},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = contentFiles,
BasePath = "./",
OutputDirectory = "bin/artifacts/",
});
});
// Remove the build artifacts and clean the thirdparty repos
Task("Clean")
.Does(() =>
{
DeleteDirectory("bin/", new DeleteDirectorySettings {
Recursive = true,
Force = true
});
StartProcess("make", new ProcessSettings {
Arguments = "clean",
WorkingDirectory = Directory("thirdparty/re2/"),
});
});
// Phony target to trigger all the things we _usually_ want done.
Task("Default")
.IsDependentOn("Pack");
RunTarget(target);