-
Notifications
You must be signed in to change notification settings - Fork 111
/
Program.cs
885 lines (742 loc) · 31.3 KB
/
Program.cs
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
/*
Copyright 2014-2022 SourceGear, LLC
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.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
public enum TFM
{
NONE,
UWP,
NETSTANDARD20,
NET461,
NET60,
NET70,
MACCATALYST,
XAMARINMAC20,
}
public static class common
{
public const string ROOT_NAME = "SQLitePCLRaw";
public static string AsString(this TFM e)
{
switch (e)
{
case TFM.NONE: throw new Exception("TFM.NONE.AsString()");
case TFM.UWP: return "uap10.0";
case TFM.NETSTANDARD20: return "netstandard2.0";
case TFM.NET461: return "net461";
case TFM.NET60: return "net6.0";
case TFM.NET70: return "net7.0";
case TFM.MACCATALYST: return "net6.0-maccatalyst15.2";
case TFM.XAMARINMAC20: return "xamarin.mac20";
default:
throw new NotImplementedException(string.Format("TFM.AsString for {0}", e));
}
}
public static void write_nuspec_file_entry(string src, string target, XmlWriter f)
{
f.WriteStartElement("file");
f.WriteAttributeString("src", src);
f.WriteAttributeString("target", target);
f.WriteEndElement(); // file
}
public static void write_empty(XmlWriter f, TFM tfm)
{
f.WriteComment("empty directory in lib to avoid nuget adding a reference");
f.WriteStartElement("file");
f.WriteAttributeString("src", "_._");
f.WriteAttributeString("target", string.Format("lib/{0}/_._", tfm.AsString()));
f.WriteEndElement(); // file
}
const string PACKAGE_TAGS = "sqlite;xamarin";
public static void write_nuspec_common_metadata(
string id,
XmlWriter f
)
{
f.WriteAttributeString("minClientVersion", "2.12"); // TODO not sure this is right
f.WriteElementString("id", id);
f.WriteElementString("title", id);
f.WriteElementString("version", "$version$");
f.WriteElementString("authors", "$authors$");
f.WriteElementString("copyright", "$copyright$");
f.WriteElementString("requireLicenseAcceptance", "false");
write_license(f);
f.WriteStartElement("repository");
f.WriteAttributeString("type", "git");
f.WriteAttributeString("url", "https://github.com/ericsink/SQLitePCL.raw");
f.WriteEndElement(); // repository
f.WriteElementString("summary", "$summary$");
f.WriteElementString("tags", PACKAGE_TAGS);
}
public static XmlWriterSettings XmlWriterSettings_default()
{
var settings = new XmlWriterSettings();
settings.NewLineChars = "\n";
settings.Indent = true;
return settings;
}
public static void gen_dummy_csproj(string dir_proj, string id)
{
var settings = XmlWriterSettings_default();
settings.OmitXmlDeclaration = true;
using (XmlWriter f = XmlWriter.Create(Path.Combine(dir_proj, $"{id}.csproj"), settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project");
f.WriteAttributeString("Sdk", "Microsoft.NET.Sdk");
f.WriteStartElement("PropertyGroup");
f.WriteElementString("TargetFramework", "netstandard2.0");
f.WriteElementString("NoBuild", "true");
f.WriteElementString("IncludeBuildOutput", "false");
f.WriteElementString("NuspecFile", $"{id}.nuspec");
f.WriteElementString("NuspecProperties", "version=$(version);src_path=$(src_path);cb_bin_path=$(cb_bin_path);authors=$(Authors);copyright=$(Copyright);summary=$(Description)");
f.WriteEndElement(); // PropertyGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
private static void write_license(XmlWriter f)
{
f.WriteStartElement("license");
f.WriteAttributeString("type", "expression");
f.WriteString("Apache-2.0");
f.WriteEndElement();
}
}
public static class gen
{
enum LibSuffix
{
DLL,
DYLIB,
SO,
A,
}
// in cb, the sqlcipher builds do not have the e_ prefix.
// we do this so we can continue to build v1.
// but in v2, we want things to be called e_sqlcipher.
static string AsString_basename_in_cb(this WhichLib e)
{
switch (e)
{
case WhichLib.E_SQLITE3: return "e_sqlite3";
case WhichLib.E_SQLCIPHER: return "e_sqlcipher"; // TODO no e_ prefix in cb yet
default:
throw new NotImplementedException(string.Format("WhichLib.AsString for {0}", e));
}
}
static string AsString_basename_in_nupkg(this WhichLib e)
{
switch (e)
{
case WhichLib.E_SQLITE3: return "e_sqlite3";
case WhichLib.E_SQLCIPHER: return "e_sqlcipher";
default:
throw new NotImplementedException(string.Format("WhichLib.AsString for {0}", e));
}
}
static string basename_to_libname(string basename, LibSuffix suffix)
{
switch (suffix)
{
case LibSuffix.DLL:
return $"{basename}.dll";
case LibSuffix.DYLIB:
return $"lib{basename}.dylib";
case LibSuffix.SO:
return $"lib{basename}.so";
case LibSuffix.A:
return $"{basename}.a";
default:
throw new NotImplementedException();
}
}
static string AsString_libname_in_nupkg(this WhichLib e, LibSuffix suffix)
{
var basename = e.AsString_basename_in_nupkg();
return basename_to_libname(basename, suffix);
}
static string AsString_libname_in_cb(this WhichLib e, LibSuffix suffix)
{
var basename = e.AsString_basename_in_cb();
return basename_to_libname(basename, suffix);
}
private static void write_nuspec_file_entry_native(string src, string rid, string filename, XmlWriter f)
{
common.write_nuspec_file_entry(
src,
string.Format("runtimes\\{0}\\native\\{1}", rid, filename),
f
);
}
private static void write_nuspec_file_entry_nativeassets(string src, string rid, TFM tfm, string filename, XmlWriter f)
{
common.write_nuspec_file_entry(
src,
string.Format("runtimes\\{0}\\nativeassets\\{1}\\{2}", rid, tfm.AsString(), filename),
f
);
}
static string make_cb_path_win(
WhichLib lib,
string toolset,
string flavor,
string arch
)
{
var dir_name = lib.AsString_basename_in_cb();
var lib_name = lib.AsString_libname_in_cb(LibSuffix.DLL);
return nuget_path_combine("$cb_bin_path$", dir_name, "win", toolset, flavor, arch, lib_name);
}
static string make_cb_path_linux(
WhichLib lib,
string cpu
)
{
var dir_name = lib.AsString_basename_in_cb();
var lib_name = lib.AsString_libname_in_cb(LibSuffix.SO);
return nuget_path_combine("$cb_bin_path$", dir_name, "linux", cpu, lib_name);
}
static string make_cb_path_wasm(
WhichLib lib,
TFM tfm
)
{
var dir_name = lib.AsString_basename_in_cb();
var lib_name = lib.AsString_libname_in_cb(LibSuffix.A);
return nuget_path_combine("$cb_bin_path$", dir_name, "wasm", tfm.AsString(), lib_name);
}
static string make_cb_path_mac(
WhichLib lib,
string cpu
)
{
var dir_name = lib.AsString_basename_in_cb();
var lib_name = lib.AsString_libname_in_cb(LibSuffix.DYLIB);
return nuget_path_combine("$cb_bin_path$", dir_name, "mac", cpu, lib_name);
}
static string make_cb_path_maccatalyst(
WhichLib lib,
string cpu
)
{
var dir_name = lib.AsString_basename_in_cb();
var lib_name = lib.AsString_libname_in_cb(LibSuffix.DYLIB);
return nuget_path_combine("$cb_bin_path$", dir_name, "maccatalyst", cpu, lib_name);
}
static void write_nuspec_file_entry_native_linux(
WhichLib lib,
string cpu_in_cb,
string rid,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.SO);
write_nuspec_file_entry_native(
make_cb_path_linux(lib, cpu_in_cb),
rid,
filename,
f
);
}
static void write_nuspec_file_entry_native_wasm(
WhichLib lib,
TFM tfm,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.A);
write_nuspec_file_entry_nativeassets(
make_cb_path_wasm(lib, tfm),
"browser-wasm",
tfm,
filename,
f
);
}
static void write_nuspec_file_entry_native_mac(
WhichLib lib,
string cpu_in_cb,
string rid,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB);
write_nuspec_file_entry_native(
make_cb_path_mac(lib, cpu_in_cb),
rid,
filename,
f
);
}
static void write_nuspec_file_entry_native_maccatalyst(
WhichLib lib,
string cpu_in_cb,
string rid,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB);
write_nuspec_file_entry_native(
make_cb_path_maccatalyst(lib, cpu_in_cb),
rid,
filename,
f
);
}
static void write_nuspec_file_entry_native_win(
WhichLib lib,
string toolset,
string flavor,
string cpu,
string rid,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DLL);
write_nuspec_file_entry_native(
make_cb_path_win(lib, toolset, flavor, cpu),
rid,
filename,
f
);
}
static void write_nuspec_file_entry_native_uwp(
WhichLib lib,
string toolset,
string flavor,
string cpu,
string rid,
XmlWriter f
)
{
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DLL);
write_nuspec_file_entry_nativeassets(
make_cb_path_win(lib, toolset, flavor, cpu),
rid,
TFM.UWP,
filename,
f
);
}
static void write_nuspec_file_entries_from_cb(
WhichLib lib,
string win_toolset,
XmlWriter f
)
{
write_nuspec_file_entry_native_win(lib, win_toolset, "plain", "x86", "win-x86", f);
write_nuspec_file_entry_native_win(lib, win_toolset, "plain", "x64", "win-x64", f);
write_nuspec_file_entry_native_win(lib, win_toolset, "plain", "arm", "win-arm", f);
write_nuspec_file_entry_native_win(lib, win_toolset, "plain", "arm64", "win-arm64", f);
write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "arm64", "win10-arm64", f);
write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "arm", "win10-arm", f);
write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "x64", "win10-x64", f);
write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "x86", "win10-x86", f);
write_nuspec_file_entry_native_mac(lib, "x86_64", "osx-x64", f);
write_nuspec_file_entry_native_mac(lib, "arm64", "osx-arm64", f);
write_nuspec_file_entry_native_maccatalyst(lib, "x86_64", "maccatalyst-x64", f);
write_nuspec_file_entry_native_maccatalyst(lib, "arm64", "maccatalyst-arm64", f);
write_nuspec_file_entry_native_linux(lib, "x64", "linux-x64", f);
write_nuspec_file_entry_native_linux(lib, "x86", "linux-x86", f);
write_nuspec_file_entry_native_linux(lib, "armhf", "linux-arm", f);
write_nuspec_file_entry_native_linux(lib, "armsf", "linux-armel", f);
write_nuspec_file_entry_native_linux(lib, "arm64", "linux-arm64", f);
// TODO seems sad to put two copies of each musl, one for linux-musl- RID and one for alpine- RID
write_nuspec_file_entry_native_linux(lib, "musl-x64", "linux-musl-x64", f);
write_nuspec_file_entry_native_linux(lib, "musl-armhf", "linux-musl-arm", f);
write_nuspec_file_entry_native_linux(lib, "musl-arm64", "linux-musl-arm64", f);
// TODO seems sad to put two copies of each musl, one for linux-musl- RID and one for alpine- RID
write_nuspec_file_entry_native_linux(lib, "musl-x64", "alpine-x64", f);
write_nuspec_file_entry_native_linux(lib, "musl-armhf", "alpine-arm", f);
write_nuspec_file_entry_native_linux(lib, "musl-arm64", "alpine-arm64", f);
write_nuspec_file_entry_native_linux(lib, "mips64", "linux-mips64", f);
write_nuspec_file_entry_native_linux(lib, "s390x", "linux-s390x", f);
write_nuspec_file_entry_native_linux(lib, "ppc64le", "linux-ppc64le", f);
write_nuspec_file_entry_native_wasm(lib, TFM.NET60, f);
write_nuspec_file_entry_native_wasm(lib, TFM.NET70, f);
}
static void write_nuspec_wasm_targets_file_entry(
string dir_src,
string id,
WhichLib lib,
TFM tfm,
XmlWriter f
)
{
var tname = string.Format("{0}.targets", id);
var dir_proj = Path.Combine(dir_src, id);
Directory.CreateDirectory(Path.Combine(dir_proj, tfm.AsString()));
var path_targets = Path.Combine(dir_proj, tfm.AsString(), tname);
var relpath_targets = nuget_path_combine(".", tfm.AsString(), tname);
gen_nuget_targets_wasm(path_targets, tfm, lib);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", tfm.AsString()),
f
);
}
private static void gen_nuspec_lib_e_sqlite3(string dir_src)
{
string id = string.Format("{0}.lib.e_sqlite3", common.ROOT_NAME);
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
var dir_proj = Path.Combine(dir_src, id);
Directory.CreateDirectory(dir_proj);
common.gen_dummy_csproj(dir_proj, id);
using (XmlWriter f = XmlWriter.Create(Path.Combine(dir_proj, string.Format("{0}.nuspec", id)), settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("package", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd");
f.WriteStartElement("metadata");
common.write_nuspec_common_metadata(id, f);
f.WriteElementString("description", "This package contains platform-specific native code builds of SQLite for use with SQLitePCLRaw. To use this, you need SQLitePCLRaw.core as well as one of the SQLitePCLRaw.provider.* packages. Convenience packages are named SQLitePCLRaw.bundle_*.");
f.WriteEndElement(); // metadata
f.WriteStartElement("files");
write_nuspec_file_entries_from_cb(WhichLib.E_SQLITE3, "v142", f);
#if not
{
var tname = string.Format("{0}.props", id);
var path_props = Path.Combine(dir_proj, tname);
var relpath_props = nuget_path_combine(".", tname);
gen_nuget_props(path_props, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_props,
"buildTransitive\\",
f
);
}
#endif
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "net461"));
var path_targets = Path.Combine(dir_proj, "net461", tname);
var relpath_targets = nuget_path_combine(".", "net461", tname);
gen_nuget_targets(path_targets, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.NET461.AsString()),
f
);
}
#if not
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "xamarin.mac20"));
var path_targets = Path.Combine(dir_proj, "xamarin.mac20", tname);
var relpath_targets = nuget_path_combine(".", "xamarin.mac20", tname);
gen_nuget_targets_legacy_xamarin_mac(path_targets, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.XAMARINMAC20.AsString()),
f
);
}
#endif
#if not
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "net6.0-maccatalyst"));
var path_targets = Path.Combine(dir_proj, "net6.0-maccatalyst", tname);
var relpath_targets = nuget_combine(".", "net6.0-maccatalyst", tname);
gen_nuget_targets_maccatalyst(path_targets, WhichLib.E_SQLITE3);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.MACCATALYST.AsString()),
f
);
}
#endif
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.E_SQLITE3, TFM.NET60, f);
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.E_SQLITE3, TFM.NET70, f);
// TODO need a comment here to explain these
common.write_empty(f, TFM.NET461);
common.write_empty(f, TFM.NETSTANDARD20);
#if not
common.write_empty(f, TFM.XAMARINMAC20);
#endif
f.WriteEndElement(); // files
f.WriteEndElement(); // package
f.WriteEndDocument();
}
}
private static void gen_nuspec_lib_e_sqlcipher(string dir_src)
{
string id = string.Format("{0}.lib.e_sqlcipher", common.ROOT_NAME);
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
var dir_proj = Path.Combine(dir_src, id);
Directory.CreateDirectory(dir_proj);
common.gen_dummy_csproj(dir_proj, id);
using (XmlWriter f = XmlWriter.Create(Path.Combine(dir_proj, string.Format("{0}.nuspec", id)), settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("package", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd");
f.WriteStartElement("metadata");
common.write_nuspec_common_metadata(id, f);
f.WriteElementString("description", "This package contains platform-specific native code builds of SQLCipher (see sqlcipher/sqlcipher on GitHub) for use with SQLitePCLRaw. Note that these sqlcipher builds are unofficial and unsupported. For official sqlcipher builds, contact Zetetic. To use this package, you need SQLitePCLRaw.core as well as one of the SQLitePCLRaw.provider.* packages. Convenience packages are named SQLitePCLRaw.bundle_*.");
f.WriteEndElement(); // metadata
f.WriteStartElement("files");
write_nuspec_file_entries_from_cb(WhichLib.E_SQLCIPHER, "v142", f);
{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "net461"));
var path_targets = Path.Combine(dir_proj, "net461", tname);
var relpath_targets = nuget_path_combine(".", "net461", tname);
gen_nuget_targets(path_targets, WhichLib.E_SQLCIPHER);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.NET461.AsString()),
f
);
}
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.E_SQLCIPHER, TFM.NET60, f);
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.E_SQLCIPHER, TFM.NET70, f);
// TODO need a comment here to explain these
common.write_empty(f, TFM.NET461);
common.write_empty(f, TFM.NETSTANDARD20);
f.WriteEndElement(); // files
f.WriteEndElement(); // package
f.WriteEndDocument();
}
}
enum WhichLib
{
NONE,
E_SQLITE3,
E_SQLCIPHER,
}
static LibSuffix get_lib_suffix_from_rid(string rid)
{
var parts = rid.Split('-');
var front = parts[0].ToLower();
if (front.StartsWith("win"))
{
return LibSuffix.DLL;
}
else if (front.StartsWith("osx"))
{
return LibSuffix.DYLIB;
}
else if (
front.StartsWith("linux")
|| front.StartsWith("alpine")
)
{
return LibSuffix.SO;
}
else
{
throw new NotImplementedException();
}
}
static void write_nuget_target_item(
string rid,
WhichLib lib,
XmlWriter f
)
{
var suffix = get_lib_suffix_from_rid(rid);
var filename = lib.AsString_libname_in_nupkg(suffix);
f.WriteStartElement("Content");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\{0}\\native\\{1}", rid, filename));
f.WriteElementString("Link", string.Format("runtimes\\{0}\\native\\{1}", rid, filename));
f.WriteElementString("CopyToOutputDirectory", "PreserveNewest");
f.WriteElementString("Pack", "false");
f.WriteEndElement(); // Content
}
#if not
static void write_nuget_prop_item(
string rid,
WhichLib lib,
XmlWriter f
)
{
var suffix = get_lib_suffix_from_rid(rid);
var filename = lib.AsString_libname_in_nupkg(suffix);
var rid_idsafe = rid.Replace("-", "_");
var prop_name = $"path__{lib.AsString_basename_in_nupkg()}__{rid_idsafe}";
f.WriteElementString(prop_name, string.Format("$(MSBuildThisFileDirectory)..\\runtimes\\{0}\\native\\{1}", rid, filename));
}
private static void gen_nuget_props(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");
f.WriteStartElement("PropertyGroup");
write_nuget_prop_item("win-x86", lib, f);
write_nuget_prop_item("win-x64", lib, f);
write_nuget_prop_item("win-arm", lib, f);
write_nuget_prop_item("osx-x64", lib, f);
write_nuget_prop_item("osx-arm64", lib, f);
write_nuget_prop_item("linux-x86", lib, f);
write_nuget_prop_item("linux-x64", lib, f);
write_nuget_prop_item("linux-arm", lib, f);
write_nuget_prop_item("linux-armel", lib, f);
write_nuget_prop_item("linux-arm64", lib, f);
write_nuget_prop_item("linux-x64", lib, f);
write_nuget_prop_item("linux-mips64", lib, f);
write_nuget_prop_item("linux-s390x", lib, f);
write_nuget_prop_item("linux-ppc64le", lib, f);
f.WriteEndElement(); // PropertyGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
#endif
private static void gen_nuget_targets(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
// TODO these targets appear to be for old situations where RuntimeIdentifier
// was not set, like desktop mono, pre-net6 days
using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == '' AND '$(OS)' == 'Windows_NT' ");
write_nuget_target_item("win-x86", lib, f);
write_nuget_target_item("win-x64", lib, f);
write_nuget_target_item("win-arm", lib, f);
f.WriteEndElement(); // ItemGroup
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == '' AND '$(OS)' == 'Unix' AND Exists('/Library/Frameworks') ");
// TODO in what case does this make sense?
write_nuget_target_item("osx-x64", lib, f);
f.WriteEndElement(); // ItemGroup
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == '' AND '$(OS)' == 'Unix' AND !Exists('/Library/Frameworks') ");
write_nuget_target_item("linux-x86", lib, f);
write_nuget_target_item("linux-x64", lib, f);
write_nuget_target_item("linux-arm", lib, f);
write_nuget_target_item("linux-armel", lib, f);
write_nuget_target_item("linux-arm64", lib, f);
write_nuget_target_item("linux-x64", lib, f);
write_nuget_target_item("linux-mips64", lib, f);
write_nuget_target_item("linux-s390x", lib, f);
f.WriteEndElement(); // ItemGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
#if not
private static void gen_nuget_targets_legacy_xamarin_mac(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB);
// --------
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'osx-x64' ");
f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\osx-x64\\native\\{0}", filename));
f.WriteElementString("Kind", "Dynamic");
f.WriteElementString("SmartLink", "False");
f.WriteEndElement(); // NativeFileReference
f.WriteEndElement(); // ItemGroup
// --------
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'osx-arm64' ");
f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\osx-arm64\\native\\{0}", filename));
f.WriteElementString("Kind", "Dynamic");
f.WriteElementString("SmartLink", "False");
f.WriteEndElement(); // NativeFileReference
f.WriteEndElement(); // ItemGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
#endif
private static void gen_nuget_targets_wasm(string dest, TFM tfm, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'browser-wasm' ");
var filename = lib.AsString_libname_in_nupkg(LibSuffix.A);
f.WriteStartElement("NativeFileReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\browser-wasm\\nativeassets\\{0}\\{1}", tfm.AsString(), filename));
f.WriteEndElement(); // NativeFileReference
f.WriteEndElement(); // ItemGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
private static string nuget_path_combine(params string[] paths)
{
return Path.Combine(paths).Replace('/', '\\');
}
#if not
private static void gen_nuget_targets_maccatalyst(string dest, WhichLib lib)
{
var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;
using (XmlWriter f = XmlWriter.Create(dest, settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");
f.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
f.WriteAttributeString("ToolsVersion", "4.0");
var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB);
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'maccatalyst-x64' ");
f.WriteStartElement("NativeReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\maccatalyst-x64\\nativeassets\\net6.0\\{0}", filename));
f.WriteEndElement(); // Content
f.WriteEndElement(); // ItemGroup
f.WriteStartElement("ItemGroup");
f.WriteAttributeString("Condition", " '$(RuntimeIdentifier)' == 'maccatalyst-arm64' ");
f.WriteStartElement("NativeReference");
f.WriteAttributeString("Include", string.Format("$(MSBuildThisFileDirectory)..\\..\\runtimes\\maccatalyst-arm64\\nativeassets\\net6.0\\{0}", filename));
f.WriteEndElement(); // Content
f.WriteEndElement(); // ItemGroup
f.WriteEndElement(); // Project
f.WriteEndDocument();
}
}
#endif
public static void Main(string[] args)
{
string dir_root = Path.GetFullPath(args[0]);
var dir_src = Path.Combine(dir_root, "src");
gen_nuspec_lib_e_sqlite3(dir_src);
gen_nuspec_lib_e_sqlcipher(dir_src);
}
}