-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathgenerate_nuspec_for_native_nuget.py
1150 lines (1020 loc) · 47.4 KB
/
generate_nuspec_for_native_nuget.py
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
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import argparse
import os
import re
import sys
from pathlib import Path
# What does the names of our C API tarball/zip files looks like
# os: win, linux, osx
# ep: cuda, tensorrt, None
def get_package_name(os, cpu_arch, ep, is_training_package):
pkg_name = "onnxruntime-training" if is_training_package else "onnxruntime"
if os == "win":
pkg_name += "-win-"
pkg_name += cpu_arch
if ep == "cuda":
pkg_name += "-cuda"
elif ep == "tensorrt":
pkg_name += "-tensorrt"
elif ep == "rocm":
pkg_name += "-rocm"
elif os == "linux":
pkg_name += "-linux-"
pkg_name += cpu_arch
if ep == "cuda":
pkg_name += "-cuda"
elif ep == "tensorrt":
pkg_name += "-tensorrt"
elif ep == "rocm":
pkg_name += "-rocm"
elif os == "osx":
pkg_name = "onnxruntime-osx-" + cpu_arch
return pkg_name
# Currently we take onnxruntime_providers_cuda from CUDA build
# And onnxruntime, onnxruntime_providers_shared and
# onnxruntime_providers_tensorrt from tensorrt build
# cuda binaries are split out into the platform dependent packages Microsoft.ML.OnnxRuntime.{Linux|Windows}
# and not included in the base Microsoft.ML.OnnxRuntime.Gpu package
def is_this_file_needed(ep, filename, package_name):
if package_name == "Microsoft.ML.OnnxRuntime.Gpu":
return False
return (ep != "cuda" or "cuda" in filename) and (ep != "tensorrt" or "cuda" not in filename)
# nuget_artifacts_dir: the directory with uncompressed C API tarball/zip files
# ep: cuda, tensorrt, None
# files_list: a list of xml string pieces to append
# This function has no return value. It updates files_list directly
def generate_file_list_for_ep(nuget_artifacts_dir, ep, files_list, include_pdbs, is_training_package, package_name):
for child in nuget_artifacts_dir.iterdir():
if not child.is_dir():
continue
for cpu_arch in ["x86", "x64", "arm", "arm64"]:
if child.name == get_package_name("win", cpu_arch, ep, is_training_package):
child = child / "lib" # noqa: PLW2901
for child_file in child.iterdir():
suffixes = [".dll", ".lib", ".pdb"] if include_pdbs else [".dll", ".lib"]
if (
child_file.suffix in suffixes
and is_this_file_needed(ep, child_file.name, package_name)
and package_name != "Microsoft.ML.OnnxRuntime.Gpu.Linux"
):
files_list.append(
'<file src="' + str(child_file) + f'" target="runtimes/win-{cpu_arch}/native"/>'
)
for cpu_arch in ["x86_64", "arm64"]:
if child.name == get_package_name("osx", cpu_arch, ep, is_training_package):
child = child / "lib" # noqa: PLW2901
if cpu_arch == "x86_64":
cpu_arch = "x64" # noqa: PLW2901
for child_file in child.iterdir():
# Check if the file has digits like onnxruntime.1.8.0.dylib. We can skip such things
is_versioned_dylib = re.match(r".*[\.\d+]+\.dylib$", child_file.name)
if child_file.is_file() and child_file.suffix == ".dylib" and not is_versioned_dylib:
files_list.append(
'<file src="' + str(child_file) + f'" target="runtimes/osx-{cpu_arch}/native"/>'
)
for cpu_arch in ["x64", "aarch64"]:
if child.name == get_package_name("linux", cpu_arch, ep, is_training_package):
child = child / "lib" # noqa: PLW2901
if cpu_arch == "x86_64":
cpu_arch = "x64" # noqa: PLW2901
elif cpu_arch == "aarch64":
cpu_arch = "arm64" # noqa: PLW2901
for child_file in child.iterdir():
if not child_file.is_file():
continue
if (
child_file.suffix == ".so"
and is_this_file_needed(ep, child_file.name, package_name)
and package_name != "Microsoft.ML.OnnxRuntime.Gpu.Windows"
):
files_list.append(
'<file src="' + str(child_file) + f'" target="runtimes/linux-{cpu_arch}/native"/>'
)
if child.name == "onnxruntime-android" or child.name == "onnxruntime-training-android":
for child_file in child.iterdir():
if child_file.suffix in [".aar"]:
files_list.append('<file src="' + str(child_file) + '" target="runtimes/android/native"/>')
if child.name == "onnxruntime-ios":
for child_file in child.iterdir():
if child_file.suffix in [".zip"]:
files_list.append('<file src="' + str(child_file) + '" target="runtimes/ios/native"/>')
def parse_arguments():
parser = argparse.ArgumentParser(
description="ONNX Runtime create nuget spec script (for hosting native shared library artifacts)",
usage="",
)
# Main arguments
parser.add_argument("--package_name", required=True, help="ORT package name. Eg: Microsoft.ML.OnnxRuntime.Gpu")
parser.add_argument("--package_version", required=True, help="ORT package version. Eg: 1.0.0")
parser.add_argument("--target_architecture", required=True, help="Eg: x64")
parser.add_argument("--build_config", required=True, help="Eg: RelWithDebInfo")
parser.add_argument("--ort_build_path", required=True, help="ORT build directory.")
parser.add_argument("--native_build_path", required=True, help="Native build output directory.")
parser.add_argument("--packages_path", required=True, help="Nuget packages output directory.")
parser.add_argument("--sources_path", required=True, help="OnnxRuntime source code root.")
parser.add_argument("--commit_id", required=True, help="The last commit id included in this package.")
parser.add_argument(
"--is_release_build",
required=False,
default=None,
type=str,
help="Flag indicating if the build is a release build. Accepted values: true/false.",
)
parser.add_argument(
"--execution_provider",
required=False,
default="None",
type=str,
choices=["cuda", "dnnl", "openvino", "tensorrt", "snpe", "qnn", "None"],
help="The selected execution provider for this build.",
)
parser.add_argument("--sdk_info", required=False, default="", type=str, help="dependency SDK information.")
parser.add_argument(
"--nuspec_name", required=False, default="NativeNuget.nuspec", type=str, help="nuget spec name."
)
return parser.parse_args()
def generate_id(line_list, package_name):
line_list.append("<id>" + package_name + "</id>")
def generate_version(line_list, package_version):
line_list.append("<version>" + package_version + "</version>")
def generate_authors(line_list, authors):
line_list.append("<authors>" + authors + "</authors>")
def generate_owners(line_list, owners):
line_list.append("<owners>" + owners + "</owners>")
def generate_description(line_list, package_name):
description = ""
if package_name == "Microsoft.AI.MachineLearning":
description = "This package contains Windows ML binaries."
elif "Microsoft.ML.OnnxRuntime.Training" in package_name: # This is a Microsoft.ML.OnnxRuntime.Training.* package
description = (
"The onnxruntime-training native shared library artifacts are designed to efficiently train and infer "
+ "a wide range of ONNX models on edge devices, such as client machines, gaming consoles, and other "
+ "portable devices with a focus on minimizing resource usage and maximizing accuracy."
+ "See https://github.com/microsoft/onnxruntime-training-examples/tree/master/on_device_training for "
+ "more details."
)
elif "Microsoft.ML.OnnxRuntime.Gpu.Linux" in package_name:
description = "This package contains Linux native shared library artifacts for ONNX Runtime with CUDA."
elif "Microsoft.ML.OnnxRuntime.Gpu.Windows" in package_name:
description = "This package contains Windows native shared library artifacts for ONNX Runtime with CUDA."
elif "Intel.ML.OnnxRuntime" in package_name:
description = "This package contains native shared library artifacts for ONNX Runtime with OpenVINO."
elif "Microsoft.ML.OnnxRuntime" in package_name: # This is a Microsoft.ML.OnnxRuntime.* package
description = (
"This package contains native shared library artifacts for all supported platforms of ONNX Runtime."
)
line_list.append("<description>" + description + "</description>")
def generate_copyright(line_list, copyright):
line_list.append("<copyright>" + copyright + "</copyright>")
def generate_tags(line_list, tags):
line_list.append("<tags>" + tags + "</tags>")
def generate_icon(line_list, icon_file):
line_list.append("<icon>" + icon_file + "</icon>")
def generate_license(line_list):
line_list.append('<license type="file">LICENSE</license>')
def generate_project_url(line_list, project_url):
line_list.append("<projectUrl>" + project_url + "</projectUrl>")
def generate_repo_url(line_list, repo_url, commit_id):
line_list.append('<repository type="git" url="' + repo_url + '"' + ' commit="' + commit_id + '" />')
def generate_readme(line_list):
line_list.append("<readme>README.md</readme>")
def add_common_dependencies(xml_text, package_name, version):
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
if package_name == "Microsoft.ML.OnnxRuntime.Gpu":
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Gpu.Windows"' + ' version="' + version + '"/>')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Gpu.Linux"' + ' version="' + version + '"/>')
def generate_dependencies(xml_text, package_name, version):
dml_dependency = '<dependency id="Microsoft.AI.DirectML" version="1.15.4"/>'
if package_name == "Microsoft.AI.MachineLearning":
xml_text.append("<dependencies>")
# Support .Net Core
xml_text.append('<group targetFramework="net5.0">')
xml_text.append(dml_dependency)
xml_text.append("</group>")
# UAP10.0.16299, This is the earliest release of the OS that supports .NET Standard apps
xml_text.append('<group targetFramework="UAP10.0.16299">')
xml_text.append(dml_dependency)
xml_text.append("</group>")
# Support Native C++
xml_text.append('<group targetFramework="native">')
xml_text.append(dml_dependency)
xml_text.append("</group>")
xml_text.append("</dependencies>")
else:
include_dml = package_name == "Microsoft.ML.OnnxRuntime.DirectML"
xml_text.append("<dependencies>")
# Support .Net Core
xml_text.append('<group targetFramework="NETCOREAPP">')
add_common_dependencies(xml_text, package_name, version)
if include_dml:
xml_text.append(dml_dependency)
xml_text.append("</group>")
# Support .Net Standard
xml_text.append('<group targetFramework="NETSTANDARD">')
add_common_dependencies(xml_text, package_name, version)
if include_dml:
xml_text.append(dml_dependency)
xml_text.append("</group>")
# Support .Net Framework
xml_text.append('<group targetFramework="NETFRAMEWORK">')
add_common_dependencies(xml_text, package_name, version)
if include_dml:
xml_text.append(dml_dependency)
xml_text.append("</group>")
if package_name == "Microsoft.ML.OnnxRuntime":
xml_text.append('<group targetFramework="native" />')
# Support net8.0-android
xml_text.append('<group targetFramework="net8.0-android31.0">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support net8.0-ios
xml_text.append('<group targetFramework="net8.0-ios15.4">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support net8.0-maccatalyst
xml_text.append('<group targetFramework="net8.0-maccatalyst14.0">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support Native C++
if include_dml:
xml_text.append('<group targetFramework="native">')
xml_text.append(dml_dependency)
xml_text.append("</group>")
xml_text.append("</dependencies>")
def get_env_var(key):
return os.environ.get(key)
def generate_release_notes(line_list, dependency_sdk_info):
line_list.append("<releaseNotes>")
line_list.append("Release Def:")
branch = get_env_var("BUILD_SOURCEBRANCH")
line_list.append("\t" + "Branch: " + (branch if branch is not None else ""))
version = get_env_var("BUILD_SOURCEVERSION")
line_list.append("\t" + "Commit: " + (version if version is not None else ""))
build_id = get_env_var("BUILD_BUILDID")
line_list.append(
"\t"
+ "Build: https://aiinfra.visualstudio.com/Lotus/_build/results?buildId="
+ (build_id if build_id is not None else "")
)
if dependency_sdk_info:
line_list.append("Dependency SDK: " + dependency_sdk_info)
line_list.append("</releaseNotes>")
def generate_metadata(line_list, args):
tags = "native ONNX Runtime ONNXRuntime Machine Learning MachineLearning"
if "Microsoft.ML.OnnxRuntime.Training." in args.package_name:
tags.append(" ONNXRuntime-Training Learning-on-The-Edge On-Device-Training On-Device Training")
metadata_list = ["<metadata>"]
generate_id(metadata_list, args.package_name)
generate_version(metadata_list, args.package_version)
generate_authors(metadata_list, "Microsoft")
generate_owners(metadata_list, "Microsoft")
generate_description(metadata_list, args.package_name)
generate_copyright(metadata_list, "\xc2\xa9 " + "Microsoft Corporation. All rights reserved.")
generate_tags(metadata_list, tags)
generate_icon(metadata_list, "ORT_icon_for_light_bg.png")
generate_license(metadata_list)
generate_project_url(metadata_list, "https://github.com/Microsoft/onnxruntime")
generate_repo_url(metadata_list, "https://github.com/Microsoft/onnxruntime.git", args.commit_id)
generate_readme(metadata_list)
generate_dependencies(metadata_list, args.package_name, args.package_version)
generate_release_notes(metadata_list, args.sdk_info)
metadata_list.append("</metadata>")
line_list += metadata_list
def generate_files(line_list, args):
files_list = ["<files>"]
is_cpu_package = args.package_name in [
"Microsoft.ML.OnnxRuntime",
"Microsoft.ML.OnnxRuntime.OpenMP",
"Microsoft.ML.OnnxRuntime.Training",
]
is_mklml_package = args.package_name == "Microsoft.ML.OnnxRuntime.MKLML"
is_cuda_gpu_package = args.package_name == "Microsoft.ML.OnnxRuntime.Gpu"
is_cuda_gpu_win_sub_package = args.package_name == "Microsoft.ML.OnnxRuntime.Gpu.Windows"
is_cuda_gpu_linux_sub_package = args.package_name == "Microsoft.ML.OnnxRuntime.Gpu.Linux"
is_rocm_gpu_package = args.package_name == "Microsoft.ML.OnnxRuntime.ROCm"
is_dml_package = args.package_name == "Microsoft.ML.OnnxRuntime.DirectML"
is_windowsai_package = args.package_name == "Microsoft.AI.MachineLearning"
is_snpe_package = args.package_name == "Microsoft.ML.OnnxRuntime.Snpe"
is_qnn_package = args.package_name == "Microsoft.ML.OnnxRuntime.QNN"
is_training_package = args.package_name in [
"Microsoft.ML.OnnxRuntime.Training",
"Microsoft.ML.OnnxRuntime.Training.Gpu",
]
includes_winml = is_windowsai_package
includes_directml = (is_dml_package or is_windowsai_package) and (
args.target_architecture == "x64" or args.target_architecture == "x86"
)
is_windows_build = is_windows()
nuget_dependencies = {}
if is_windows_build:
nuget_dependencies = {
"mklml": "mklml.dll",
"openmp": "libiomp5md.dll",
"dnnl": "dnnl.dll",
"providers_shared_lib": "onnxruntime_providers_shared.dll",
"dnnl_ep_shared_lib": "onnxruntime_providers_dnnl.dll",
"tensorrt_ep_shared_lib": "onnxruntime_providers_tensorrt.dll",
"openvino_ep_shared_lib": "onnxruntime_providers_openvino.dll",
"cuda_ep_shared_lib": "onnxruntime_providers_cuda.dll",
"qnn_ep_shared_lib": "onnxruntime_providers_qnn.dll",
"onnxruntime_perf_test": "onnxruntime_perf_test.exe",
"onnx_test_runner": "onnx_test_runner.exe",
}
copy_command = "copy"
runtimes_target = '" target="runtimes\\win-'
else:
nuget_dependencies = {
"mklml": "libmklml_intel.so",
"mklml_1": "libmklml_gnu.so",
"openmp": "libiomp5.so",
"dnnl": "libdnnl.so.1",
"providers_shared_lib": "libonnxruntime_providers_shared.so",
"dnnl_ep_shared_lib": "libonnxruntime_providers_dnnl.so",
"tensorrt_ep_shared_lib": "libonnxruntime_providers_tensorrt.so",
"openvino_ep_shared_lib": "libonnxruntime_providers_openvino.so",
"cuda_ep_shared_lib": "libonnxruntime_providers_cuda.so",
"rocm_ep_shared_lib": "libonnxruntime_providers_rocm.so",
"onnxruntime_perf_test": "onnxruntime_perf_test",
"onnx_test_runner": "onnx_test_runner",
}
copy_command = "cp"
runtimes_target = '" target="runtimes\\linux-'
if is_windowsai_package:
runtimes_native_folder = "_native"
else:
runtimes_native_folder = "native"
runtimes = f'{runtimes_target}{args.target_architecture}\\{runtimes_native_folder}"'
# Process headers
build_dir = "buildTransitive" if "Gpu" in args.package_name else "build"
include_dir = f"{build_dir}\\native\\include"
# Sub.Gpu packages do not include the onnxruntime headers
if args.package_name != "Microsoft.ML.OnnxRuntime.Gpu":
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "include\\onnxruntime\\core\\session\\onnxruntime_*.h")
+ '" target="'
+ include_dir
+ '" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "include\\onnxruntime\\core\\framework\\provider_options.h")
+ '" target="'
+ include_dir
+ '" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "include\\onnxruntime\\core\\providers\\cpu\\cpu_provider_factory.h")
+ '" target="'
+ include_dir
+ '" />'
)
if is_training_package:
files_list.append(
"<file src="
+ '"'
+ os.path.join(
args.sources_path, "orttraining\\orttraining\\training_api\\include\\onnxruntime_training_*.h"
)
+ '" target="build\\native\\include" />'
)
if args.execution_provider == "openvino":
files_list.append(
"<file src="
+ '"'
+ os.path.join(
args.sources_path, "include\\onnxruntime\\core\\providers\\openvino\\openvino_provider_factory.h"
)
+ '" target="build\\native\\include" />'
)
if args.execution_provider == "tensorrt":
files_list.append("<file src=" + '"' + '" target="build\\native\\include" />')
if args.execution_provider == "dnnl":
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "include\\onnxruntime\\core\\providers\\dnnl\\dnnl_provider_options.h")
+ '" target="build\\native\\include" />'
)
if includes_directml:
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "include\\onnxruntime\\core\\providers\\dml\\dml_provider_factory.h")
+ '" target="build\\native\\include" />'
)
if includes_winml:
# Add microsoft.ai.machinelearning headers
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.ort_build_path, args.build_config, "microsoft.ai.machinelearning.h")
+ '" target="build\\native\\include\\abi\\Microsoft.AI.MachineLearning.h" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.sources_path, "winml\\api\\dualapipartitionattribute.h")
+ '" target="build\\native\\include\\abi\\dualapipartitionattribute.h" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.ort_build_path, args.build_config, "microsoft.ai.machinelearning.native.h")
+ '" target="build\\native\\include\\Microsoft.AI.MachineLearning.Native.h" />'
)
# Add custom operator headers
mlop_path = "onnxruntime\\core\\providers\\dml\\dmlexecutionprovider\\inc\\mloperatorauthor.h"
files_list.append(
"<file src=" + '"' + os.path.join(args.sources_path, mlop_path) + '" target="build\\native\\include" />'
)
# Process microsoft.ai.machinelearning.winmd
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.ort_build_path, args.build_config, "microsoft.ai.machinelearning.winmd")
+ '" target="winmds\\Microsoft.AI.MachineLearning.winmd" />'
)
# Process microsoft.ai.machinelearning.experimental.winmd
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.ort_build_path, args.build_config, "microsoft.ai.machinelearning.experimental.winmd")
+ '" target="winmds\\Microsoft.AI.MachineLearning.Experimental.winmd" />'
)
if args.target_architecture == "x64":
interop_dll_path = "Microsoft.AI.MachineLearning.Interop\\net5.0-windows10.0.17763.0"
interop_dll = interop_dll_path + "\\Microsoft.AI.MachineLearning.Interop.dll"
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, interop_dll)
+ '" target="lib\\net5.0\\Microsoft.AI.MachineLearning.Interop.dll" />'
)
interop_pdb_path = "Microsoft.AI.MachineLearning.Interop\\net5.0-windows10.0.17763.0"
interop_pdb = interop_pdb_path + "\\Microsoft.AI.MachineLearning.Interop.pdb"
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, interop_pdb)
+ '" target="lib\\net5.0\\Microsoft.AI.MachineLearning.Interop.pdb" />'
)
if args.package_name == "Microsoft.ML.OnnxRuntime.Snpe" or args.package_name == "Microsoft.ML.OnnxRuntime.QNN":
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "onnx_test_runner.exe") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "onnxruntime_perf_test.exe") + runtimes + " />"
)
if is_qnn_package:
files_list.append("<file src=" + '"' + os.path.join(args.native_build_path, "QnnCpu.dll") + runtimes + " />")
files_list.append("<file src=" + '"' + os.path.join(args.native_build_path, "QnnHtp.dll") + runtimes + " />")
files_list.append("<file src=" + '"' + os.path.join(args.native_build_path, "QnnSaver.dll") + runtimes + " />")
if args.target_architecture != "x64":
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "QnnSystem.dll") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "QnnHtpPrepare.dll") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "QnnHtpV73Stub.dll") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "libQnnHtpV73Skel.so") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "libqnnhtpv73.cat") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "QnnHtpV68Stub.dll") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "libQnnHtpV68Skel.so") + runtimes + " />"
)
is_ado_packaging_build = False
# Process runtimes
# Process onnxruntime import lib, dll, and pdb
# for Snpe android build
if is_windows_build:
nuget_artifacts_dir = Path(args.native_build_path) / "nuget-artifacts"
# the winml package includes pdbs. for other packages exclude them.
include_pdbs = includes_winml
if nuget_artifacts_dir.exists():
# Code path for ADO build pipeline, the files under 'nuget-artifacts' are
# downloaded from other build jobs
if is_cuda_gpu_package or is_cuda_gpu_win_sub_package or is_cuda_gpu_linux_sub_package:
ep_list = ["tensorrt", "cuda", None]
elif is_rocm_gpu_package:
ep_list = ["rocm", None]
else:
ep_list = [None]
for ep in ep_list:
generate_file_list_for_ep(
nuget_artifacts_dir, ep, files_list, include_pdbs, is_training_package, args.package_name
)
is_ado_packaging_build = True
else:
# Code path for local dev build
# for local dev build, gpu linux package is also generated for compatibility though it is not used
if not is_cuda_gpu_linux_sub_package:
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "onnxruntime.lib") + runtimes + " />"
)
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "onnxruntime.dll") + runtimes + " />"
)
if include_pdbs and os.path.exists(os.path.join(args.native_build_path, "onnxruntime.pdb")):
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, "onnxruntime.pdb") + runtimes + " />"
)
else:
ort_so = os.path.join(args.native_build_path, "libonnxruntime.so")
if os.path.exists(ort_so):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, "libonnxruntime.so")
+ '" target="runtimes\\linux-'
+ args.target_architecture
+ '\\native" />'
)
if includes_winml:
# Process microsoft.ai.machinelearning import lib, dll, and pdb
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, "microsoft.ai.machinelearning.lib")
+ runtimes_target
+ args.target_architecture
+ "\\_native"
+ '\\Microsoft.AI.MachineLearning.lib" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, "microsoft.ai.machinelearning.dll")
+ runtimes_target
+ args.target_architecture
+ "\\_native"
+ '\\Microsoft.AI.MachineLearning.dll" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, "microsoft.ai.machinelearning.pdb")
+ runtimes_target
+ args.target_architecture
+ "\\_native"
+ '\\Microsoft.AI.MachineLearning.pdb" />'
)
# Process execution providers which are built as shared libs
if args.execution_provider == "tensorrt" and not is_ado_packaging_build:
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["cuda_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["tensorrt_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if args.execution_provider == "dnnl":
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["dnnl_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if args.execution_provider == "rocm" or (is_rocm_gpu_package and not is_ado_packaging_build):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["rocm_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if args.execution_provider == "openvino":
openvino_path = get_env_var("INTEL_OPENVINO_DIR")
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["openvino_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if is_windows():
dll_list_path = os.path.join(openvino_path, "runtime\\bin\\intel64\\Release\\")
tbb_list_path = os.path.join(openvino_path, "runtime\\3rdparty\\tbb\\bin\\")
for dll_element in os.listdir(dll_list_path):
if dll_element.endswith("dll"):
files_list.append(
"<file src="
+ '"'
+ os.path.join(dll_list_path, dll_element)
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
for tbb_element in os.listdir(tbb_list_path):
if tbb_element.endswith("dll"):
files_list.append(
"<file src="
+ '"'
+ os.path.join(tbb_list_path, tbb_element)
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if args.execution_provider == "cuda" or (is_cuda_gpu_win_sub_package and not is_ado_packaging_build):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["cuda_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
if args.execution_provider == "qnn" or (is_qnn_package and not is_ado_packaging_build):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["providers_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["qnn_ep_shared_lib"])
+ runtimes_target
+ args.target_architecture
+ '\\native" />'
)
# process all other library dependencies
if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package:
# Process dnnl dependency
if os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["dnnl"])):
files_list.append(
"<file src=" + '"' + os.path.join(args.native_build_path, nuget_dependencies["dnnl"]) + runtimes + " />"
)
# Process mklml dependency
if os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["mklml"])):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["mklml"])
+ runtimes
+ " />"
)
if is_linux() and os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["mklml_1"])):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["mklml_1"])
+ runtimes
+ " />"
)
# Process libiomp5md dependency
if os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["openmp"])):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["openmp"])
+ runtimes
+ " />"
)
# Some tools to be packaged in nightly debug build only, should not be released
# These are copied to the runtimes folder for convenience of loading with the dlls
# NOTE: nuget gives a spurious error on linux if these aren't in a separate directory to the library so
# we add them to a tools folder for that reason.
if (
args.is_release_build.lower() != "true"
and args.target_architecture == "x64"
and os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["onnxruntime_perf_test"]))
):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["onnxruntime_perf_test"])
+ runtimes[:-1]
+ "\\tools\\"
+ nuget_dependencies["onnxruntime_perf_test"]
+ '"'
+ " />"
)
if (
args.is_release_build.lower() != "true"
and args.target_architecture == "x64"
and os.path.exists(os.path.join(args.native_build_path, nuget_dependencies["onnx_test_runner"]))
):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["onnx_test_runner"])
+ runtimes[:-1]
+ "\\tools\\"
+ nuget_dependencies["onnx_test_runner"]
+ '"'
+ " />"
)
# Process props and targets files
if is_windowsai_package:
windowsai_src = "Microsoft.AI.MachineLearning"
windowsai_props = "Microsoft.AI.MachineLearning.props"
windowsai_targets = "Microsoft.AI.MachineLearning.targets"
windowsai_native_props = os.path.join(args.sources_path, "csharp", "src", windowsai_src, windowsai_props)
windowsai_rules = "Microsoft.AI.MachineLearning.Rules.Project.xml"
windowsai_native_rules = os.path.join(args.sources_path, "csharp", "src", windowsai_src, windowsai_rules)
windowsai_native_targets = os.path.join(args.sources_path, "csharp", "src", windowsai_src, windowsai_targets)
build = f"{build_dir}\\native"
files_list.append("<file src=" + '"' + windowsai_native_props + '" target="' + build + '" />')
# Process native targets
files_list.append("<file src=" + '"' + windowsai_native_targets + '" target="' + build + '" />')
# Process rules
files_list.append("<file src=" + '"' + windowsai_native_rules + '" target="' + build + '" />')
# Process .net5.0 targets
if args.target_architecture == "x64":
interop_src = "Microsoft.AI.MachineLearning.Interop"
interop_props = "Microsoft.AI.MachineLearning.props"
interop_targets = "Microsoft.AI.MachineLearning.targets"
windowsai_net50_props = os.path.join(args.sources_path, "csharp", "src", interop_src, interop_props)
windowsai_net50_targets = os.path.join(args.sources_path, "csharp", "src", interop_src, interop_targets)
files_list.append("<file src=" + '"' + windowsai_net50_props + '" target="build\\net5.0" />')
files_list.append("<file src=" + '"' + windowsai_net50_targets + '" target="build\\net5.0" />')
if (
is_cpu_package
or is_cuda_gpu_package
or is_cuda_gpu_linux_sub_package
or is_cuda_gpu_win_sub_package
or is_rocm_gpu_package
or is_dml_package
or is_mklml_package
or is_snpe_package
or is_qnn_package
):
# Process props file
source_props = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "netstandard", "props.xml"
)
target_props = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"netstandard",
args.package_name + ".props",
)
os.system(copy_command + " " + source_props + " " + target_props)
files_list.append("<file src=" + '"' + target_props + '" target="' + build_dir + '\\native" />')
if not is_snpe_package and not is_qnn_package:
files_list.append("<file src=" + '"' + target_props + '" target="' + build_dir + '\\netstandard2.0" />')
files_list.append("<file src=" + '"' + target_props + '" target="' + build_dir + '\\netstandard2.1" />')
# Process targets file
source_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "netstandard", "targets.xml"
)
target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"netstandard",
args.package_name + ".targets",
)
os.system(copy_command + " " + source_targets + " " + target_targets)
files_list.append("<file src=" + '"' + target_targets + '" target="' + build_dir + '\\native" />')
if not is_snpe_package and not is_qnn_package:
files_list.append("<file src=" + '"' + target_targets + '" target="' + build_dir + '\\netstandard2.0" />')
files_list.append("<file src=" + '"' + target_targets + '" target="' + build_dir + '\\netstandard2.1" />')
# Process xamarin targets files
if args.package_name == "Microsoft.ML.OnnxRuntime":
net8_android_source_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net8.0-android",
"targets.xml",
)
net8_android_target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net8.0-android",
args.package_name + ".targets",
)
net8_ios_source_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "net8.0-ios", "targets.xml"
)
net8_ios_target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net8.0-ios",
args.package_name + ".targets",
)
net8_maccatalyst_source_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net8.0-maccatalyst",
"_._",
)
net8_maccatalyst_target_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "net8.0-maccatalyst", "_._"
)
os.system(copy_command + " " + net8_android_source_targets + " " + net8_android_target_targets)
os.system(copy_command + " " + net8_ios_source_targets + " " + net8_ios_target_targets)
os.system(copy_command + " " + net8_maccatalyst_source_targets + " " + net8_maccatalyst_target_targets)
files_list.append(
"<file src=" + '"' + net8_android_target_targets + '" target="build\\net8.0-android31.0" />'