Add support for Clang 6, 8, 9 and 10 when building for Linux

This commit is contained in:
Wojtek Figat
2021-02-23 23:28:06 +01:00
parent 84ee882439
commit c0f81a6f0a
5 changed files with 35 additions and 16 deletions

View File

@@ -33,7 +33,7 @@ namespace Flax.Build.Platforms
/// <param name="architecture">The target architecture.</param>
/// <param name="toolchainRoot">The toolchain root path.</param>
public AndroidToolchain(AndroidPlatform platform, TargetArchitecture architecture, string toolchainRoot)
: base(platform, architecture, toolchainRoot, false, string.Empty)
: base(platform, architecture, toolchainRoot, null, string.Empty)
{
var toolchain = ToolsetRoot.Replace('\\', '/');
SystemIncludePaths.Add(Path.Combine(toolchain, "sources/usr/include/c++/v1").Replace('\\', '/'));

View File

@@ -27,23 +27,40 @@ namespace Flax.Build.Platforms
public readonly string ToolchainRoot;
/// <summary>
/// True if use platform native system compiler instead of external package.
/// The compiler name.
/// </summary>
public readonly bool UseSystemCompiler;
public readonly string Compiler;
/// <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)
// Try to use system compiler
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
// Build toolchain root path
// Pick the newest compiler (overriden by specified in command line)
if (Which(Compiler) != null)
Compiler = Configuration.Compiler;
else if (Which("clang++-10") != null)
Compiler = "clang++-10";
else if (Which("clang++-9") != null)
Compiler = "clang++-9";
else if (Which("clang++-8") != null)
Compiler = "clang++-8";
else if (Which("clang++-7") != null)
Compiler = "clang++-7";
else if (Which("clang++-6") != null)
Compiler = "clang++-6";
else if (Which("clang++") != null)
Compiler = "clang++";
}
if (Compiler != null)
{
// System compiler
ToolchainRoot = string.Empty;
Log.Verbose("Using native Linux toolchain (system compiler)");
Log.Verbose($"Using native Linux toolchain (compiler {Compiler})");
HasRequiredSDKsInstalled = true;
UseSystemCompiler = true;
}
else
{
@@ -60,11 +77,10 @@ namespace Flax.Build.Platforms
return;
}
// Build toolchain root path
// Installed toolchain
ToolchainRoot = Path.Combine(toolchainsRoot, toolchainName).Replace('\\', '/');
Log.Verbose(string.Format("Found Linux Toolchain at {0}", ToolchainRoot));
HasRequiredSDKsInstalled = true;
UseSystemCompiler = false;
}
}

View File

@@ -20,12 +20,12 @@ namespace Flax.Build.Platforms
/// <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)
: base(platform, architecture, platform.ToolchainRoot, platform.Compiler)
{
// 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"));
SystemIncludePaths.Add(Path.Combine(ToolsetRoot, "lib", "clang", ClangVersion.Major.ToString(), "include"));
}
/// <inheritdoc />

View File

@@ -46,6 +46,9 @@ namespace Flax.Build.Platforms
/// <returns>The full path or null if not found anything valid.</returns>
public static string Which(string name)
{
if (string.IsNullOrEmpty(name))
return null;
Process proc = new Process
{
StartInfo =

View File

@@ -72,18 +72,18 @@ namespace Flax.Build.Platforms
/// <param name="platform">The platform.</param>
/// <param name="architecture">The target architecture.</param>
/// <param name="toolchainRoots">The root folder for the toolchains installation.</param>
/// <param name="useSystemCompiler">True if use system compiler instead of toolchain.</param>
/// <param name="systemCompiler">The system compiler to use. Null if use toolset root.</param>
/// <param name="toolchainSubDir">The custom toolchain folder location in <paramref name="toolchainRoots"/> directory. If nul the architecture name will be sued.</param>
protected UnixToolchain(UnixPlatform platform, TargetArchitecture architecture, string toolchainRoots, bool useSystemCompiler, string toolchainSubDir = null)
protected UnixToolchain(UnixPlatform platform, TargetArchitecture architecture, string toolchainRoots, string systemCompiler, string toolchainSubDir = null)
: base(platform, architecture)
{
ArchitectureName = GetToolchainName(platform.Target, architecture);
// Build paths
if (useSystemCompiler)
if (systemCompiler != null)
{
ToolsetRoot = toolchainRoots;
ClangPath = UnixPlatform.Which("clang++-7");
ClangPath = UnixPlatform.Which(systemCompiler);
ArPath = UnixPlatform.Which("ar");
LlvmArPath = UnixPlatform.Which("llvm-ar");
RanlibPath = UnixPlatform.Which("ranlib");