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

Add Linux x86, arm, arm64 Compilation #26

Merged
merged 54 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3764e2b
Analyze available archs
Danielku15 Oct 7, 2023
3add550
Test packages
Danielku15 Oct 7, 2023
c53b893
Check paths
Danielku15 Oct 7, 2023
11a30e1
More test outputs
Danielku15 Oct 7, 2023
f7500f9
Continue on error
Danielku15 Oct 7, 2023
949ebb5
check apt sources
Danielku15 Oct 7, 2023
a080978
Update before install
Danielku15 Oct 7, 2023
f0a770c
print apt mirrors
Danielku15 Oct 7, 2023
c3b0e22
Arch test
Danielku15 Oct 7, 2023
5419754
Check install with container
Danielku15 Oct 7, 2023
1d4aedc
Remove sudo for container
Danielku15 Oct 7, 2023
3738658
Add confirm flag
Danielku15 Oct 7, 2023
354d95c
Use c++/12
Danielku15 Oct 7, 2023
4ad9d3a
Back to c++/11 for ubuntu
Danielku15 Oct 7, 2023
37f4435
test sources modification
Danielku15 Oct 7, 2023
a1d5f7f
Fix sources update
Danielku15 Oct 7, 2023
98adcbf
Source update
Danielku15 Oct 7, 2023
8f191c7
libc6
Danielku15 Oct 7, 2023
8feb06b
libc6-dev
Danielku15 Oct 7, 2023
e763c21
reorder
Danielku15 Oct 7, 2023
c96a693
individual install
Danielku15 Oct 7, 2023
75afb23
More archs
Danielku15 Oct 7, 2023
2b9af87
Indention fix
Danielku15 Oct 7, 2023
fc2e2bd
Indention 2
Danielku15 Oct 7, 2023
7a140b0
Indention 3
Danielku15 Oct 7, 2023
79a3444
Check individual install
Danielku15 Oct 7, 2023
0127e1a
try install with aptitude
Danielku15 Oct 7, 2023
88cf5f5
Remove multilib
Danielku15 Oct 7, 2023
9b96bfc
Try confirm
Danielku15 Oct 7, 2023
79e756c
Prepare linux build
Danielku15 Oct 8, 2023
025fec8
Manual resolve of latest c++ include dir and fallback
Danielku15 Oct 8, 2023
ab26e9e
Cleanup and build order
Danielku15 Oct 8, 2023
a8b9165
No upgrade
Danielku15 Oct 8, 2023
e6e0218
Missing dash
Danielku15 Oct 8, 2023
698f80d
Adjust quoting
Danielku15 Oct 8, 2023
7f36769
Troubleshoot sources
Danielku15 Oct 8, 2023
c7adc60
Generate shell script
Danielku15 Oct 8, 2023
ded9e28
Adjust lib paths
Danielku15 Oct 9, 2023
8567d92
Fix wrong type name
Danielku15 Oct 9, 2023
2b53c04
Add logs to troubleshoot arm build
Danielku15 Oct 9, 2023
1c29850
More test outputs
Danielku15 Oct 9, 2023
9ab90b2
Troubleshoot remaining archs
Danielku15 Oct 9, 2023
653a89a
Trigger again
Danielku15 Oct 9, 2023
c01dbfe
change syntax
Danielku15 Oct 9, 2023
122a551
Modify correct file
Danielku15 Oct 9, 2023
0e4da76
Fix double aptitude
Danielku15 Oct 9, 2023
8bd85db
Remove include path
Danielku15 Oct 11, 2023
adadc5a
Tweak include paths
Danielku15 Oct 11, 2023
653ae0f
Ensure /usr/include is at the end
Danielku15 Oct 11, 2023
7be7a97
Adjust settings
Danielku15 Oct 11, 2023
4cb9abd
Re-add aptitude
Danielku15 Oct 11, 2023
e704773
Fail fast on errors
Danielku15 Oct 11, 2023
7e69050
Correct conditional for arch
Danielku15 Oct 11, 2023
c612496
Install dependencies on JNI build
Danielku15 Oct 11, 2023
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
4 changes: 1 addition & 3 deletions .github/actions/build-skia/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ runs:
- uses: actions/cache/save@v3
with:
path: dist
key: alphaskia-${{ inputs.target-os }}-${{ inputs.architecture }}-${{ inputs.variant }}-${{ github.run_id }}


key: alphaskia-${{ inputs.target-os }}-${{ inputs.architecture }}-${{ inputs.variant }}-${{ github.run_id }}
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
architecture: [x64]
# TODO architecture: [x64, x86, arm64]
architecture: [x64, x86, arm, arm64]
variant: ['shared', 'static']
steps:
- uses: actions/checkout@v3
Expand All @@ -65,8 +64,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# TODO architecture: [x64, x86, arm64]
architecture: [x64]
architecture: [x64, x86, arm, arm64]
variant: ['shared']
steps:
- uses: actions/checkout@v3
Expand Down
116 changes: 96 additions & 20 deletions build/Build.Linux.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Nuke.Common.IO;
using Nuke.Common.Tooling;

partial class Build
{
void InstallDependenciesLinux()
{
if (!IsGitHubActions)
{
return;
}

var bash = ToolResolver.GetPathTool("bash");
var sudo = ToolResolver.GetPathTool("sudo");
var dependenciesScript = SkiaPath / "tools" / "install_dependencies.sh";
if (dependenciesScript.FileExists())
{
bash($"{dependenciesScript}", workingDirectory: SkiaPath);
}

// Linux cross compilation
if (Architecture != Architecture.X64 && TargetOs == TargetOperatingSystem.Linux)
{
var linuxArch = Architecture.LinuxArch;

var crossInstallDependencies = new StringBuilder();
crossInstallDependencies.AppendLine("#!/bin/bash");
crossInstallDependencies.AppendLine("set -e");

// Using aptitude here because github actions runners have quite some packages preinstalled
// which leads to many version conflicts after adding more sources. aptitude can resolve those
// conflicts easier
crossInstallDependencies.AppendLine("echo Install Aptitude");
crossInstallDependencies.AppendLine("apt-get update");
crossInstallDependencies.AppendLine("apt-get install -y aptitude");

crossInstallDependencies.AppendLine($"echo Adding Arch {linuxArch}");
crossInstallDependencies.AppendLine($"dpkg --add-architecture {linuxArch}");

crossInstallDependencies.AppendLine("echo Modifying sources.list");
crossInstallDependencies.AppendLine("sed -i \"s/deb /deb [arch=amd64,i386] /\" /etc/apt/sources.list");
crossInstallDependencies.AppendLine("sed -i \"s/deb-src /deb-src [arch=amd64,i386] /\" /etc/apt/sources.list");

if (Architecture == Architecture.Arm || Architecture == Architecture.Arm64)
{
crossInstallDependencies.AppendLine($"echo 'deb [arch={linuxArch}] http://ports.ubuntu.com/ubuntu-ports/ jammy main multiverse universe' >> /etc/apt/sources.list");
crossInstallDependencies.AppendLine(
$"echo 'deb [arch={linuxArch}] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main multiverse universe' >> /etc/apt/sources.list");
crossInstallDependencies.AppendLine(
$"echo 'deb [arch={linuxArch}] http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main multiverse universe' >> /etc/apt/sources.list");
crossInstallDependencies.AppendLine(
$"echo 'deb [arch={linuxArch}] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main multiverse universe' >> /etc/apt/sources.list");
}
crossInstallDependencies.AppendLine("echo Updating Packages");
crossInstallDependencies.AppendLine("apt-get update");
crossInstallDependencies.AppendLine("echo Installing main build tools");
crossInstallDependencies.AppendLine($"aptitude install -y crossbuild-essential-{linuxArch} libstdc++-11-dev-{linuxArch}-cross");
crossInstallDependencies.AppendLine("echo Installing arch libs");
crossInstallDependencies.AppendLine($"aptitude install -y libfontconfig-dev:{linuxArch} libgl1-mesa-dev:{linuxArch} libglu1-mesa-dev:{linuxArch} freeglut3-dev:{linuxArch}");

var scriptFile = SkiaPath / "tools" / "cross_install_dependencies.sh";
File.WriteAllText(scriptFile, crossInstallDependencies.ToString());
sudo($"bash {scriptFile}");
}
}

void BuildLibAlphaSkiaLinux()
{
var gnArgs = new Dictionary<string, string>();
Expand Down Expand Up @@ -53,28 +119,38 @@ void BuildSkiaLinux(string buildTarget, Dictionary<string, string> gnArgs,
void SetClangLinux(Dictionary<string, string> gnArgs)
{
AppendToFlagList(gnArgs, "extra_cflags", "'-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM'");
AppendToFlagList(gnArgs, "extra_ldflags", "'-static-libstdc++', '-static-libgcc'");

if (Architecture == Architecture.X64)
{
gnArgs["cc"] = "clang";
gnArgs["cxx"] = "'clang++'";
AppendToFlagList(gnArgs, "extra_ldflags", "'-static-libstdc++', '-static-libgcc'");
}
else if (Architecture == Architecture.X86)
{
// TODO
gnArgs["cc"] = "clang";
gnArgs["cxx"] = "'clang++'";
AppendToFlagList(gnArgs, "extra_ldflags", "'-static-libstdc++', '-static-libgcc'");
}
else if (Architecture == Architecture.Arm64) // aka AArch64
gnArgs["cc"] = "clang";
gnArgs["cxx"] = "'clang++'";

var crossCompileToolchainArch = Architecture.LinuxCrossToolchain;
var crossCompileTargetArch = Architecture.LinuxCrossTargetArch;

if (!string.IsNullOrEmpty(crossCompileToolchainArch) && TargetOs == TargetOperatingSystem.Linux)
{
// TODO
gnArgs["cc"] = "clang";
gnArgs["cxx"] = "'clang++'";
AppendToFlagList(gnArgs, "extra_ldflags", "'-static-libstdc++', '-static-libgcc'");
}
var sysroot = $"/usr/{crossCompileToolchainArch}";
var init = $"'--target={crossCompileTargetArch}'";
var bin = $"'-B{sysroot}/bin/' ";
var libs = $"'-L/usr/lib/{crossCompileToolchainArch}'";

// gnArgs["ar"] = "llvm-ar";
AbsolutePath sysRootPath = sysroot;
var newestCpp = Directory.EnumerateDirectories(sysRootPath / "include" / "c++")
.Select(Path.GetFileName)
.OrderByDescending(x => x)
.First();

var includes =
$"'-I{sysroot}/include', " +
$"'-I{sysroot}/include/c++/{newestCpp}', " +
$"'-I{sysroot}/include/c++/{newestCpp}/{crossCompileToolchainArch}', " +
$"'-I/usr/include/{crossCompileToolchainArch}', " +
// non arch specific headers last (as system header to ensure it is really last, normal -I will fail)
$"'-isystem/usr/include/' ";

AppendToFlagList(gnArgs, "extra_asmflags", $"{init}, '-no-integrated-as', {bin}, {includes}");
AppendToFlagList(gnArgs, "extra_ldflags", $"{init}, {bin}, {libs}");
AppendToFlagList(gnArgs, "extra_cflags", $"{init}, {bin}, {includes}");
}
}
}
32 changes: 21 additions & 11 deletions build/Build.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
public class TargetOperatingSystem : Enumeration
{
public static TargetOperatingSystem Windows = new()
{ Value = "windows", SkiaTargetOs = "win", RuntimeIdentifier = "win" };
{ Value = "windows", SkiaTargetOs = "win", RuntimeIdentifier = "win" };

public static TargetOperatingSystem Linux = new()
{ Value = "linux", SkiaTargetOs = "linux", RuntimeIdentifier = "linux" };
{ Value = "linux", SkiaTargetOs = "linux", RuntimeIdentifier = "linux" };

public static TargetOperatingSystem Android = new()
{ Value = "android", SkiaTargetOs = "android", RuntimeIdentifier = "android" };
{ Value = "android", SkiaTargetOs = "android", RuntimeIdentifier = "android" };

public static TargetOperatingSystem MacOs = new()
{ Value = "macos", SkiaTargetOs = "mac", RuntimeIdentifier = "macos" };
{ Value = "macos", SkiaTargetOs = "mac", RuntimeIdentifier = "macos" };

public string SkiaTargetOs { get; private set; }
public string RuntimeIdentifier { get; private set; }
Expand All @@ -33,10 +33,14 @@ public class TargetOperatingSystem : Enumeration
[TypeConverter(typeof(TypeConverter<Architecture>))]
public class Architecture : Enumeration
{
public static Architecture X64 = new() { Value = "x64" };
public static Architecture X86 = new() { Value = "x86" };
public static Architecture Arm = new() { Value = "arm" };
public static Architecture Arm64 = new() { Value = "arm64" };
public static Architecture X64 = new() { Value = "x64", LinuxArch = "amd64", LinuxCrossToolchain = "", LinuxCrossTargetArch = ""};
public static Architecture X86 = new() { Value = "x86", LinuxArch = "i386", LinuxCrossToolchain = "i686-linux-gnu", LinuxCrossTargetArch = "i686-linux-gnu"};
public static Architecture Arm = new() { Value = "arm", LinuxArch = "armhf", LinuxCrossToolchain = "arm-linux-gnueabihf", LinuxCrossTargetArch = "armv7a-linux-gnueabihf"};
public static Architecture Arm64 = new() { Value = "arm64", LinuxArch = "arm64", LinuxCrossToolchain = "aarch64-linux-gnu", LinuxCrossTargetArch = "aarch64-linux-gnu"};

public string LinuxArch { get; private set; }
public string LinuxCrossToolchain { get; private set; }
public string LinuxCrossTargetArch { get; private set; }
}

[TypeConverter(typeof(TypeConverter<Variant>))]
Expand Down Expand Up @@ -130,7 +134,8 @@ partial class Build
.Requires(() => Architecture)
.Requires(() => Variant)
.Requires(() => TargetOs)
.Before(SetupDepotTools) // ensure it runs before any oher targets
// ensure it runs before any oher targets
.Before(SetupDepotTools, PatchSkiaBuildFiles, GitSyncDepsLibAlphaSkia)
.Executes(() =>
{
if (SkipLibAlphaSkia)
Expand All @@ -143,8 +148,7 @@ partial class Build
GitTool("submodule update --init --recursive");
if (OperatingSystem.IsLinux())
{
var dependenciesScript = SkiaPath / "tools" / "install_dependencies.sh";
ToolResolver.GetPathTool("bash")($"{dependenciesScript}", workingDirectory: SkiaPath);
InstallDependenciesLinux();
}
}
})
Expand Down Expand Up @@ -183,6 +187,12 @@ partial class Build
.Requires(() => TargetOs)
.Executes(() =>
{
GitTool("submodule update --init --recursive");
if (OperatingSystem.IsLinux())
{
InstallDependenciesLinux();
}

if (TargetOs == TargetOperatingSystem.Windows)
{
BuildLibAlphaSkiaJniWindows();
Expand Down