Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ jobs:
shell: bash
run: |
C:\\msys64\\usr\\bin\\bash.exe -c 'export PATH="/usr/bin:/mingw64/bin:$PATH"; pacman -S --needed --noconfirm mingw-w64-x86_64-toolchain mingw-w64-x86_64-mpg123 mingw-w64-x86_64-gtk2 mingw-w64-x86_64-libogg mingw-w64-x86_64-libvorbis mingw-w64-x86_64-lame mingw-w64-x86_64-pkg-config nasm yasm make base-devel autoconf automake libtool'

- name: Install llvm-mingw for ARM64 cross-compilation
if: runner.os == 'Windows'
shell: pwsh
run: |
$llvmMingwVersion = "20250114"
$url = "https://github.com/mstorsjo/llvm-mingw/releases/download/$llvmMingwVersion/llvm-mingw-$llvmMingwVersion-ucrt-x86_64.zip"
Invoke-WebRequest -Uri $url -OutFile "$env:TEMP\llvm-mingw.zip"
Expand-Archive -Path "$env:TEMP\llvm-mingw.zip" -DestinationPath "C:\llvm-mingw-extract"
if (Test-Path "C:\llvm-mingw") { Remove-Item -Path "C:\llvm-mingw" -Recurse -Force }
Move-Item -Path "C:\llvm-mingw-extract\llvm-mingw-$llvmMingwVersion-ucrt-x86_64" -Destination "C:\llvm-mingw"
Write-Host "llvm-mingw installed to C:\llvm-mingw"

- name: Clone repository
uses: actions/checkout@v4
with:
Expand Down
115 changes: 106 additions & 9 deletions build/BuildWIndowsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ public sealed class BuildWindowsTask : FrostingTask<BuildContext>
public override bool ShouldRun(BuildContext context) => context.IsRunningOnWindows();

public override void Run(BuildContext context)
{
Buildx64(context);
Buildarm64(context);
}

private void Buildx64(BuildContext context)
{
// Absolute path to the artifact directory is needed for flags since they don't allow relative path
var artifactDir = context.MakeAbsolute(new DirectoryPath(context.ArtifactsDir));
var artifactDir = context.MakeAbsolute(new DirectoryPath(System.IO.Path.Combine(context.ArtifactsDir, "windows-x64")));

// The directory that all dependencies that are built manually are output too. Originally this was output to the
// artifacts directory but that started causing issues on the github runners, so it was moved back to the
Expand All @@ -21,12 +27,13 @@ public override void Run(BuildContext context)
// since they would be set for the Windows side of things and not the mingw environment that everything is
// running in. Instead, we'll build an export statement that can be used at the start of every process call to
// ensure the correct environment variables are set for each command executed.
var cFlagsExport = "export CFLAGS=\"-w\";";
var ccFlagsExport = "export CCFLAGS=\"x86_64-w64-mingw32-gcc\";";
var ldFlagsExport = "export LDFLAGS=\"--static\";";
var pathExport = "export PATH=\"/usr/bin:/mingw64/bin:$PATH\";";
var pkgConfigExport = $"export PKG_CONFIG_PATH=\"/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH\";";
var exports = $"{pathExport}{cFlagsExport}{ccFlagsExport}{ldFlagsExport}{pkgConfigExport}";
var cFlagsExport = "export CFLAGS='-w -Wno-error=incompatible-pointer-types';";
var ccFlagsExport = "export CC='x86_64-w64-mingw32-gcc';";
var cxxFlagsExport = "export CXX='x86_64-w64-mingw32-g++';";
var ldFlagsExport = "export LDFLAGS='--static';";
var pathExport = "export PATH='/usr/bin:/mingw64/bin:$PATH';";
var pkgConfigExport = $"export PKG_CONFIG_PATH='/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH';";
var exports = $"{pathExport}{cFlagsExport}{ccFlagsExport}{cxxFlagsExport}{ldFlagsExport}{pkgConfigExport}";

// The --prefix flag used for all ./configure commands to ensure that build dependencies are output to the
// dependency directory specified
Expand Down Expand Up @@ -94,11 +101,101 @@ public override void Run(BuildContext context)
context.StartProcess(shellCommandPath, processSettings);
}

private static string GetFFMpegConfigureFlags(BuildContext context)
private void Buildarm64(BuildContext context)
{
// Absolute path to the artifact directory is needed for flags since they don't allow relative path
var artifactDir = context.MakeAbsolute(new DirectoryPath(System.IO.Path.Combine(context.ArtifactsDir, "windows-arm64")));

// The directory that all dependencies that are built manually are output too. Originally this was output to the
// artifacts directory but that started causing issues on the github runners, so it was moved back to the
// project root directory.
var dependencyDir = context.MakeAbsolute(new DirectoryPath($"{context.ArtifactsDir}/../dependencies-windows-arm64"));

// For Windows build, since we're using mingw environment, we can't set environment variables as normal
// since they would be set for the Windows side of things and not the mingw environment that everything is
// running in. Instead, we'll build an export statement that can be used at the start of every process call to
// ensure the correct environment variables are set for each command executed.
var depPathUnix = dependencyDir.FullPath.Replace("\\", "/").Replace("C:", "/c");
var cFlagsExport = $"export CFLAGS='-w -Wno-error=incompatible-pointer-types -I{depPathUnix}/include';";
var ccFlagsExport = "export CC='aarch64-w64-mingw32-clang';";
var cxxFlagsExport = "export CXX='aarch64-w64-mingw32-clang++';";
var ldFlagsExport = $"export LDFLAGS='--static -L{depPathUnix}/lib';";
var pathExport = "export PATH='/c/llvm-mingw/bin:/usr/bin:/mingw64/bin:$PATH';";
var pkgConfigExport = $"export PKG_CONFIG_PATH='{depPathUnix}/lib/pkgconfig';";
var exports = $"{pathExport}{cFlagsExport}{ccFlagsExport}{cxxFlagsExport}{ldFlagsExport}{pkgConfigExport}";

// The --prefix flag used for all ./configure commands to ensure that build dependencies are output to the
// dependency directory specified
var prefixFlag = $"--prefix='{depPathUnix}'";

// The --bindir flag used in the final ffmpeg build so that the binary is output to the artifacts directory.
var binDirFlag = $"--bindir='{artifactDir}'";

// Get the FFmpeg ./configure flags specific for this windows build
var configureFlags = GetFFMpegConfigureFlags(context, "windows-arm64");

// The command to execute in order to run the shell environment (mingw) needed for this build.
var shellCommandPath = @"C:\msys64\usr\bin\bash.exe";

// Reusuable process settings instance. As each dependency is built, we'll adjust the working directory and
// arguments of this instance for each command.
var processSettings = new ProcessSettings();

// Build libogg
processSettings.WorkingDirectory = "./ogg";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} ./autogen.sh\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} ./configure --host=aarch64-w64-mingw32 --disable-shared {prefixFlag}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make -j{Environment.ProcessorCount}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make install\"";
context.StartProcess(shellCommandPath, processSettings);

// build libvorbis
processSettings.WorkingDirectory = "./vorbis";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} ./autogen.sh\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} ./configure --host=aarch64-w64-mingw32 --disable-examples --disable-docs --disable-shared {prefixFlag}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make -j{Environment.ProcessorCount}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make install\"";
context.StartProcess(shellCommandPath, processSettings);

// build lame
processSettings.WorkingDirectory = "./lame";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} ./configure --host=aarch64-w64-mingw32 --disable-frontend --disable-decoder --disable-shared {prefixFlag}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make -j{Environment.ProcessorCount}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make install\"";
context.StartProcess(shellCommandPath, processSettings);

// Build ffmpeg
processSettings.WorkingDirectory = "./ffmpeg";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
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}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make -j{Environment.ProcessorCount}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"{exports} make install\"";
context.StartProcess(shellCommandPath, processSettings);
}

private static string GetFFMpegConfigureFlags(BuildContext context, string rid = "windows-x64")
{
var ignoreCommentsAndNewLines = (string line) => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#');
var configureFlags = context.FileReadLines("ffmpeg.config").Where(ignoreCommentsAndNewLines);
var osConfigureFlags = context.FileReadLines($"ffmpeg.windows-x64.config").Where(ignoreCommentsAndNewLines);
var osConfigureFlags = context.FileReadLines($"ffmpeg.{rid}.config").Where(ignoreCommentsAndNewLines);
return string.Join(' ', configureFlags) + " " + string.Join(' ', osConfigureFlags);
}
}

2 changes: 1 addition & 1 deletion buildscripts
14 changes: 14 additions & 0 deletions ffmpeg.windows-arm64.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
########################################################################################################################
### Toolchain Options
########################################################################################################################
--arch=aarch64
--extra-cflags='-DHAVE_UNISTD_H=0'
--extra-ldflags=-static
--target-os=mingw32

########################################################################################################################
### Optimization Options
########################################################################################################################
--enable-asm
--disable-x86asm
--enable-neon
3 changes: 2 additions & 1 deletion ffmpeg.windows-x64.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
### Toolchain Options
########################################################################################################################
--arch=x86_64
--extra-cflags="-DHAVE_UNISTD_H=0"
--extra-cflags='-DHAVE_UNISTD_H=0'
--extra-ldflags=-static
--target-os=mingw32

########################################################################################################################
Expand Down