1+ using Cake . Common . Build . AppVeyor ;
2+
13namespace BuildScripts ;
24
35[ TaskName ( "Build Windows" ) ]
@@ -9,8 +11,14 @@ public sealed class BuildWindowsTask : FrostingTask<BuildContext>
911
1012 public override void Run ( BuildContext context )
1113 {
14+ Buildx64 ( context ) ;
15+ Buildarm64 ( context ) ;
16+ }
17+
18+ private void Buildx64 ( BuildContext context )
19+ {
1220 // Absolute path to the artifact directory is needed for flags since they don't allow relative path
13- var artifactDir = context . MakeAbsolute ( new DirectoryPath ( context . ArtifactsDir ) ) ;
21+ var artifactDir = context . MakeAbsolute ( new DirectoryPath ( System . IO . Path . Combine ( context . ArtifactsDir , "windows-x64" ) ) ) ;
1422
1523 // The directory that all dependencies that are built manually are output too. Originally this was output to the
1624 // artifacts directory but that started causing issues on the github runners, so it was moved back to the
@@ -21,22 +29,23 @@ public override void Run(BuildContext context)
2129 // since they would be set for the Windows side of things and not the mingw environment that everything is
2230 // running in. Instead, we'll build an export statement that can be used at the start of every process call to
2331 // ensure the correct environment variables are set for each command executed.
24- var cFlagsExport = "export CFLAGS=\" -w\" ;" ;
25- var ccFlagsExport = "export CCFLAGS=\" x86_64-w64-mingw32-gcc\" ;" ;
26- var ldFlagsExport = "export LDFLAGS=\" --static\" ;" ;
27- var pathExport = "export PATH=\" /usr/bin:/mingw64/bin:$PATH\" ;" ;
28- var pkgConfigExport = $ "export PKG_CONFIG_PATH=\" /mingw64/lib/pkgconfig:$PKG_CONFIG_PATH\" ;";
29- var exports = $ "{ pathExport } { cFlagsExport } { ccFlagsExport } { ldFlagsExport } { pkgConfigExport } ";
32+ var cFlagsExport = "export CFLAGS='-w -Wno-error=incompatible-pointer-types';" ;
33+ var ccFlagsExport = "export CC='x86_64-w64-mingw32-gcc';" ;
34+ var cxxFlagsExport = "export CXX='x86_64-w64-mingw32-g++';" ;
35+ var ldFlagsExport = "export LDFLAGS='--static';" ;
36+ var pathExport = "export PATH='/usr/bin:/mingw64/bin:$PATH';" ;
37+ var pkgConfigExport = $ "export PKG_CONFIG_PATH='/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH';";
38+ var exports = $ "{ pathExport } { cFlagsExport } { ccFlagsExport } { cxxFlagsExport } { ldFlagsExport } { pkgConfigExport } ";
3039
3140 // The --prefix flag used for all ./configure commands to ensure that build dependencies are output to the
3241 // dependency directory specified
33- var prefixFlag = $ "--prefix=\" { dependencyDir } \" ";
42+ var prefixFlag = $ "--prefix=' { dependencyDir } ' ";
3443
3544 // The --bindir flag used in the final ffprobe build so that the binary is output to the artifacts directory.
36- var binDirFlag = $ "--bindir=\" { artifactDir } \" ";
45+ var binDirFlag = $ "--bindir=' { artifactDir } ' ";
3746
3847 // Get the FFprobe ./configure flags specific for this windows build
39- var configureFlags = GetFFProbConfigureFlags ( context ) ;
48+ var configureFlags = GetFFProbConfigureFlags ( context , "windows-x64" ) ;
4049
4150 // The command to execute in order to run the shell environment (mingw) needed for this build.
4251 var shellCommandPath = @"C:\msys64\usr\bin\bash.exe" ;
@@ -45,7 +54,9 @@ public override void Run(BuildContext context)
4554 // arguments of this instance for each command.
4655 var processSettings = new ProcessSettings ( ) ;
4756
57+
4858 // Build libogg
59+ context . Information ( "Building libogg..." ) ;
4960 processSettings . WorkingDirectory = "./ogg" ;
5061 processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
5162 context . StartProcess ( shellCommandPath , processSettings ) ;
@@ -59,6 +70,7 @@ public override void Run(BuildContext context)
5970 context . StartProcess ( shellCommandPath , processSettings ) ;
6071
6172 // build libvorbis
73+ context . Information ( "Building libvorbis..." ) ;
6274 processSettings . WorkingDirectory = "./vorbis" ;
6375 processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
6476 context . StartProcess ( shellCommandPath , processSettings ) ;
@@ -72,6 +84,7 @@ public override void Run(BuildContext context)
7284 context . StartProcess ( shellCommandPath , processSettings ) ;
7385
7486 // build lame
87+ context . Information ( "Building lame..." ) ;
7588 processSettings . WorkingDirectory = "./lame" ;
7689 processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
7790 context . StartProcess ( shellCommandPath , processSettings ) ;
@@ -83,6 +96,7 @@ public override void Run(BuildContext context)
8396 context . StartProcess ( shellCommandPath , processSettings ) ;
8497
8598 // Build ffprobe
99+ context . Information ( "Building ffprobe..." ) ;
86100 processSettings . WorkingDirectory = "./ffmpeg" ;
87101 processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
88102 context . StartProcess ( shellCommandPath , processSettings ) ;
@@ -94,11 +108,105 @@ public override void Run(BuildContext context)
94108 context . StartProcess ( shellCommandPath , processSettings ) ;
95109 }
96110
97- private static string GetFFProbConfigureFlags ( BuildContext context )
111+ private void Buildarm64 ( BuildContext context )
112+ {
113+ // Absolute path to the artifact directory is needed for flags since they don't allow relative path
114+ var artifactDir = context . MakeAbsolute ( new DirectoryPath ( System . IO . Path . Combine ( context . ArtifactsDir , "windows-arm64" ) ) ) ;
115+ context . CreateDirectory ( artifactDir ) ;
116+
117+ // The directory that all dependencies that are built manually are output too. Originally this was output to the
118+ // artifacts directory but that started causing issues on the github runners, so it was moved back to the
119+ // project root directory.
120+ var dependencyDir = context . MakeAbsolute ( new DirectoryPath ( $ "{ context . ArtifactsDir } /../dependencies-windows-arm64") ) ;
121+
122+ // For Windows build, since we're using mingw environment, we can't set environment variables as normal
123+ // since they would be set for the Windows side of things and not the mingw environment that everything is
124+ // running in. Instead, we'll build an export statement that can be used at the start of every process call to
125+ // ensure the correct environment variables are set for each command executed.
126+ var depPathUnix = dependencyDir . FullPath . Replace ( "\\ " , "/" ) . Replace ( "C:" , "/c" ) ;
127+ var cFlagsExport = $ "export CFLAGS='-w -I{ depPathUnix } /include';";
128+ var ccFlagsExport = "export CC='aarch64-w64-mingw32-clang';" ;
129+ var cxxFlagsExport = "export CXX='aarch64-w64-mingw32-clang++';" ;
130+ var ldFlagsExport = $ "export LDFLAGS='-static -L{ depPathUnix } /lib';";
131+ var pathExport = "export PATH='/c/llvm-mingw/bin:/usr/bin:/mingw64/bin:$PATH';" ;
132+ // Convert Windows dependency path to MSYS2 Unix path for pkg-config
133+
134+ var pkgConfigExport = $ "export PKG_CONFIG_PATH='{ depPathUnix } /lib/pkgconfig';";
135+ var exports = $ "{ pathExport } { cFlagsExport } { ccFlagsExport } { cxxFlagsExport } { ldFlagsExport } { pkgConfigExport } ";
136+
137+ var artifactPathUnix = artifactDir . FullPath . Replace ( "\\ " , "/" ) . Replace ( "C:" , "/c" ) ;
138+ // The --prefix flag used for all ./configure commands to ensure that build dependencies are output to the
139+ // dependency directory specified
140+ var prefixFlag = $ "--prefix='{ depPathUnix } '";
141+
142+ // The --bindir flag used in the final ffprobe build so that the binary is output to the artifacts directory.
143+ var binDirFlag = $ "--bindir='{ artifactPathUnix } '";
144+
145+ // Get the FFprobe ./configure flags specific for this windows build
146+ var configureFlags = GetFFProbConfigureFlags ( context , "windows-arm64" ) ;
147+
148+ // The command to execute in order to run the shell environment (mingw) needed for this build.
149+ var shellCommandPath = @"C:\msys64\usr\bin\bash.exe" ;
150+
151+ // Reusuable process settings instance. As each dependency is built, we'll adjust the working directory and
152+ // arguments of this instance for each command.
153+ var processSettings = new ProcessSettings ( ) ;
154+
155+ // Build libogg
156+ processSettings . WorkingDirectory = "./ogg" ;
157+ processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
158+ context . StartProcess ( shellCommandPath , processSettings ) ;
159+ processSettings . Arguments = $ "-c \" { exports } ./autogen.sh\" ";
160+ context . StartProcess ( shellCommandPath , processSettings ) ;
161+ processSettings . Arguments = $ "-c \" { exports } ./configure --host=aarch64-w64-mingw32 --disable-shared { prefixFlag } \" ";
162+ context . StartProcess ( shellCommandPath , processSettings ) ;
163+ processSettings . Arguments = $ "-c \" { exports } make -j{ Environment . ProcessorCount } \" ";
164+ context . StartProcess ( shellCommandPath , processSettings ) ;
165+ processSettings . Arguments = $ "-c \" { exports } make install\" ";
166+ context . StartProcess ( shellCommandPath , processSettings ) ;
167+
168+ // build libvorbis
169+ processSettings . WorkingDirectory = "./vorbis" ;
170+ processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
171+ context . StartProcess ( shellCommandPath , processSettings ) ;
172+ processSettings . Arguments = $ "-c \" { exports } ./autogen.sh\" ";
173+ context . StartProcess ( shellCommandPath , processSettings ) ;
174+ processSettings . Arguments = $ "-c \" { exports } ./configure --host=aarch64-w64-mingw32 --disable-examples --disable-docs --disable-shared { prefixFlag } \" ";
175+ context . StartProcess ( shellCommandPath , processSettings ) ;
176+ processSettings . Arguments = $ "-c \" { exports } make -j{ Environment . ProcessorCount } \" ";
177+ context . StartProcess ( shellCommandPath , processSettings ) ;
178+ processSettings . Arguments = $ "-c \" { exports } make install\" ";
179+ context . StartProcess ( shellCommandPath , processSettings ) ;
180+
181+ // build lame
182+ processSettings . WorkingDirectory = "./lame" ;
183+ processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
184+ context . StartProcess ( shellCommandPath , processSettings ) ;
185+ processSettings . Arguments = $ "-c \" { exports } ./configure --host=aarch64-w64-mingw32 --disable-frontend --disable-decoder --disable-shared { prefixFlag } \" ";
186+ context . StartProcess ( shellCommandPath , processSettings ) ;
187+ processSettings . Arguments = $ "-c \" { exports } make -j{ Environment . ProcessorCount } \" ";
188+ context . StartProcess ( shellCommandPath , processSettings ) ;
189+ processSettings . Arguments = $ "-c \" { exports } make install\" ";
190+ context . StartProcess ( shellCommandPath , processSettings ) ;
191+
192+ // Build ffprobe
193+ processSettings . WorkingDirectory = "./ffmpeg" ;
194+ processSettings . Arguments = $ "-c \" { exports } make distclean\" ";
195+ context . StartProcess ( shellCommandPath , processSettings ) ;
196+ processSettings . Arguments = $ "-c \" { exports } ./configure --cc=aarch64-w64-mingw32-clang --cxx=aarch64-w64-mingw32-clang++ --cross-prefix=aarch64-w64-mingw32- --pkg-config=pkg-config { binDirFlag } { configureFlags } \" ";
197+ context . StartProcess ( shellCommandPath , processSettings ) ;
198+ processSettings . Arguments = $ "-c \" { exports } make -j{ Environment . ProcessorCount } \" ";
199+ context . StartProcess ( shellCommandPath , processSettings ) ;
200+ processSettings . Arguments = $ "-c \" { exports } make install\" ";
201+ context . StartProcess ( shellCommandPath , processSettings ) ;
202+ }
203+
204+ private static string GetFFProbConfigureFlags ( BuildContext context , string rid = "windows-x64" )
98205 {
99206 var ignoreCommentsAndNewLines = ( string line ) => ! string . IsNullOrWhiteSpace ( line ) && ! line . StartsWith ( '#' ) ;
100207 var configureFlags = context . FileReadLines ( "ffprobe.config" ) . Where ( ignoreCommentsAndNewLines ) ;
101- var osConfigureFlags = context . FileReadLines ( $ "ffprobe.windows-x64 .config") . Where ( ignoreCommentsAndNewLines ) ;
208+ var osConfigureFlags = context . FileReadLines ( $ "ffprobe.{ rid } .config") . Where ( ignoreCommentsAndNewLines ) ;
102209 return string . Join ( ' ' , configureFlags ) + " " + string . Join ( ' ' , osConfigureFlags ) ;
103210 }
104211}
212+
0 commit comments