Skip to content

Commit 0f7c122

Browse files
Allows locking FFMpeg version based on commit (#3)
* 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
1 parent c4bce14 commit 0f7c122

23 files changed

Lines changed: 507 additions & 1420 deletions

.github/workflows/main.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
os: [windows-latest, macos-latest, ubuntu-latest]
12+
os: [windows-latest, ubuntu-latest, macos-latest]
1313
fail-fast: false
1414
steps:
1515
- name: Expose GitHub Runtime
1616
uses: crazy-max/ghaction-github-runtime@v3
1717

1818
- name: Install Mac Dependencies
1919
if: runner.os == 'macOS'
20-
run: brew install nasm
20+
run: |
21+
brew install nasm autoconf automake libtool
2122
2223
- name: Install Linux Dependencies
2324
if: runner.os == 'Linux'
24-
run: sudo apt-get install nasm
25+
run: sudo apt-get install nasm autoconf automake libtool
2526

27+
- name: Install Windows Dependencies
28+
if: runner.os == 'Windows'
29+
shell: bash
30+
run: |
31+
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'
2632
- name: Clone repository
2733
uses: actions/checkout@v4
2834
with:
@@ -33,6 +39,7 @@ jobs:
3339
env:
3440
ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }}
3541
ACTIONS_RUNTIME_URL: "${{ env.ACTIONS_RUNTIME_URL }}"
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3643

3744
deploy:
3845
name: deploy
@@ -51,6 +58,9 @@ jobs:
5158
with:
5259
submodules: recursive
5360

61+
- name: Rename License File
62+
run: mv ./ffmpeg/COPYING.GPLv2 ./ffmpeg/LICENSE
63+
5464
- name: Run CAKE
5565
run: dotnet run --project ./build/Build.csproj -- --target=Package --universalBinary=true --toolname=FFMpeg --executablename=ffmpeg --commandname=mgcb-ffmpeg --licensepath=ffmpeg/LICENSE
5666
env:

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,8 @@ tools/
404404
artifacts/
405405
artifacts-*/
406406

407-
.idea
407+
.idea
408+
409+
# Build dependencies
410+
dependencies-*/
411+
temp/

.gitmodules

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@
44
[submodule "buildscripts"]
55
path = buildscripts
66
url = https://github.com/MonoGame/MonoGame.Tool.BuildScripts.git
7+
[submodule "ffmpeg"]
8+
path = ffmpeg
9+
url = https://github.com/ffmpeg/ffmpeg.git
10+
[submodule "vorbis"]
11+
path = vorbis
12+
url = https://gitlab.xiph.org/xiph/vorbis.git
13+
[submodule "ogg"]
14+
path = ogg
15+
url = https://gitlab.xiph.org/xiph/ogg.git
16+
[submodule "lame"]
17+
path = lame
18+
url = https://github.com/monogame/monogame.mirror.lame

build/BuildLinuxTask.cs

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,81 @@ public sealed class BuildLinuxTask : FrostingTask<BuildContext>
99

1010
public override void Run(BuildContext context)
1111
{
12-
// Patch vcpkg files for linux build
13-
context.StartProcess("patch", "./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
14-
context.StartProcess("patch", "./buildscripts/vcpkg/triplets/x64-linux.cmake ./patches/x64-linux-cmake.patch");
12+
// 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));
14+
var dependencyDir = context.MakeAbsolute(new DirectoryPath($"{context.ArtifactsDir}/../dependencies-linux-x64"));
15+
var prefixFlag = $"--prefix=\"{dependencyDir}\"";
16+
var hostFlag = "--host=\"x86_64-linux-gnu\"";
17+
var binDirFlag = $"--bindir=\"{artifactDir}\"";
1518

16-
// Bootstrap vcpkg
17-
context.StartProcess("buildscripts/vcpkg/bootstrap-vcpkg.sh");
19+
var envVariables = new Dictionary<string, string>
20+
{
21+
{"CFLAGS", $"-w -I{dependencyDir}/include"},
22+
{"CPPFLAGS", $"-I{dependencyDir}/include"},
23+
{"LDFLAGS", $"--static -L{dependencyDir}/lib"},
24+
{"PKG_CONFIG_PATH", $"{dependencyDir}/lib/pkgconfig"}
25+
};
1826

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

22-
// Copy build to artifacts
23-
context.CopyFile("buildscripts/vcpkg/installed/x64-linux/tools/ffmpeg/ffmpeg", $"{context.ArtifactsDir}/ffmpeg");
31+
var shellCommandPath = "sh";
32+
33+
// Build libogg
34+
processSettings.WorkingDirectory = "./ogg";
35+
processSettings.Arguments = $"-c \"make distclean\"";
36+
context.StartProcess(shellCommandPath, processSettings);
37+
processSettings.Arguments = $"-c \"./autogen.sh\"";
38+
context.StartProcess(shellCommandPath, processSettings);
39+
processSettings.Arguments = $"-c \"./configure --disable-shared {prefixFlag} {hostFlag}\"";
40+
context.StartProcess(shellCommandPath, processSettings);
41+
processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\"";
42+
context.StartProcess(shellCommandPath, processSettings);
43+
processSettings.Arguments = $"-c \"make install\"";
44+
context.StartProcess(shellCommandPath, processSettings);
45+
46+
// build libvorbis
47+
processSettings.WorkingDirectory = "./vorbis";
48+
processSettings.Arguments = $"-c \"make distclean\"";
49+
context.StartProcess(shellCommandPath, processSettings);
50+
processSettings.Arguments = $"-c \"./autogen.sh\"";
51+
context.StartProcess(shellCommandPath, processSettings);
52+
processSettings.Arguments = $"-c \"./configure --disable-examples --disable-docs --disable-shared {prefixFlag} {hostFlag}\"";
53+
context.StartProcess(shellCommandPath, processSettings);
54+
processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\"";
55+
context.StartProcess(shellCommandPath, processSettings);
56+
processSettings.Arguments = $"-c \"make install\"";
57+
context.StartProcess(shellCommandPath, processSettings);
58+
59+
// build lame
60+
processSettings.WorkingDirectory = "./lame";
61+
processSettings.Arguments = $"-c \"make distclean\"";
62+
context.StartProcess(shellCommandPath, processSettings);
63+
processSettings.Arguments = $"-c \"./configure --disable-frontend --disable-decoder --disable-shared {prefixFlag} {hostFlag}\"";
64+
context.StartProcess(shellCommandPath, processSettings);
65+
processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\"";
66+
context.StartProcess(shellCommandPath, processSettings);
67+
processSettings.Arguments = $"-c \"make install\"";
68+
context.StartProcess(shellCommandPath, processSettings);
69+
70+
// Build ffmpeg
71+
processSettings.WorkingDirectory = "./ffmpeg";
72+
processSettings.Arguments = $"-c \"make distclean\"";
73+
context.StartProcess(shellCommandPath, processSettings);
74+
processSettings.Arguments = $"-c \"./configure {binDirFlag} {configureFlags}\"";
75+
context.StartProcess(shellCommandPath, processSettings);
76+
processSettings.Arguments = $"-c \"make -j{Environment.ProcessorCount}\"";
77+
context.StartProcess(shellCommandPath, processSettings);
78+
processSettings.Arguments = $"-c \"make install\"";
79+
context.StartProcess(shellCommandPath, processSettings);
2480
}
2581

26-
public override void Finally(BuildContext context)
82+
private static string GetFFMpegConfigureFlags(BuildContext context)
2783
{
28-
// Ensure we revert the patched files so when running/testing locally they are put back in original state
29-
context.StartProcess("patch", "-R ./buildscripts/vcpkg/ports/ffmpeg/portfile.cmake ./patches/ffmpeg-portfile.patch");
30-
context.StartProcess("patch", "-R ./buildscripts/vcpkg/triplets/x64-linux.cmake ./patches/x64-linux-cmake.patch");
84+
var ignoreCommentsAndNewLines = (string line) => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#');
85+
var configureFlags = context.FileReadLines("ffmpeg.config").Where(ignoreCommentsAndNewLines);
86+
var osConfigureFlags = context.FileReadLines($"ffmpeg.linux-x64.config").Where(ignoreCommentsAndNewLines);
87+
return string.Join(' ', configureFlags) + " " + string.Join(' ', osConfigureFlags);
3188
}
3289
}

0 commit comments

Comments
 (0)