You're breathtaking!

This commit is contained in:
Wojtek Figat
2020-12-07 23:40:54 +01:00
commit 6fb9eee74c
5143 changed files with 1153594 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
using System;
using System.IO;
namespace Flax.Build.Platforms
{
/// <summary>
/// The Linux build platform implementation.
/// </summary>
/// <seealso cref="Platform" />
/// <seealso cref="UnixPlatform" />
public class LinuxPlatform : UnixPlatform
{
/// <inheritdoc />
public override TargetPlatform Target => TargetPlatform.Linux;
/// <inheritdoc />
public override bool HasRequiredSDKsInstalled { get; }
/// <inheritdoc />
public override bool HasSharedLibrarySupport => true;
/// <summary>
/// The toolchain folder root.
/// </summary>
public readonly string ToolchainRoot;
/// <summary>
/// True if use platform native system compiler instead of external package.
/// </summary>
public readonly bool UseSystemCompiler;
/// <summary>
/// Initializes a new instance of the <see cref="LinuxPlatform"/> class.
/// </summary>
public LinuxPlatform()
{
// Check if use system compiler
if (Environment.OSVersion.Platform == PlatformID.Unix && Which("clang++-7") != null)
{
// Build toolchain root path
ToolchainRoot = string.Empty;
Log.Verbose("Using native Linux toolchain (system compiler)");
HasRequiredSDKsInstalled = true;
UseSystemCompiler = true;
}
else
{
// Check if Linux toolchain is installed
string toolchainName = "v13_clang-7.0.1-centos7";
string toolchainsRoot = Environment.GetEnvironmentVariable("LINUX_TOOLCHAINS_ROOT");
if (string.IsNullOrEmpty(toolchainsRoot) || !Directory.Exists(Path.Combine(toolchainsRoot, toolchainName)))
{
if (string.IsNullOrEmpty(toolchainsRoot))
{
Log.Warning("Missing Linux Toolchain. Cannot build for Linux platform.");
}
return;
}
// Build toolchain root path
ToolchainRoot = Path.Combine(toolchainsRoot, toolchainName).Replace('\\', '/');
Log.Verbose(string.Format("Found Linux Toolchain at {0}", ToolchainRoot));
HasRequiredSDKsInstalled = true;
UseSystemCompiler = false;
}
}
/// <inheritdoc />
protected override Toolchain CreateToolchain(TargetArchitecture architecture)
{
return new LinuxToolchain(this, architecture);
}
/// <inheritdoc />
public override bool CanBuildPlatform(TargetPlatform platform)
{
switch (platform)
{
case TargetPlatform.Linux: return true;
case TargetPlatform.Android: return AndroidSdk.Instance.IsValid && AndroidNdk.Instance.IsValid;
default: return false;
}
}
}
}

View File

@@ -0,0 +1,89 @@
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.IO;
using Flax.Build.Graph;
using Flax.Build.NativeCpp;
namespace Flax.Build.Platforms
{
/// <summary>
/// The Linux build toolchain implementation.
/// </summary>
/// <seealso cref="Platform" />
/// <seealso cref="UnixToolchain" />
public class LinuxToolchain : UnixToolchain
{
/// <summary>
/// Initializes a new instance of the <see cref="LinuxToolchain"/> class.
/// </summary>
/// <param name="platform">The platform.</param>
/// <param name="architecture">The target architecture.</param>
public LinuxToolchain(LinuxPlatform platform, TargetArchitecture architecture)
: base(platform, architecture, platform.ToolchainRoot, platform.UseSystemCompiler)
{
// Setup system paths
SystemIncludePaths.Add(Path.Combine(ToolsetRoot, "usr", "include"));
SystemIncludePaths.Add(Path.Combine(ToolsetRoot, "include", "c++", "5.2.0"));
SystemIncludePaths.Add(Path.Combine(ToolsetRoot, "lib", "clang", "7.0.1", "include"));
}
/// <inheritdoc />
public override void SetupEnvironment(BuildOptions options)
{
base.SetupEnvironment(options);
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_LINUX");
if (Architecture == TargetArchitecture.x64)
options.CompileEnv.PreprocessorDefinitions.Add("_LINUX64");
}
/// <inheritdoc />
protected override void SetupCompileCppFilesArgs(TaskGraph graph, BuildOptions options, List<string> args, string outputPath)
{
base.SetupCompileCppFilesArgs(graph, options, args, outputPath);
args.Add(string.Format("-target {0}", ArchitectureName));
args.Add(string.Format("--sysroot=\"{0}\"", ToolsetRoot.Replace('\\', '/')));
}
/// <inheritdoc />
protected override void SetupLinkFilesArgs(TaskGraph graph, BuildOptions options, List<string> args, string outputFilePath)
{
base.SetupLinkFilesArgs(graph, options, args, outputFilePath);
// Speed up build
//args.Add("-Wl,--as-needed");
args.Add("-Wl,--hash-style=gnu");
//args.Add("-Wl,--build-id");
if (options.LinkEnv.Output == LinkerOutput.SharedLibrary)
{
args.Add("-shared");
args.Add(string.Format("-soname=\"{0}\"", Path.GetFileNameWithoutExtension(outputFilePath)));
}
args.Add(string.Format("-target {0}", ArchitectureName));
args.Add(string.Format("--sysroot=\"{0}\"", ToolsetRoot.Replace('\\', '/')));
// Link core libraries
args.Add("-pthread");
args.Add("-ldl");
args.Add("-lrt");
// Link X11
args.Add("-L/usr/X11R6/lib");
args.Add("-lX11");
args.Add("-lXcursor");
args.Add("-lXinerama");
}
/// <inheritdoc />
protected override Task CreateBinary(TaskGraph graph, BuildOptions options, string outputFilePath)
{
var task = base.CreateBinary(graph, options, outputFilePath);
task.CommandPath = ClangPath;
return task;
}
}
}