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
16 changes: 16 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 Expand Up @@ -78,3 +91,6 @@ jobs:
removeArtifacts: true
artifacts: "artifacts/**/*.nupkg"
token: ${{ secrets.GITHUB_TOKEN }}



132 changes: 120 additions & 12 deletions build/BuildWIndowsTask.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Cake.Common.Build.AppVeyor;

namespace BuildScripts;

[TaskName("Build Windows")]
Expand All @@ -9,8 +11,14 @@ public sealed class BuildWindowsTask : FrostingTask<BuildContext>

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,22 +29,23 @@ 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
var prefixFlag = $"--prefix=\"{dependencyDir}\"";
var prefixFlag = $"--prefix='{dependencyDir}'";

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

// Get the FFprobe ./configure flags specific for this windows build
var configureFlags = GetFFProbConfigureFlags(context);
var configureFlags = GetFFProbConfigureFlags(context, "windows-x64");

// The command to execute in order to run the shell environment (mingw) needed for this build.
var shellCommandPath = @"C:\msys64\usr\bin\bash.exe";
Expand All @@ -45,7 +54,9 @@ public override void Run(BuildContext context)
// arguments of this instance for each command.
var processSettings = new ProcessSettings();


// Build libogg
context.Information("Building libogg...");
processSettings.WorkingDirectory = "./ogg";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
Expand All @@ -59,6 +70,7 @@ public override void Run(BuildContext context)
context.StartProcess(shellCommandPath, processSettings);

// build libvorbis
context.Information("Building libvorbis...");
processSettings.WorkingDirectory = "./vorbis";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
Expand All @@ -72,6 +84,7 @@ public override void Run(BuildContext context)
context.StartProcess(shellCommandPath, processSettings);

// build lame
context.Information("Building lame...");
processSettings.WorkingDirectory = "./lame";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
Expand All @@ -83,6 +96,7 @@ public override void Run(BuildContext context)
context.StartProcess(shellCommandPath, processSettings);

// Build ffprobe
context.Information("Building ffprobe...");
processSettings.WorkingDirectory = "./ffmpeg";
processSettings.Arguments = $"-c \"{exports} make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
Expand All @@ -94,11 +108,105 @@ public override void Run(BuildContext context)
context.StartProcess(shellCommandPath, processSettings);
}

private static string GetFFProbConfigureFlags(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")));
context.CreateDirectory(artifactDir);

// 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 -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';";
// Convert Windows dependency path to MSYS2 Unix path for pkg-config

var pkgConfigExport = $"export PKG_CONFIG_PATH='{depPathUnix}/lib/pkgconfig';";
var exports = $"{pathExport}{cFlagsExport}{ccFlagsExport}{cxxFlagsExport}{ldFlagsExport}{pkgConfigExport}";

var artifactPathUnix = artifactDir.FullPath.Replace("\\", "/").Replace("C:", "/c");
// 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 ffprobe build so that the binary is output to the artifacts directory.
var binDirFlag = $"--bindir='{artifactPathUnix}'";

// Get the FFprobe ./configure flags specific for this windows build
var configureFlags = GetFFProbConfigureFlags(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 ffprobe
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 GetFFProbConfigureFlags(BuildContext context, string rid = "windows-x64")
{
var ignoreCommentsAndNewLines = (string line) => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#');
var configureFlags = context.FileReadLines("ffprobe.config").Where(ignoreCommentsAndNewLines);
var osConfigureFlags = context.FileReadLines($"ffprobe.windows-x64.config").Where(ignoreCommentsAndNewLines);
var osConfigureFlags = context.FileReadLines($"ffprobe.{rid}.config").Where(ignoreCommentsAndNewLines);
return string.Join(' ', configureFlags) + " " + string.Join(' ', osConfigureFlags);
}
}

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

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

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