Fixes, tweaks and improvements for Linux support
This commit is contained in:
@@ -2140,7 +2140,12 @@ int32 LinuxPlatform::RunProcess(const StringView& cmdLine, const StringView& wor
|
|||||||
void* LinuxPlatform::LoadLibrary(const Char* filename)
|
void* LinuxPlatform::LoadLibrary(const Char* filename)
|
||||||
{
|
{
|
||||||
const StringAsANSI<> filenameANSI(filename);
|
const StringAsANSI<> filenameANSI(filename);
|
||||||
return dlopen(filenameANSI.Get(), RTLD_LAZY);
|
void* result = dlopen(filenameANSI.Get(), RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
LOG(Error, "Failed to load {0} because {1}", filename, String(dlerror()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxPlatform::FreeLibrary(void* handle)
|
void LinuxPlatform::FreeLibrary(void* handle)
|
||||||
|
|||||||
@@ -43,8 +43,22 @@ namespace Flax.Build.Platforms
|
|||||||
{
|
{
|
||||||
base.SetupCompileCppFilesArgs(graph, options, args, outputPath);
|
base.SetupCompileCppFilesArgs(graph, options, args, outputPath);
|
||||||
|
|
||||||
|
// Hide all symbols by default
|
||||||
|
args.Add("-fvisibility-inlines-hidden");
|
||||||
|
args.Add("-fvisibility-ms-compat");
|
||||||
|
|
||||||
args.Add(string.Format("-target {0}", ArchitectureName));
|
args.Add(string.Format("-target {0}", ArchitectureName));
|
||||||
args.Add(string.Format("--sysroot=\"{0}\"", ToolsetRoot.Replace('\\', '/')));
|
args.Add(string.Format("--sysroot=\"{0}\"", ToolsetRoot.Replace('\\', '/')));
|
||||||
|
|
||||||
|
if (Architecture == TargetArchitecture.x64)
|
||||||
|
{
|
||||||
|
args.Add("-mssse3");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.Target.OutputType == TargetOutputType.Library)
|
||||||
|
{
|
||||||
|
args.Add("-fPIC");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -53,8 +67,6 @@ namespace Flax.Build.Platforms
|
|||||||
base.SetupLinkFilesArgs(graph, options, args, outputFilePath);
|
base.SetupLinkFilesArgs(graph, options, args, outputFilePath);
|
||||||
|
|
||||||
args.Add("-Wl,-rpath,\"\\$ORIGIN\"");
|
args.Add("-Wl,-rpath,\"\\$ORIGIN\"");
|
||||||
|
|
||||||
// Speed up build
|
|
||||||
//args.Add("-Wl,--as-needed");
|
//args.Add("-Wl,--as-needed");
|
||||||
args.Add("-Wl,--hash-style=gnu");
|
args.Add("-Wl,--hash-style=gnu");
|
||||||
//args.Add("-Wl,--build-id");
|
//args.Add("-Wl,--build-id");
|
||||||
@@ -62,7 +74,7 @@ namespace Flax.Build.Platforms
|
|||||||
if (options.LinkEnv.Output == LinkerOutput.SharedLibrary)
|
if (options.LinkEnv.Output == LinkerOutput.SharedLibrary)
|
||||||
{
|
{
|
||||||
args.Add("-shared");
|
args.Add("-shared");
|
||||||
args.Add(string.Format("-soname=\"{0}\"", Path.GetFileNameWithoutExtension(outputFilePath)));
|
args.Add(string.Format("-Wl,-soname=\"{0}\"", Path.GetFileNameWithoutExtension(outputFilePath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Add(string.Format("-target {0}", ArchitectureName));
|
args.Add(string.Format("-target {0}", ArchitectureName));
|
||||||
|
|||||||
@@ -255,12 +255,8 @@ namespace Flax.Build.Platforms
|
|||||||
var commonArgs = new List<string>();
|
var commonArgs = new List<string>();
|
||||||
SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath);
|
SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath);
|
||||||
{
|
{
|
||||||
// Don't link, only compile code
|
|
||||||
commonArgs.Add("-c");
|
commonArgs.Add("-c");
|
||||||
|
|
||||||
commonArgs.Add("-pipe");
|
commonArgs.Add("-pipe");
|
||||||
|
|
||||||
// C++ compile flags
|
|
||||||
commonArgs.Add("-x");
|
commonArgs.Add("-x");
|
||||||
commonArgs.Add("c++");
|
commonArgs.Add("c++");
|
||||||
commonArgs.Add("-std=c++14");
|
commonArgs.Add("-std=c++14");
|
||||||
@@ -280,25 +276,6 @@ namespace Flax.Build.Platforms
|
|||||||
if (compileEnvironment.TreatWarningsAsErrors)
|
if (compileEnvironment.TreatWarningsAsErrors)
|
||||||
commonArgs.Add("-Wall -Werror");
|
commonArgs.Add("-Wall -Werror");
|
||||||
|
|
||||||
/*
|
|
||||||
if (ShouldUseLibcxx(CompileEnvironment.Architecture))
|
|
||||||
{
|
|
||||||
commonArgs.Add("-nostdinc++");
|
|
||||||
commonArgs.Add("-I" + "ThirdParty/Linux/LibCxx/include/");
|
|
||||||
commonArgs.Add("-I" + "ThirdParty/Linux/LibCxx/include/c++/v1");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
if (Options.HasFlag(LinuxToolChainOptions.EnableAddressSanitizer))
|
|
||||||
commonArgs.Add("-fsanitize=address");
|
|
||||||
|
|
||||||
if (Options.HasFlag(LinuxToolChainOptions.EnableThreadSanitizer))
|
|
||||||
commonArgs.Add("-fsanitize=thread");
|
|
||||||
|
|
||||||
if (Options.HasFlag(LinuxToolChainOptions.EnableUndefinedBehaviorSanitizer))
|
|
||||||
commonArgs.Add("-fsanitize=undefined");
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: compileEnvironment.IntrinsicFunctions
|
// TODO: compileEnvironment.IntrinsicFunctions
|
||||||
// TODO: compileEnvironment.FunctionLevelLinking
|
// TODO: compileEnvironment.FunctionLevelLinking
|
||||||
// TODO: compileEnvironment.FavorSizeOrSpeed
|
// TODO: compileEnvironment.FavorSizeOrSpeed
|
||||||
@@ -469,12 +446,18 @@ namespace Flax.Build.Platforms
|
|||||||
foreach (var library in linkEnvironment.InputLibraries)
|
foreach (var library in linkEnvironment.InputLibraries)
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(library);
|
var dir = Path.GetDirectoryName(library);
|
||||||
|
var ext = Path.GetExtension(library);
|
||||||
if (string.IsNullOrEmpty(dir))
|
if (string.IsNullOrEmpty(dir))
|
||||||
{
|
{
|
||||||
args.Add(string.Format("\"-l{0}\"", library));
|
args.Add(string.Format("\"-l{0}\"", library));
|
||||||
}
|
}
|
||||||
else if (library.EndsWith(".so"))
|
else if (string.IsNullOrEmpty(ext))
|
||||||
{
|
{
|
||||||
|
// Skip executable
|
||||||
|
}
|
||||||
|
else if (ext == ".so")
|
||||||
|
{
|
||||||
|
// Link against dynamic library
|
||||||
task.PrerequisiteFiles.Add(library);
|
task.PrerequisiteFiles.Add(library);
|
||||||
libraryPaths.Add(dir);
|
libraryPaths.Add(dir);
|
||||||
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));
|
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));
|
||||||
@@ -488,12 +471,18 @@ namespace Flax.Build.Platforms
|
|||||||
foreach (var library in options.Libraries)
|
foreach (var library in options.Libraries)
|
||||||
{
|
{
|
||||||
var dir = Path.GetDirectoryName(library);
|
var dir = Path.GetDirectoryName(library);
|
||||||
|
var ext = Path.GetExtension(library);
|
||||||
if (string.IsNullOrEmpty(dir))
|
if (string.IsNullOrEmpty(dir))
|
||||||
{
|
{
|
||||||
args.Add(string.Format("\"-l{0}\"", library));
|
args.Add(string.Format("\"-l{0}\"", library));
|
||||||
}
|
}
|
||||||
else if (library.EndsWith(".so"))
|
else if (string.IsNullOrEmpty(ext))
|
||||||
{
|
{
|
||||||
|
// Skip executable
|
||||||
|
}
|
||||||
|
else if (ext == ".so")
|
||||||
|
{
|
||||||
|
// Link against dynamic library
|
||||||
task.PrerequisiteFiles.Add(library);
|
task.PrerequisiteFiles.Add(library);
|
||||||
libraryPaths.Add(dir);
|
libraryPaths.Add(dir);
|
||||||
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));
|
args.Add(string.Format("\"-l{0}\"", GetLibName(library)));
|
||||||
|
|||||||
Reference in New Issue
Block a user