Add support for C++ scripting on platforms that don't support referencing executable file when linking shared library (eg. Linux)
This commit is contained in:
@@ -37,7 +37,6 @@ public class Editor : EditorModule
|
||||
base.Setup(options);
|
||||
|
||||
options.PublicDependencies.Add("Engine");
|
||||
options.PrivateDependencies.Add("Main");
|
||||
options.PrivateDependencies.Add("pugixml");
|
||||
options.PrivateDependencies.Add("UniversalAnalytics");
|
||||
options.PrivateDependencies.Add("ContentImporters");
|
||||
|
||||
@@ -51,7 +51,6 @@ public class FlaxGame : EngineTarget
|
||||
// Build engine as DLL to be linked in the game UWP project
|
||||
if (options.Platform.Target == TargetPlatform.XboxOne || options.Platform.Target == TargetPlatform.UWP)
|
||||
{
|
||||
OutputType = TargetOutputType.Library;
|
||||
options.LinkEnv.Output = LinkerOutput.SharedLibrary;
|
||||
options.LinkEnv.GenerateWindowsMetadata = true;
|
||||
options.LinkEnv.GenerateDocumentation = true;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
namespace Flax.Build
|
||||
{
|
||||
@@ -14,7 +16,7 @@ namespace Flax.Build
|
||||
private static Version _engineVersion;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the engine version (from Version.h in the engine source).
|
||||
/// Gets the engine version.
|
||||
/// </summary>
|
||||
public static Version EngineVersion
|
||||
{
|
||||
@@ -40,5 +42,120 @@ namespace Flax.Build
|
||||
Modules.Add("Main");
|
||||
Modules.Add("Engine");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetOutputFilePath(BuildOptions options, TargetOutputType? outputType)
|
||||
{
|
||||
// If building engine executable for platform doesn't support referencing it when linking game shared libraries
|
||||
if (UseSymbolsExports && (outputType ?? OutputType) == TargetOutputType.Executable && !options.Platform.HasExecutableFileReferenceSupport)
|
||||
{
|
||||
// Build into shared library
|
||||
outputType = TargetOutputType.Library;
|
||||
}
|
||||
|
||||
return base.GetOutputFilePath(options, outputType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetupTargetEnvironment(BuildOptions options)
|
||||
{
|
||||
base.SetupTargetEnvironment(options);
|
||||
|
||||
// If building engine executable for platform doesn't support referencing it when linking game shared libraries
|
||||
if (UseSymbolsExports && OutputType == TargetOutputType.Executable && !options.Platform.HasExecutableFileReferenceSupport)
|
||||
{
|
||||
// Build into shared library
|
||||
options.LinkEnv.Output = LinkerOutput.SharedLibrary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PreBuild(TaskGraph graph, BuildOptions buildOptions)
|
||||
{
|
||||
// If building engine executable for platform doesn't support referencing it when linking game shared libraries
|
||||
if (UseSymbolsExports && OutputType == TargetOutputType.Executable && !buildOptions.Platform.HasExecutableFileReferenceSupport)
|
||||
{
|
||||
// Don't link Main module into shared library
|
||||
Modules.Remove("Main");
|
||||
}
|
||||
|
||||
base.PreBuild(graph, buildOptions);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PostBuild(TaskGraph graph, BuildOptions buildOptions)
|
||||
{
|
||||
base.PostBuild(graph, buildOptions);
|
||||
|
||||
// If building engine executable for platform doesn't support referencing it when linking game shared libraries
|
||||
if (UseSymbolsExports && OutputType == TargetOutputType.Executable && !buildOptions.Platform.HasExecutableFileReferenceSupport)
|
||||
{
|
||||
// Build additional executable with Main module only that uses shared library
|
||||
using (new ProfileEventScope("BuildExecutable"))
|
||||
{
|
||||
BuildMainExecutable(graph, buildOptions);
|
||||
}
|
||||
|
||||
// Restore state from PreBuild
|
||||
Modules.Add("Main");
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildMainExecutable(TaskGraph graph, BuildOptions buildOptions)
|
||||
{
|
||||
var outputPath = Path.Combine(buildOptions.OutputFolder, buildOptions.Platform.GetLinkOutputFileName(OutputName, LinkerOutput.Executable));
|
||||
var exeBuildOptions = Builder.GetBuildOptions(this, buildOptions.Platform, buildOptions.Toolchain, buildOptions.Architecture, buildOptions.Configuration, buildOptions.WorkingDirectory);
|
||||
exeBuildOptions.LinkEnv.Output = LinkerOutput.Executable;
|
||||
var rules = Builder.GenerateRulesAssembly();
|
||||
var buildData = new Builder.BuildData
|
||||
{
|
||||
Rules = rules,
|
||||
Target = this,
|
||||
Graph = graph,
|
||||
TargetOptions = exeBuildOptions,
|
||||
Platform = buildOptions.Platform,
|
||||
Toolchain = buildOptions.Toolchain,
|
||||
Architecture = buildOptions.Architecture,
|
||||
Configuration = buildOptions.Configuration,
|
||||
};
|
||||
|
||||
// Build Main module
|
||||
var mainModule = rules.GetModule("Main");
|
||||
var mainModuleOutputPath = Path.Combine(exeBuildOptions.IntermediateFolder, mainModule.Name);
|
||||
if (!IsPreBuilt && !Directory.Exists(mainModuleOutputPath))
|
||||
Directory.CreateDirectory(mainModuleOutputPath);
|
||||
var mainModuleOptions = new BuildOptions
|
||||
{
|
||||
Target = this,
|
||||
Platform = buildOptions.Platform,
|
||||
Toolchain = buildOptions.Toolchain,
|
||||
Architecture = buildOptions.Architecture,
|
||||
Configuration = buildOptions.Configuration,
|
||||
CompileEnv = (CompileEnvironment)exeBuildOptions.CompileEnv.Clone(),
|
||||
LinkEnv = (LinkEnvironment)exeBuildOptions.LinkEnv.Clone(),
|
||||
IntermediateFolder = mainModuleOutputPath,
|
||||
OutputFolder = mainModuleOutputPath,
|
||||
WorkingDirectory = exeBuildOptions.WorkingDirectory,
|
||||
HotReloadPostfix = exeBuildOptions.HotReloadPostfix,
|
||||
};
|
||||
mainModuleOptions.SourcePaths.Add(mainModule.FolderPath);
|
||||
mainModule.Setup(mainModuleOptions);
|
||||
mainModuleOptions.MergeSourcePathsIntoSourceFiles();
|
||||
mainModuleOptions.CompileEnv.PreprocessorDefinitions.Add("FLAXENGINE_API=DLLIMPORT");
|
||||
Builder.BuildModuleInner(buildData, mainModule, mainModuleOptions, false);
|
||||
|
||||
// Link executable
|
||||
exeBuildOptions.LinkEnv.InputLibraries.Add(Path.Combine(buildOptions.OutputFolder, buildOptions.Platform.GetLinkOutputFileName(OutputName, LinkerOutput.SharedLibrary)));
|
||||
foreach (var e in mainModuleOptions.OutputFiles)
|
||||
exeBuildOptions.LinkEnv.InputFiles.Add(e);
|
||||
foreach (var e in mainModuleOptions.DependencyFiles)
|
||||
exeBuildOptions.DependencyFiles.Add(e);
|
||||
foreach (var e in mainModuleOptions.OptionalDependencyFiles)
|
||||
exeBuildOptions.OptionalDependencyFiles.Add(e);
|
||||
exeBuildOptions.Libraries.AddRange(mainModuleOptions.Libraries);
|
||||
exeBuildOptions.DelayLoadLibraries.AddRange(mainModuleOptions.DelayLoadLibraries);
|
||||
exeBuildOptions.ScriptingAPI.Add(mainModuleOptions.ScriptingAPI);
|
||||
buildOptions.Toolchain.LinkFiles(graph, exeBuildOptions, outputPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ namespace Flax.Build
|
||||
Architectures = new[]
|
||||
{
|
||||
TargetArchitecture.x64,
|
||||
TargetArchitecture.x86,
|
||||
};
|
||||
ConfigurationName = "Editor";
|
||||
GlobalDefinitions.Add("USE_EDITOR");
|
||||
|
||||
@@ -180,6 +180,23 @@ namespace Flax.Build
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
/// <returns>The list of modules to use for build (unique items).</returns>
|
||||
public static Dictionary<Module, BuildOptions> CollectModules(RulesAssembly rules, Platform platform, Target target, BuildOptions targetBuildOptions, Toolchain toolchain, TargetArchitecture architecture, TargetConfiguration configuration)
|
||||
{
|
||||
return CollectModules(rules, platform, target, targetBuildOptions, toolchain, architecture, configuration, target.Modules);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collects the modules required to build (includes dependencies).
|
||||
/// </summary>
|
||||
/// <param name="rules">The rules.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="targetBuildOptions">The target build options.</param>
|
||||
/// <param name="platform">The platform.</param>
|
||||
/// <param name="toolchain">The toolchain.</param>
|
||||
/// <param name="architecture">The architecture.</param>
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
/// <param name="moduleNames">The list of root modules to start collection.</param>
|
||||
/// <returns>The list of modules to use for build (unique items).</returns>
|
||||
public static Dictionary<Module, BuildOptions> CollectModules(RulesAssembly rules, Platform platform, Target target, BuildOptions targetBuildOptions, Toolchain toolchain, TargetArchitecture architecture, TargetConfiguration configuration, IEnumerable<string> moduleNames)
|
||||
{
|
||||
var buildData = new BuildData
|
||||
{
|
||||
@@ -193,7 +210,7 @@ namespace Flax.Build
|
||||
};
|
||||
|
||||
// Collect all modules
|
||||
foreach (var moduleName in target.Modules)
|
||||
foreach (var moduleName in moduleNames)
|
||||
{
|
||||
var module = rules.GetModule(moduleName);
|
||||
if (module != null)
|
||||
@@ -259,7 +276,7 @@ namespace Flax.Build
|
||||
return moduleOptions;
|
||||
}
|
||||
|
||||
private static void BuildModuleInner(BuildData buildData, Module module, BuildOptions moduleOptions)
|
||||
internal static void BuildModuleInner(BuildData buildData, Module module, BuildOptions moduleOptions, bool withApi = true)
|
||||
{
|
||||
// Inherit build environment from dependent modules
|
||||
foreach (var moduleName in moduleOptions.PrivateDependencies)
|
||||
@@ -337,7 +354,7 @@ namespace Flax.Build
|
||||
cppFiles.Add(moduleOptions.SourceFiles[i]);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(module.BinaryModuleName))
|
||||
if (!string.IsNullOrEmpty(module.BinaryModuleName) && withApi)
|
||||
{
|
||||
// Generate scripting bindings
|
||||
using (new ProfileEventScope("GenerateBindings"))
|
||||
@@ -396,7 +413,7 @@ namespace Flax.Build
|
||||
}
|
||||
}
|
||||
|
||||
private static void BuildModuleInnerBindingsOnly(BuildData buildData, Module module, BuildOptions moduleOptions)
|
||||
internal static void BuildModuleInnerBindingsOnly(BuildData buildData, Module module, BuildOptions moduleOptions)
|
||||
{
|
||||
// Inherit build environment from dependent modules
|
||||
foreach (var moduleName in moduleOptions.PrivateDependencies)
|
||||
@@ -751,7 +768,9 @@ namespace Flax.Build
|
||||
using (new ProfileEventScope("BuildBindings"))
|
||||
{
|
||||
if (!buildData.Target.IsPreBuilt)
|
||||
{
|
||||
BuildTargetBindings(rules, graph, buildData);
|
||||
}
|
||||
}
|
||||
|
||||
// Link modules into a target
|
||||
|
||||
@@ -66,11 +66,6 @@ namespace Flax.Build
|
||||
/// </summary>
|
||||
public abstract bool HasRequiredSDKsInstalled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether precompiled headers are supported on that platform.
|
||||
/// </summary>
|
||||
public abstract bool HasPrecompiledHeaderSupport { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether that platform supports shared libraries (dynamic link libraries).
|
||||
/// </summary>
|
||||
@@ -81,6 +76,11 @@ namespace Flax.Build
|
||||
/// </summary>
|
||||
public virtual bool HasModularBuildSupport => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether that platform supports using executable file as a reference when linking shared library. Otherwise, platform enforces monolithic linking or separate shared libraries usage.
|
||||
/// </summary>
|
||||
public virtual bool HasExecutableFileReferenceSupport => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the executable file extension (including leading dot).
|
||||
/// </summary>
|
||||
@@ -102,9 +102,19 @@ namespace Flax.Build
|
||||
public abstract string ProgramDatabaseFileExtension { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the executable and library files prefix.
|
||||
/// Gets the executable files prefix.
|
||||
/// </summary>
|
||||
public virtual string BinaryFilePrefix => string.Empty;
|
||||
public virtual string ExecutableFilePrefix => string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the shared library files prefix.
|
||||
/// </summary>
|
||||
public virtual string SharedLibraryFilePrefix => string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the statuc library files prefix.
|
||||
/// </summary>
|
||||
public virtual string StaticLibraryFilePrefix => string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default project format used by the given platform.
|
||||
@@ -138,10 +148,10 @@ namespace Flax.Build
|
||||
{
|
||||
switch (output)
|
||||
{
|
||||
case LinkerOutput.Executable: return BinaryFilePrefix + name + ExecutableFileExtension;
|
||||
case LinkerOutput.SharedLibrary: return BinaryFilePrefix + name + SharedLibraryFileExtension;
|
||||
case LinkerOutput.Executable: return ExecutableFilePrefix + name + ExecutableFileExtension;
|
||||
case LinkerOutput.SharedLibrary: return SharedLibraryFilePrefix + name + SharedLibraryFileExtension;
|
||||
case LinkerOutput.StaticLibrary:
|
||||
case LinkerOutput.ImportLibrary: return BinaryFilePrefix + name + StaticLibraryFileExtension;
|
||||
case LinkerOutput.ImportLibrary: return StaticLibraryFilePrefix + name + StaticLibraryFileExtension;
|
||||
default: throw new ArgumentOutOfRangeException(nameof(output), output, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,15 @@ namespace Flax.Build.Platforms
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasSharedLibrarySupport => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasExecutableFileReferenceSupport => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ExecutableFileExtension => ".so";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BinaryFilePrefix => "lib";
|
||||
public override string ExecutableFilePrefix => "lib";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AndroidPlatform"/> class.
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Flax.Build.Platforms
|
||||
args.Add("-mssse3");
|
||||
}
|
||||
|
||||
if (options.Target.OutputType == TargetOutputType.Library)
|
||||
if (options.LinkEnv.Output == LinkerOutput.SharedLibrary)
|
||||
{
|
||||
args.Add("-fPIC");
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ namespace Flax.Build.Platforms
|
||||
/// <seealso cref="Platform" />
|
||||
public abstract class UnixPlatform : Platform
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool HasPrecompiledHeaderSupport => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ExecutableFileExtension => string.Empty;
|
||||
|
||||
@@ -26,6 +23,12 @@ namespace Flax.Build.Platforms
|
||||
/// <inheritdoc />
|
||||
public override string ProgramDatabaseFileExtension => string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SharedLibraryFilePrefix => "lib";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string StaticLibraryFilePrefix => "lib";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ProjectFormat DefaultProjectFormat => ProjectFormat.VisualStudioCode;
|
||||
|
||||
|
||||
@@ -122,11 +122,11 @@ namespace Flax.Build.Platforms
|
||||
/// <inheritdoc />
|
||||
public override bool HasRequiredSDKsInstalled => _hasRequiredSDKsInstalled;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasPrecompiledHeaderSupport => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasSharedLibrarySupport => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasExecutableFileReferenceSupport => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ExecutableFileExtension => ".exe";
|
||||
|
||||
Reference in New Issue
Block a user