-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ps1
1761 lines (1402 loc) · 58.5 KB
/
build.ps1
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) 2021-2022 Mark Roszko <[email protected]>
# Copyright (C) 2021-2022 KiCad Developers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
##
# KiCad Powershell Windows Build Assistant
#
# Note, options in brackets [] are optional
# Usage:
# Configure/set the vcpkg path, OPTIONAL
# Otherwise will checkout vcpkg inside the win-builder folder
# ./build.ps1 -Config -VcpkgPath="path to vcpkg"
#
# Checkout any required tools
# ./build.ps1 -Init
#
# Checkout any required tools, setup build environment variables
# ./build.ps1 -Env [-Arch x64]
#
# Rebuilds vcpkg dependencies (if updated)
# ./build.ps1 -Vcpkg [-Latest] [-Arch x64]
#
# Triggers a build
# ./build.ps1 -Build [-Latest] [-Arch x64] [-BuildType Release]
#
# Triggers a package operation
# ./build.ps1 -PreparePackage [-Arch x64] [-BuildType Release] [-Lite] [-IncludeDebugSymbols]
#
# Triggers a package operation
# ./build.ps1 -Package [-PackType Nsis] [-Arch x64] [-BuildType Release] [-Lite] [-IncludeDebugSymbols]
#
# Triggers a msix assets generation
# ./build.ps1 -MsixAssets
#
# IncludeDebugSymbols will include PDBs (off by default)
# Lite will build the light version of the installer (no libraries)
##
param(
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="config")]
[Switch]$Config,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="init")]
[Switch]$Init,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="env")]
[Switch]$Env,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="build")]
[Switch]$Build,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="vcpkg")]
[Switch]$Vcpkg,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="package")]
[Switch]$Package,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="preparepackage")]
[Switch]$PreparePackage,
[Parameter(Position = 0, Mandatory=$True, ParameterSetName="msixassets")]
[Switch]$MsixAssets,
[Parameter(Mandatory=$True, ParameterSetName="msixassets")]
[Parameter(Mandatory=$False, ParameterSetName="package")]
[string]$Version,
[Parameter(Mandatory=$False, ParameterSetName="build")]
[Parameter(Mandatory=$False, ParameterSetName="vcpkg")]
[Switch]$Latest,
[Parameter(Mandatory=$False, ParameterSetName="env")]
[Parameter(Mandatory=$False, ParameterSetName="build")]
[Parameter(Mandatory=$False, ParameterSetName="vcpkg")]
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[ValidateSet('x86', 'x64', 'arm64', 'arm')]
[string]$Arch = 'x64',
[Parameter(Mandatory=$False, ParameterSetName="package")]
[ValidateSet('nsis', 'msix')]
[string]$PackType = 'nsis',
[Parameter(Mandatory=$False, ParameterSetName="build")]
[Parameter(Mandatory=$False, ParameterSetName="vcpkg")]
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
# NOTE Change to your build config
[string]$BuildConfigName = 'kicad-test',
[Parameter(Mandatory=$False, ParameterSetName="build")]
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[ValidateSet('Release', 'Debug')]
[string]$BuildType = 'Release',
[Parameter(Mandatory=$False, ParameterSetName="package")]
[switch]$DebugSymbols,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[switch]$IncludeVcpkgDebugSymbols,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[switch]$Lite,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[bool]$Prepare = $True,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[switch]$Sign,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[bool]$SignAKV = $False,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[string]$AKVAppId = "",
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[string]$AKVAppSecret = "",
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[string]$AKVTenantId = "",
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[string]$AKVCertName = "",
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[string]$AKVUrl = "",
[Parameter(Mandatory=$False, ParameterSetName="package")]
[bool]$PostCleanup = $False,
[Parameter(Mandatory=$False, ParameterSetName="package")]
[Parameter(Mandatory=$False, ParameterSetName="preparepackage")]
[bool]$SentryArtifact = $False,
[Parameter(Mandatory=$False, ParameterSetName="config")]
[string]$VcpkgPath = "",
[Parameter(Mandatory=$False, ParameterSetName="config")]
[bool]$UseMsvcCmake = $True,
[Parameter(Mandatory=$False, ParameterSetName="config")]
[string]$SentryDsn = ""
)
Import-Module $PSScriptRoot\KiBuild -Force -DisableNameChecking
###
## Base setup
###
$vcpkgCommit = "c6928dfb9eb7f333f988d2ce70d1e771b7606849";
$cmakeFolder = 'cmake-3.27.1-windows-x86_64'
$cmakeDownload = 'https://github.com/Kitware/CMake/releases/download/v3.27.1/cmake-3.27.1-windows-x86_64.zip'
$cmakeChecksum = "664FE1655999F0B693D1E64DDB430191C727AB0A03DC1DA7278F291172E1E04E"
$ninjaFolder = 'ninja-win'
$ninjaDownload = 'https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip'
$ninjaChecksum = "524B344A1A9A55005EAF868D991E090AB8CE07FA109F1820D40E74642E289ABC"
$vswhereDownload = 'https://github.com/microsoft/vswhere/releases/download/2.8.4/vswhere.exe'
$vswhereChecksum = "E50A14767C27477F634A4C19709D35C27A72F541FB2BA5C3A446C80998A86419"
$swigwinFolder = "swigwin-4.1.1"
$swigwinDownload = "https://github.com/user-attachments/files/16921684/swigwin-4.1.1.zip"
$swigwinChecksum = "5af8dc2df5eb4d38663d875d035cd4868f08c43a6100edfbd8d6ae53d61ae1b9"
$nsisFolderName = "nsis-3.08"
$nsisDownload = "https://sourceforge.net/projects/nsis/files/NSIS%203/3.08/nsis-3.08.zip/download"
$nsisChecksum = "1BB9FC85EE5B220D3869325DBB9D191DFE6537070F641C30FBB275C97051FD0C"
$gettextFolderName = "gettext0.21-iconv1.16-static-64"
$gettextDownload = "https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.21-v1.16/gettext0.21-iconv1.16-static-64.zip"
$gettextChecksum = "721395C2E057EEED321F0C793311732E57CB4FA30D5708672A13902A69A77D43"
$doxygenDownload = "https://sourceforge.net/projects/doxygen/files/rel-1.9.3/doxygen-1.9.3.windows.x64.bin.zip/download?use_mirror=pilotfiber"
$doxygenChecksum = "575B1A27CB907675D24F2C348A4D95D9CDD6A2000F6A8D8BFC4C3A20B2E120F5"
$doxygenFolderName = "doxygen-1.9.3.windows.x64.bin"
$s5cmdDownload = "https://github.com/peak/s5cmd/releases/download/v1.4.0/s5cmd_1.4.0_Windows-64bit.zip"
$s5cmdChecksum = "085CCD677662C0B4EEA00325AAF04CE62B920D2A37F313AF9616ACE7DDDA537E"
$s5cmdFolderName = "s5cmd_1.4.0_Windows-64bit"
$sentryCliDownload = 'https://github.com/getsentry/sentry-cli/releases/download/1.74.3/sentry-cli-Windows-x86_64.exe'
$sentryCliChecksum = "0D2F372D98F53EA4D4DF26161F1F821D5322B00A0227CE84EC939BF271C720AD"
$7zaFolderName = "7z2201-extra"
Init-Paths $PSScriptRoot
$BuilderPaths = Get-BuilderPaths
$swigWinPath = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $swigwinFolder
$gettextPath = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "/$gettextFolderName/bin"
$doxygenPath = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $doxygenFolderName
$nsisPath = Join-Path -Path (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $nsisFolderName) -ChildPath "bin/"
$azureSignToolVersion = "3.0.0"
$azureSignToolPath = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "azuresigntool-$azureSignToolVersion"
$env:Path = $swigWinPath+";"+$gettextPath+";"+$nsisPath+";"+$doxygenPath+";"+$env:PATH
# Use TLS1.2 by force in case of older powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Force git output to go to stdout or else powershell eats it and doesn't show us it
$env:GIT_REDIRECT_STDERR='2>&1'
###
# Load and handle Config
###
$settingsPath = Join-Path -Path $PSScriptRoot -ChildPath "settings.json"
$settingDefault = @{
VcpkgPath = ''
VcpkgPlatformToolset = 'v142'
VsVersionMin = '16.0'
VsVersionMax = '17.99'
SignSubjectName = 'KiCad Services Corporation'
UseMsvcCmake = $True
SentryDsn = ''
}
$settingsSaved = @{}
if ( Test-Path $settingsPath ) {
Write-Host "Loading settings from $settingsPath"
$settingsObj = Get-Content -Path $settingsPath | ConvertFrom-Json
Write-Host "-----"
$settingsObj.psobject.properties | Foreach {
$settingsSaved[$_.Name] = $_.Value
Write-Host "$($_.Name): $($_.Value)"
}
Write-Host "-----"
} else {
Write-Host "Existing settings not found" -ForegroundColor DarkYellow
}
###
# Load release if set
###
$buildConfigured = $false
$buildConfig = @{}
$buildConfigsPath = Join-Path -Path $PSScriptRoot -ChildPath "\build-configs"
if( $BuildConfigName ) {
$buildConfigPath = Join-Path -Path $buildConfigsPath -ChildPath "$BuildConfigName.json"
if ( -Not (Test-Path $buildConfigPath) ) {
Write-Error "Build Config ""$BuildConfigName"" not found"
Exit [ExitCodes]::ReleaseDoesNotExit
}
$buildConfig = Get-Content -Path $buildConfigPath | ConvertFrom-Json
$BuildConfigName = $true
Write-Host "Loaded release config $($buildConfig.name)" -ForegroundColor Yellow
}
$settings = Merge-HashTable -Default $settingDefault -Uppend $settingsSaved
# Set VCPKG Platform Toolset
$env:VCPKG_PLATFORM_TOOLSET = $settings.VcpkgPlatformToolset
###
# Setup aliases to shorten accessing tools
##
function Set-Aliases()
{
Write-Host "Configuring tool aliases"
if( -not (Test-Path alias:vcpkg ) )
{
if( $settings.VcpkgPath -ne "" )
{
$tmp = Join-Path -Path $settings.VcpkgPath -ChildPath "vcpkg.exe"
Set-Alias vcpkg $tmp -Option AllScope -Scope Global
}
}
if( -not (Test-Path alias:vswhere ) )
{
$tmp = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "vswhere.exe"
Set-Alias vswhere $tmp -Option AllScope -Scope Global
}
if( -not $settings.UseMsvcCmake )
{
if( -not (Test-Path alias:cmake ) )
{
$cmakeBin = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "$cmakeFolder/bin"
$cmakeExe = Join-Path -Path $cmakeBin -ChildPath "cmake.exe"
$env:Path = $cmakeBin+";"+$env:Path;
Set-Alias cmake $cmakeExe -Option AllScope -Scope Global
}
if( -not (Test-Path alias:ninja ) )
{
$ninjaBin = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "$ninjaFolder"
$ninjaExe = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "$ninjaFolder/ninja.exe"
$env:NINJA_PATH = $ninjaExe;
$env:Path = $ninjaBin+";"+$env:Path;
Set-Alias ninja $ninjaExe -Option AllScope -Scope Global
}
}
if( -not (Test-Path alias:makensis ) )
{
$tmp = Join-Path -Path (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $nsisFolderName) -ChildPath "bin/makensis.exe"
Set-Alias makensis $tmp -Option AllScope -Scope Global
}
if( -not (Test-Path alias:7za ) )
{
$tmp = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "$7zaFolderName/7za.exe"
Set-Alias 7za $tmp -Option AllScope -Scope Global
}
if( -not (Test-Path alias:sentry-cli ) )
{
$tmp = Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "sentry-cli.exe"
Set-Alias sentry-cli $tmp -Option AllScope -Scope Global
}
if( -not (Test-Path alias:azuresigntool ) )
{
$tmp = Join-Path -Path $azureSignToolPath -ChildPath "azuresigntool.exe"
Set-Alias azuresigntool $tmp -Option AllScope -Scope Global
}
if( -not (Test-Path alias:s5cmd ) )
{
$tmp = Join-Path -Path (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $s5cmdFolderName) -ChildPath "s5cmd.exe"
Set-Alias s5cmd $tmp -Option AllScope -Scope Global
}
}
## Invoke it
Set-Aliases
###
# General functions
##
function Get-Source-Path([string]$subfolder) {
return Join-Path -Path $BuilderPaths.BuildRoot -ChildPath $subfolder
}
function Build-Library-Source {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[ValidateSet('Release', 'Debug')]
[string]$buildType = 'Release',
[string]$libraryFolderName
)
Push-Location (Get-Source-Path $libraryFolderName)
Set-MSVCEnvironment -Arch $arch -VersionMin $settings.VsVersionMin -VersionMax $settings.VsVersionMax
$buildName = Get-Build-Name -Arch $arch -BuildType $buildType
$installPath = Join-Path -Path $BuilderPaths.OutRoot -ChildPath "$buildName/"
$cmakeBuildFolder = "build/$buildName"
$generator = "Ninja"
& {
$ErrorActionPreference = 'SilentlyContinue'
cmake -G $generator `
-B $cmakeBuildFolder `
-S . `
-DCMAKE_INSTALL_PREFIX="$installPath" `
-DCMAKE_RULE_MESSAGES:BOOL="OFF" `
-DCMAKE_VERBOSE_MAKEFILE:BOOL="OFF"
}
if ($LastExitCode -ne 0) {
Write-Error "Failure generating cmake"
Pop-Location
Exit [ExitCodes]::CMakeGenerationFailure
}
Write-Host "Configured $libraryFolderName" -ForegroundColor Green
Pop-Location
}
function Install-Library {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[ValidateSet('Release', 'Debug')]
[string]$buildType = 'Release',
[string]$libraryFolderName
)
Push-Location (Get-Source-Path $libraryFolderName)
Set-MSVCEnvironment -Arch $arch -VersionMin $settings.VsVersionMin -VersionMax $settings.VsVersionMax
$buildName = Get-Build-Name -Arch $arch -BuildType $buildType
$cmakeBuildFolder = "build/$buildName"
Write-Host "Installing $libraryFolderName to output" -ForegroundColor Yellow
& {
$ErrorActionPreference = 'SilentlyContinue'
cmake --install $cmakeBuildFolder > $null
}
if ($LastExitCode -ne 0) {
Write-Error "Failure with cmake install"
Pop-Location
Exit [ExitCodes]::CMakeInstallFailure
}
Pop-Location
}
function Install-Kicad {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[ValidateSet('Release', 'Debug')]
[string]$buildType = 'Release',
[Parameter(Mandatory=$False)]
[string]$installPath = ''
)
Set-MSVCEnvironment -Arch $arch -VersionMin $settings.VsVersionMin -VersionMax $settings.VsVersionMax
$buildName = Get-Build-Name -Arch $arch -BuildType $buildType
#step down into kicad folder
Push-Location (Get-Source-Path kicad)
$cmakeBuildFolder = "build/$buildName"
Write-Host "Invoking cmake install" -ForegroundColor Yellow
& {
$ErrorActionPreference = 'SilentlyContinue'
if( $installPath ) {
cmake --install $cmakeBuildFolder --prefix $installPath > $null
} else {
cmake --install $cmakeBuildFolder > $null
}
}
if ($LastExitCode -ne 0) {
Write-Error "Failure with cmake install"
Pop-Location
Exit [ExitCodes]::CMakeInstallFailure
} else {
Write-Host "Install success" -ForegroundColor Green
}
#restore path
Pop-Location
}
function Build-Kicad {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[ValidateSet('Release', 'Debug')]
[string]$buildType = 'Release',
[Parameter(Mandatory=$False)]
[bool]$fresh = $False
)
$buildName = Get-Build-Name -Arch $arch -BuildType $buildType
#step down into kicad folder
Push-Location (Get-Source-Path kicad)
Set-MSVCEnvironment -Arch $arch -VersionMin $settings.VsVersionMin -VersionMax $settings.VsVersionMax
$cmakeBuildFolder = "build/$buildName"
$generator = "Ninja"
#delete the old build folder https://gitlab.com/kicad/code/kicad.git
if($fresh) {
Remove-Item $cmakeBuildFolder -Recurse -ErrorAction SilentlyContinue
}
$installPath = Join-Path -Path $BuilderPaths.OutRoot -ChildPath "$buildName/"
$toolchainPath = Join-Path -Path $settings["VcpkgPath"] -ChildPath "/scripts/buildsystems/vcpkg.cmake"
$installPdbPath = Join-Path -Path $BuilderPaths.OutRoot -ChildPath "$buildName-pdb"
Write-Host "Starting build"
Write-Host "arch: $arch"
Write-Host "buildType: $buildType"
Write-Host "Configured install directory: $installPath"
Write-Host "Vcpkg Path: $toolchainPath"
Set-Aliases
$msvcInfo = & vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to find a suitable MSVC installation."
exit 1
}
$vcInstallDir = Join-Path $msvcInfo "VC"
$cCompilerPath = Join-Path $vcInstallDir "Tools\MSVC\*\bin\Hostx64\x64\cl.exe"
$cxxCompilerPath = $cCompilerPath.Replace("cl.exe", "cl.exe")
$cCompilerPath = (Resolve-Path $cCompilerPath).Path
$cxxCompilerPath = (Resolve-Path $cxxCompilerPath).Path
if (-not (Test-Path $cCompilerPath) -or -not (Test-Path $cxxCompilerPath)) {
Write-Host "Unable to locate C/C++ compilers at the specified paths."
exit 1
}
$cmakeArgs = @(
'-G',
$generator,
'-B',
$cmakeBuildFolder,
'-Wno-dev',
'--fresh',
"-DCMAKE_BUILD_TYPE=$buildType",
"-DCMAKE_TOOLCHAIN_FILE=$toolchainPath",
"-DCMAKE_INSTALL_PREFIX=$installPath",
"-DCMAKE_PDB_OUTPUT_DIRECTORY=$installPdbPath",
"-DCMAKE_MAKE_PROGRAM=$env:NINJA_PATH",
'-DKICAD_BUILD_QA_TESTS=OFF',
'-DKICAD_BUILD_I18N=ON',
'-DKICAD_WIN32_DPI_AWARE=ON',
'-DVCPKG_MANIFEST_MODE=ON',
"-DKICAD_RUN_FROM_BUILD_DIR=1"
)
if( $arch -ne [Arch]::arm64 ) {
$cmakeArgs += '-DKICAD_SCRIPTING_WXPYTHON=ON';
if( $settings.SentryDsn -ne "" ) {
$cmakeArgs += '-DKICAD_USE_SENTRY=ON';
$cmakeArgs += "-DKICAD_SENTRY_DSN=$($settings.SentryDsn)";
}
}
else {
$hostArch = Get-HostArch
if( $hostArch -ne $arch ) {
# this is a hack required to cross compile arm64
# since lemon.exe in the build tree must be run to generate the compilable grammer
# so you must run a native compile first
# TODO consider doing a offshoot targeted compile of the lemon target on the host arch
$hostArchBuildName = Get-Build-Name -Arch $hostArch -BuildType $buildType
$hostArchcmakeBuildFolder = "build/$hostArchBuildName"
$lemonPath = Join-Path -Path $hostArchcmakeBuildFolder -ChildPath "thirdparty/lemon/lemon.exe"
$cmakeArgs += "-DLEMON_EXE=$lemonPath";
}
}
$cmakeArgs += '-S';
$cmakeArgs += '.';
# ignore cmake dumping to stderr
# the boost warnings will cause it to treat it as a failed command
& cmake $cmakeArgs 2>&1
if ($LastExitCode -ne 0) {
Write-Error "Failure generating cmake"
Pop-Location
Exit [ExitCodes]::CMakeGenerationFailure
} else {
Write-Host "Invoking cmake build" -ForegroundColor Yellow
& {
$ErrorActionPreference = 'SilentlyContinue'
cmake --build $cmakeBuildFolder -j 2>&1 | % ToString
}
if ($LastExitCode -ne 0) {
Write-Error "Failure with cmake build"
Pop-Location
Exit [ExitCodes]::CMakeBuildFailure
} else {
Write-Host "Build complete" -ForegroundColor Green
}
}
#restore path
Pop-Location
}
function script:Get-Source-Repo ([string] $sourceKey, [string] $defaultRepo) {
if( $buildConfig.sources.PSObject.Properties.Match($sourceKey) )
{
if( $buildConfig.sources.$sourceKey.PSobject.Properties.Name -contains "repo" )
{
return $buildConfig.sources.$sourceKey.repo
}
}
return $defaultRepo
}
function script:Get-Source-Ref ([string] $sourceKey) {
if( $buildConfig.sources.PSObject.Properties.Match($sourceKey) )
{
return $buildConfig.sources.$sourceKey.ref
}
else {
return ""
}
}
function Start-Build {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[ValidateSet('Release', 'Debug')]
[string]$buildType = 'Release',
[Parameter(Mandatory=$False)]
[bool]$latest = $False
)
# NOTE Change to your own fork
Get-Source -url https://gitlab.com/Liangtie/kicad.git `
-dest (Get-Source-Path kicad) `
-sourceType git `
-latest $latest `
-ref (Get-Source-Ref -sourceKey "kicad")
Get-Source -url https://gitlab.com/kicad/libraries/kicad-symbols.git `
-dest (Get-Source-Path kicad-symbols) `
-sourceType git `
-latest $latest `
-ref (Get-Source-Ref -sourceKey "symbols")
Get-Source -url https://gitlab.com/kicad/libraries/kicad-footprints.git `
-dest (Get-Source-Path kicad-footprints) `
-sourceType git `
-latest $latest `
-ref (Get-Source-Ref -sourceKey "footprints")
Get-Source -url https://gitlab.com/kicad/libraries/kicad-packages3D.git `
-dest (Get-Source-Path kicad-packages3D) `
-sourceType git `
-latest $latest `
-ref (Get-Source-Ref -sourceKey "3dmodels")
Get-Source -url https://gitlab.com/kicad/libraries/kicad-templates.git `
-dest (Get-Source-Path kicad-templates) `
-sourceType git `
-latest $latest `
-ref (Get-Source-Ref -sourceKey "templates")
Build-KiCad -arch $arch -buildType $buildType
Build-Library-Source -arch $arch -buildType $buildType -libraryFolderName kicad-symbols
Build-Library-Source -arch $arch -buildType $buildType -libraryFolderName kicad-footprints
Build-Library-Source -arch $arch -buildType $buildType -libraryFolderName kicad-packages3D
Build-Library-Source -arch $arch -buildType $buildType -libraryFolderName kicad-templates
}
function Start-Init {
# The progress bar slows down download performance by absurd amounts, turn it off
$ProgressPreference = 'SilentlyContinue'
if( -Not $settings.UseMsvcCmake )
{
Get-Tool -ToolName "CMake" `
-Url $cmakeDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $cmakeFolder) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "cmake.zip") `
-Checksum $cmakeChecksum `
-ExtractZip $true `
-ZipRelocate $False `
-ExtractInSupportRoot $True
Get-Tool -ToolName "Ninja" `
-Url $ninjaDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $ninjaFolder) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "ninja.zip") `
-Checksum $ninjaChecksum `
-ExtractZip $true `
-ZipRelocate $False `
-ExtractInSupportRoot $False
}
Get-Tool -ToolName "swigwin" `
-Url $swigwinDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $swigwinFolder) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "$swigwinFolder.zip") `
-Checksum $swigwinChecksum `
-ExtractZip $true `
-ExtractInSupportRoot $True
Get-Tool -ToolName "doxygen" `
-Url $doxygenDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $doxygenFolderName) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "$doxygenFolderName.zip") `
-Checksum $doxygenChecksum `
-ExtractZip $true `
-ExtractInSupportRoot $False
Get-Tool -ToolName "nsis" `
-Url $nsisDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $nsisFolderName) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "nsis.zip") `
-Checksum $nsisChecksum `
-ExtractZip $true `
-ExtractInSupportRoot $True
Get-Tool -ToolName "vswhere" `
-Url $vswhereDownload `
-DestPath ($BuilderPaths.SupportRoot+'vswhere.exe') `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "vswhere.exe") `
-Checksum $vswhereChecksum `
-ExtractZip $False
Get-Tool -ToolName "sentry-cli" `
-Url $sentryCliDownload `
-DestPath ($BuilderPaths.SupportRoot+'sentry-cli.exe') `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "sentry-cli.exe") `
-Checksum $sentryCliChecksum `
-ExtractZip $False
Get-Tool -ToolName "gettext" `
-Url $gettextDownload `
-DestPath ($BuilderPaths.SupportRoot+"$gettextFolderName/") `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "$gettextFolderName.zip") `
-Checksum $gettextChecksum `
-ExtractZip $true
Get-Tool -ToolName "s5cmd" `
-Url $s5cmdDownload `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath $s5cmdFolderName) `
-DownloadPath (Join-Path -Path $BuilderPaths.DownloadsRoot -ChildPath "s5cmd.zip") `
-Checksum $s5cmdChecksum `
-ExtractZip $true `
-ZipRelocate $False `
-ExtractInSupportRoot $False
if( -not (Test-Path $azureSignToolPath ) ) {
if (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue) {
dotnet tool install AzureSignTool --version $azureSignToolVersion --tool-path $azureSignToolPath
}
else {
Write-Warning "Missing dotnet executable to install azure sign tool"
}
}
$7zaSource = Join-Path -Path $PSScriptRoot -ChildPath "\support\7z2201-extra.zip"
Expand-Tool -ToolName "7za" `
-SourcePath $7zaSource `
-DestPath (Join-Path -Path $BuilderPaths.SupportRoot -ChildPath "$7zaFolderName/")
# Restore progress bar
$ProgressPreference = 'Continue'
}
function Get-Vcpkg-Triplet {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$Arch
)
$triplet = "$Arch-windows"
return $triplet;
}
function Get-Build-Name {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$Arch,
[Parameter(Mandatory=$True)]
[ValidateSet('Release', 'Debug')]
[string]$BuildType
)
return "$Arch-windows-$BuildType";
}
function Build-Vcpkg {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[Arch]$arch,
[Parameter(Mandatory=$False)]
[bool]$latest = $True
)
$vcpkgPath = $settings["VcpkgPath"]
if( $vcpkgPath -eq "" ) {
Write-Host "No vcpkg path provided" -ForegroundColor DarkYellow
$vcpkgPath = Join-Path -Path $PSScriptRoot -ChildPath vcpkg
# for now, destroy the folder if it isnt configured on our side
if( Test-Path $vcpkgPath ) {
Remove-Item $vcpkgPath -Recurse -Force
}
Write-Host "Checking out vcpkg to $vcpkgPath" -ForegroundColor Yellow
if($buildConfig.vcpkg.manifest_mode) {
git clone https://github.com/microsoft/vcpkg.git $vcpkgPath
} else {
git clone https://gitlab.com/kicad/packaging/vcpkg.git $vcpkgPath
}
Set-Config -VcpkgPath $vcpkgPath
# get vcpkg alias updated
Set-Aliases
}
# Bootstrap vcpkg
Push-Location $vcpkgPath
if( $latest ) {
Write-Host "Updating vcpkg git repo" -ForegroundColor Yellow
git fetch
if($buildConfig.vcpkg.manifest_mode) {
Write-Host "vcpkg.manifest_mode: start git reset --hard $vcpkgCommit"
git checkout master
git reset --hard $vcpkgCommit
} else {
git checkout kicad
git reset --hard origin/kicad
}
}
Write-Host "start git pull vcpkg port"
git pull
.\bootstrap-vcpkg.bat
Set-Aliases
& vcpkg upgrade
& vcpkg update
if(-Not $buildConfig.vcpkg.manifest_mode) {
# Setup dependencies
$triplet = Get-Vcpkg-Triplet -Arch $arch
$dependencies = @()
$dependencies = $dependencies + $buildConfig.vcpkg.dependencies
# Format the dependencies with the triplet
for ($i = 0; $i -lt $dependencies.Count; $i++) {
$dependencies[$i] = $dependencies[$i]+":$triplet"
}
vcpkg install $dependencies --recurse 2>&1
if ($LastExitCode -ne 0) {
Write-Error "Failure installing vcpkg ports"
Exit [ExitCodes]::VcpkgInstallPortsFailure
} else {
Write-Host "vcpkg ports installed/updated" -ForegroundColor Green
}
# Unforunately, theres no "install or upgrade" command
# We can safely however run ugprade and install and it'll just do nothing in the worse case
vcpkg upgrade $dependencies --no-dry-run 2>&1
if ($LastExitCode -ne 0) {
Write-Error "Failure upgrading vcpkg ports"
Exit [ExitCodes]::VcpkgInstallPortsFailure
} else {
Write-Host "vcpkg ports installed/updated" -ForegroundColor Green
}
}
Pop-Location
}
function Get-KiCad-CommitHash {
Push-Location (Get-Source-Path kicad)
$commitHash = (git rev-parse --verify HEAD)
Pop-Location
return $commitHash
}
function Get-KiCad-PackageVersion {
if( $buildConfig.train -eq "stable" )
{
return $buildConfig.package_version
}
else
{
Push-Location (Get-Source-Path kicad)
$revCount = (git describe --long --tags | %{$_ -replace "-","."} )
Pop-Location
return "$revCount"
}
}
function Get-KiCad-Version {
$srcFile = Join-Path -Path (Get-Source-Path kicad) -ChildPath "CMakeModules\KiCadVersion.cmake"
if( -not (Test-Path $srcFile ) )
{
# new path in master
$srcFile = Join-Path -Path (Get-Source-Path kicad) -ChildPath "cmake\KiCadVersion.cmake"
}
$result = Select-String -Path $srcFile -Pattern '(?<=KICAD_SEMANTIC_VERSION\s")([0-9]+).([0-9])+' -AllMatches | % { $_.Matches } | % { $_.Value } | Select-Object -First 1
return $result
}
function Get-KiCad-PackageVersion-Msix {
$base = Get-KiCad-Version
Push-Location (Get-Source-Path kicad)
$revCount = (git describe --long --tags | %{$_ -replace "-","."} )
Pop-Location
# SPECIAL REQUIREMENT
# MSIX package version must always end with .0
return "${base}.${revCount}.0"
}
function Sign-File {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string]$File
)
Write-Host "Signing file: $File" -ForegroundColor Blue
if( $SignAKV ) {
azuresigntool sign -kvt "$AKVTenantId" -fd sha256 `
-td sha256 -kvu "$AKVUrl" -kvi "$AKVAppId" `
-kvs "$AKVAppSecret" -kvc "$AKVCertName" `
-tr http://timestamp.digicert.com -q "$File"
if ($LastExitCode -ne 0) {
Write-Error "Error signing file $File, exit code $LastExitCode"
Exit [ExitCodes]::SignFail
}
}