Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows locking FFMpeg version based on commit #2

Closed
Closed
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
11 changes: 9 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ jobs:

- name: Install Mac Dependencies
if: runner.os == 'macOS'
run: brew install nasm
run: brew install nasm autoconf automake libtool

- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: sudo apt-get install nasm
run: sudo apt-get install nasm autoconf automake libtool

- name: Install Windows Dependencies
if: runner.os == 'Windows'
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: Clone repository
uses: actions/checkout@v4
Expand All @@ -33,6 +39,7 @@ jobs:
env:
ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }}
ACTIONS_RUNTIME_URL: "${{ env.ACTIONS_RUNTIME_URL }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy:
name: deploy
Expand Down
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@
[submodule "buildscripts"]
path = buildscripts
url = https://github.com/MonoGame/MonoGame.Tool.BuildScripts.git
[submodule "ffmpeg"]
path = ffmpeg
url = https://github.com/ffmpeg/ffmpeg.git
[submodule "vorbis"]
path = vorbis
url = https://gitlab.xiph.org/xiph/vorbis.git
[submodule "MonoGame.Mirror.Lame"]
path = MonoGame.Mirror.Lame
url = https://github.com/MonoGame/MonoGame.Mirror.Lame
[submodule "ogg"]
path = ogg
url = https://gitlab.xiph.org/xiph/ogg.git
1 change: 1 addition & 0 deletions MonoGame.Mirror.Lame
Submodule MonoGame.Mirror.Lame added at b59ea1
42 changes: 26 additions & 16 deletions build/BuildLinuxTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,40 @@ namespace BuildScripts;
[TaskName("Build Linux")]
[IsDependentOn(typeof(PrepTask))]
[IsDependeeOf(typeof(BuildToolTask))]
public sealed class BuildLinuxTask : FrostingTask<BuildContext>
public sealed class BuildLinuxTask : BuildTaskBase
{
public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux();

public override void Run(BuildContext context)
{
// Patch vcpkg files for linux build
context.StartProcess("patch", "./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
context.StartProcess("patch", "./buildscripts/vcpkg/triplets/x64-linux.cmake ./patches/x64-linux-cmake.patch");
// Absolute path to the artifact directory is needed for flags since they don't allow relative path
var absoluteArtifactDir = context.MakeAbsolute(new DirectoryPath(context.ArtifactsDir));

// Bootstrap vcpkg
context.StartProcess("buildscripts/vcpkg/bootstrap-vcpkg.sh");
// Generate common build directory path
var buildDirectory = $"{absoluteArtifactDir}/linux-x86_64";

// Perform x64-linux build
context.StartProcess("buildscripts/vcpkg/vcpkg", "install ffmpeg[mp3lame,vorbis]:x64-linux");
// Create the build settings used by each library build
var buildSettings = new BuildSettings
{
ShellCommand = "sh",
PrefixFlag = buildDirectory,
PkgConfigPath = $"{buildDirectory}/lib/pkgconfig",
HostFlag = "x86_64-linux-gnu",
CFlags = $"-w -I{buildDirectory}/include",
CPPFlags = $"-I{buildDirectory}/include",
LDFlags = $"-L{buildDirectory}/lib --static"
};

// Copy build to artifacts
context.CopyFile("buildscripts/vcpkg/installed/x64-linux/tools/ffmpeg/ffmpeg", $"{context.ArtifactsDir}/ffmpeg");
}
// Get the configuration flags that will be used for the FFMpeg build
var ffmpegConfigureFlags = GetFFMpegConfigureFlags(context, "linux-x86_64");

public override void Finally(BuildContext context)
{
// Ensure we revert the patched files so when running/testing locally they are put back in original state
context.StartProcess("patch", "-R ./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
context.StartProcess("patch", "-R ./buildscripts/vcpkg/triplets/x64-linux.cmake ./patches/x64-linux-cmake.patch");
// Build each library in correct order
BuildOgg(context, buildSettings);
BuildVorbis(context, buildSettings);
BuildLame(context, buildSettings);
BuildFFMpeg(context, buildSettings, ffmpegConfigureFlags);

// Move the built binary from the build directory to the artifact directory
context.MoveFile($"{buildDirectory}/bin/ffmpeg", $"{absoluteArtifactDir}/ffmpeg");
}
}
98 changes: 74 additions & 24 deletions build/BuildMacOSTask.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,92 @@
using System.Runtime.InteropServices;

namespace BuildScripts;

[TaskName("Build macOS")]
[IsDependentOn(typeof(PrepTask))]
[IsDependeeOf(typeof(BuildToolTask))]
public sealed class BuildMacOSTask : FrostingTask<BuildContext>
public sealed class BuildMacOSTask : BuildTaskBase
{
public override bool ShouldRun(BuildContext context) => context.IsRunningOnMacOs();

public override void Run(BuildContext context)
{
// Patch vcpkg files for mac build
context.StartProcess("patch", "./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
context.StartProcess("patch", "./buildscripts/vcpkg/triplets/x64-osx.cmake ./patches/x64-osx-cmake.patch");
context.StartProcess("patch", "./buildscripts/vcpkg/triplets/arm64-osx.cmake ./patches/arm64-osx-cmake.patch");
// Determine which mac architecture(s) to build for.
var buildx8664 = context.IsUniversalBinary || RuntimeInformation.ProcessArchitecture is not Architecture.Arm or Architecture.Arm64;
var buildArm64 = context.IsUniversalBinary || RuntimeInformation.ProcessArchitecture is Architecture.Arm or Architecture.Arm64;

// Absolute path to the artifact directory is needed for flags since they don't allow relative path
var absoluteArtifactDir = context.MakeAbsolute(new DirectoryPath(context.ArtifactsDir));

// Generate common build directory paths for each architectures build artifacts
var x866BuildDirectory = $"{absoluteArtifactDir}/osx-x86_64";
var arm64BuildDirectory = $"{absoluteArtifactDir}/osx-arm64";

// Bootstrap vcpkg
context.StartProcess("buildscripts/vcpkg/bootstrap-vcpkg.sh");
if (buildx8664)
{
// Create the build settings used by each library build
var buildSettings = new BuildSettings()
{
ShellCommand = "zsh",
PrefixFlag = x866BuildDirectory,
PkgConfigPath = $"{x866BuildDirectory}/lib/pkgconfig",
HostFlag = "x86_64-apple-darwin",
CFlags = $"-w -arch x86_64 -I{x866BuildDirectory}/include",
CPPFlags = $"-arch x86_64 -I{x866BuildDirectory}/include",
CXXFlags = "-arch x86_84",
LDFlags = $"-arch x86_64 -L{x866BuildDirectory}/lib"
};

// Perform x64-osx build
context.StartProcess("buildscripts/vcpkg/vcpkg", "install ffmpeg[mp3lame,vorbis]:x64-osx");
// Get the configuration flags that will be used for the FFMpeg build
var x8664FFMpegConfigureFlags = GetFFMpegConfigureFlags(context, "osx-x86_64");

// Perform arm64-osx build
context.StartProcess("buildscripts/vcpkg/vcpkg", "install ffmpeg[mp3lame,vorbis]:arm64-osx");
// Build each library in correct order
BuildOgg(context, buildSettings);
BuildVorbis(context, buildSettings);
BuildLame(context, buildSettings);
BuildFFMpeg(context, buildSettings, x8664FFMpegConfigureFlags);
}

// Use lipo to combine into universal binary and output in the artifacts directory
string x64 = "buildscripts/vcpkg/installed/x64-osx/tools/ffmpeg/ffmpeg";
string arm64 = "buildscripts/vcpkg/installed/arm64-osx/tools/ffmpeg/ffmpeg";
context.StartProcess("lipo", new ProcessSettings()
if (buildArm64)
{
Arguments = $"-create {x64} {arm64} -output {context.ArtifactsDir}/ffmpeg"
});
}
// Create the build settings used by each library build
var buildSettings = new BuildSettings()
{
ShellCommand = "zsh",
PrefixFlag = arm64BuildDirectory,
PkgConfigPath = $"{arm64BuildDirectory}/lib/pkgconfig",
HostFlag = "aarch64-apple-darwin",
CFlags = $"-w -arch arm64 -I{arm64BuildDirectory}/include",
CPPFlags = $"-arch arm64 -I{arm64BuildDirectory}/include",
CXXFlags = "-arch arm64",
LDFlags = $"-arch arm64 -L{arm64BuildDirectory}/lib"
};

public override void Finally(BuildContext context)
{
// Ensure we revert the patched files so when running/testing locally they are put back in original state
context.StartProcess("patch", "-R ./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
context.StartProcess("patch", "-R ./buildscripts/vcpkg/triplets/x64-osx.cmake ./patches/x64-osx-cmake.patch");
context.StartProcess("patch", "-R ./buildscripts/vcpkg/triplets/arm64-osx.cmake ./patches/arm64-osx-cmake.patch");
// Get the configuration flags that will be used for the FFMpeg build
var arm64FFMpegConfigureFlags = GetFFMpegConfigureFlags(context, "osx-arm64");

BuildOgg(context, buildSettings);
BuildVorbis(context, buildSettings);
BuildLame(context, buildSettings);
BuildFFMpeg(context, buildSettings, arm64FFMpegConfigureFlags);
}

// Move the build binary from the build directory to the artifact directory.
// If this is a universal build, we'll need to combine both binaries using lipo and output the result of that.
if (buildx8664 && buildArm64)
{
context.StartProcess("lipo", new ProcessSettings()
{
Arguments = $"-create {x866BuildDirectory}/bin/ffmpeg {arm64BuildDirectory}/bin/ffmpeg -output {absoluteArtifactDir}/ffmpeg"
});
}
else if (buildx8664)
{
context.CopyFile($"{x866BuildDirectory}/bin/ffmpeg", $"{absoluteArtifactDir}/ffmpeg");
}
else
{
context.CopyFile($"{arm64BuildDirectory}/bin/ffmpeg", $"{absoluteArtifactDir}/ffmpeg");
}
}
}
84 changes: 84 additions & 0 deletions build/BuildSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace BuildScripts;

/// <summary>
/// Provides settings to be used when building libraries.
/// </summary>
public class BuildSettings
{
/// <summary>
/// Gets or Sets the command used to start a shell process to execute shell commands. If the command is not part of
/// $PATH then full path to the shell executable should be provided.
/// </summary>
public string ShellCommand { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the CFLAGS environment variable.
/// </summary>
public string CFlags { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the CCFLAGS environment variable.
/// </summary>
public string CCFlags { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the CXXFLAGS environment variable.
/// </summary>
public string CXXFlags { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the CPPFLAGS environment variable.
/// </summary>
public string CPPFlags { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the LDFLAGS environment variable.
/// </summary>
public string LDFlags { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets additional values to add to the existing $PATH variable.
/// </summary>
public string Path { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for the --prefix flag when calling the configure scripts.
/// </summary>
public string PrefixFlag { get; set; } = string.Empty;

/// <summary>
/// Gets or Sets the value to use for hte --host flag when calling the configure scripts.
/// </summary>
public string HostFlag { get; set; } = string.Empty;

/// <summary>
/// Gets or Sts the value to use for the PKG_CONFIG_PATH environment variable.
/// </summary>
public string PkgConfigPath { get; set; } = string.Empty;

/// <summary>
/// Returns a key-value pair dictionary of the environment variables to set for a build.
/// </summary>
public IDictionary<string, string> GetEnvironmentVariables()
{
var environmentVariables = new Dictionary<string, string>();

// Only add those that have a value otherwise it could cause issues for builds.
if (!string.IsNullOrEmpty(CFlags))
environmentVariables.Add("CFLAGS", CFlags);

if (!string.IsNullOrEmpty(CCFlags))
environmentVariables.Add("CCFLAGS", CCFlags);

if (!string.IsNullOrEmpty(CXXFlags))
environmentVariables.Add("CXXFLAGS", CXXFlags);

if (!string.IsNullOrEmpty(CPPFlags))
environmentVariables.Add("CPPFLAGS", CPPFlags);

if (!string.IsNullOrEmpty(LDFlags))
environmentVariables.Add("LDFLAGS", LDFlags);

return environmentVariables;
}
}
Loading
Loading