Skip to content

Commit

Permalink
Allows locking FFMpeg version based on commit (#3)
Browse files Browse the repository at this point in the history
* removed ffmpeg directory

* FFMpeg licked at n7.0

* Added dependency submodules

* patch files no longer needed

* Added config files for ffmpeg builds per platform

* Added command execution helper
This is to assist in executing commands that need specific path and pkgconfig environment variables set before running

* Added BuildSettings
Common settings used for each platform between all builds

* Updated all tasks

* Install windows dependencies in action

* Remove lame submodule so it can be renamed

* Added lame mirror into proper submodule directory

* Simplifying

* Mac Finished for real this time

* Update windows task

* Update .gitignore to ignore new dependencies-* dirs

* Update build scripts so they test before publish

* Ensure windows uses dependencies pkgconfig path

* Test WIndows Only on Github

* Rename to x64

* Update linux build task

* Test ubunut build on github

* Ensure correct dependencies installed for windows build

* Test Windows Only Github

* Test Windows Github Build

* Test WIndows and Linux

* Let's try all three

* Patch mac

* Cleanup, Bounty Submission Point 3

* rename license
The build we are doing will be COPYING.GPLv2 licensed. This renamed the license file so that it's called LICENSE for the dotnet-tool pack that occurs during deploy

* Bounty Submission Point 4

* Remove binaries I used for testing

* Don't need to set initial working directory

* Ignore temp directory

* Use text replace instead of patch file

* Move environment variable set to object initialization

* Use string.IsNullOrWhitespace for empty line check
  • Loading branch information
AristurtleDev authored Apr 30, 2024
1 parent c4bce14 commit 0f7c122
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 1,420 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false
steps:
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3

- 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
with:
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 All @@ -51,6 +58,9 @@ jobs:
with:
submodules: recursive

- name: Rename License File
run: mv ./ffmpeg/COPYING.GPLv2 ./ffmpeg/LICENSE

- name: Run CAKE
run: dotnet run --project ./build/Build.csproj -- --target=Package --universalBinary=true --toolname=FFMpeg --executablename=ffmpeg --commandname=mgcb-ffmpeg --licensepath=ffmpeg/LICENSE
env:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,8 @@ tools/
artifacts/
artifacts-*/

.idea
.idea

# Build dependencies
dependencies-*/
temp/
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 "ogg"]
path = ogg
url = https://gitlab.xiph.org/xiph/ogg.git
[submodule "lame"]
path = lame
url = https://github.com/monogame/monogame.mirror.lame
83 changes: 70 additions & 13 deletions build/BuildLinuxTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,81 @@ public sealed class BuildLinuxTask : FrostingTask<BuildContext>

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 artifactDir = context.MakeAbsolute(new DirectoryPath(context.ArtifactsDir));
var dependencyDir = context.MakeAbsolute(new DirectoryPath($"{context.ArtifactsDir}/../dependencies-linux-x64"));
var prefixFlag = $"--prefix=\"{dependencyDir}\"";
var hostFlag = "--host=\"x86_64-linux-gnu\"";
var binDirFlag = $"--bindir=\"{artifactDir}\"";

// Bootstrap vcpkg
context.StartProcess("buildscripts/vcpkg/bootstrap-vcpkg.sh");
var envVariables = new Dictionary<string, string>
{
{"CFLAGS", $"-w -I{dependencyDir}/include"},
{"CPPFLAGS", $"-I{dependencyDir}/include"},
{"LDFLAGS", $"--static -L{dependencyDir}/lib"},
{"PKG_CONFIG_PATH", $"{dependencyDir}/lib/pkgconfig"}
};

// Perform x64-linux build
context.StartProcess("buildscripts/vcpkg/vcpkg", "install ffmpeg[mp3lame,vorbis]:x64-linux");
var configureFlags = GetFFMpegConfigureFlags(context);
var processSettings = new ProcessSettings();
processSettings.EnvironmentVariables = envVariables;

// Copy build to artifacts
context.CopyFile("buildscripts/vcpkg/installed/x64-linux/tools/ffmpeg/ffmpeg", $"{context.ArtifactsDir}/ffmpeg");
var shellCommandPath = "sh";

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

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

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

// Build ffmpeg
processSettings.WorkingDirectory = "./ffmpeg";
processSettings.Arguments = $"-c \"make distclean\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"./configure {binDirFlag} {configureFlags}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\"";
context.StartProcess(shellCommandPath, processSettings);
processSettings.Arguments = $"-c \"make install\"";
context.StartProcess(shellCommandPath, processSettings);
}

public override void Finally(BuildContext context)
private static string GetFFMpegConfigureFlags(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");
var ignoreCommentsAndNewLines = (string line) => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#');
var configureFlags = context.FileReadLines("ffmpeg.config").Where(ignoreCommentsAndNewLines);
var osConfigureFlags = context.FileReadLines($"ffmpeg.linux-x64.config").Where(ignoreCommentsAndNewLines);
return string.Join(' ', configureFlags) + " " + string.Join(' ', osConfigureFlags);
}
}
Loading

0 comments on commit 0f7c122

Please sign in to comment.