Add improved dll import/export attributes injection when building binary modules

This commit is contained in:
Wojtek Figat
2021-02-25 13:02:13 +01:00
parent b193a7abc4
commit 6f12dc8567
11 changed files with 27 additions and 16 deletions

View File

@@ -2,8 +2,6 @@
#pragma once
#include "Engine/Core/Compiler.h"
struct Vector2;
struct Vector3;
struct Vector4;

View File

@@ -4,8 +4,6 @@
#if COMPILE_WITH_NAV_MESH_BUILDER
#include "Engine/Core/Compiler.h"
class Scene;
/// <summary>

View File

@@ -2,8 +2,6 @@
#pragma once
#include "Engine/Core/Compiler.h"
struct RenderContext;
struct RenderView;
class ParticleEmitter;

View File

@@ -3,7 +3,6 @@
#pragma once
#include "Engine/Core/Singleton.h"
#include "Engine/Core/Compiler.h"
class MClass;
class MMethod;

View File

@@ -2,8 +2,6 @@
#pragma once
#include "Engine/Core/Compiler.h"
#define FLAXENGINE_NAME "FlaxEngine"
#define FLAXENGINE_VERSION Version(1, 0, 6216)
#define FLAXENGINE_VERSION_TEXT "1.0.6216"

View File

@@ -2005,8 +2005,6 @@ namespace Flax.Build.Bindings
contents.AppendLine();
contents.AppendLine("#pragma once");
contents.AppendLine();
contents.AppendLine("#include \"Engine/Core/Compiler.h\"");
contents.AppendLine();
contents.AppendLine($"#define {binaryModuleNameUpper}_NAME \"{binaryModuleName}\"");
if (version.Build == -1)
contents.AppendLine($"#define {binaryModuleNameUpper}_VERSION Version({version.Major}, {version.Minor})");

View File

@@ -141,7 +141,7 @@ namespace Flax.Build
mainModuleOptions.SourcePaths.Add(mainModule.FolderPath);
mainModule.Setup(mainModuleOptions);
mainModuleOptions.MergeSourcePathsIntoSourceFiles();
mainModuleOptions.CompileEnv.PreprocessorDefinitions.Add("FLAXENGINE_API=DLLIMPORT");
mainModuleOptions.CompileEnv.PreprocessorDefinitions.Add("FLAXENGINE_API=" + buildOptions.Toolchain.DllImport);
Builder.BuildModuleInner(buildData, mainModule, mainModuleOptions, false);
// Link executable

View File

@@ -695,14 +695,14 @@ namespace Flax.Build
if (buildData.Target.LinkType == TargetLinkType.Modular)
{
// Export symbols from binary module
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(binaryModuleNameUpper + (target.UseSymbolsExports ? "_API=DLLEXPORT" : "_API="));
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(binaryModuleNameUpper + (target.UseSymbolsExports ? "_API=" + toolchain.DllExport : "_API="));
}
else
{
// Export symbols from all binary modules in the build
foreach (var q in buildData.BinaryModules)
{
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Key.ToUpperInvariant() + (target.UseSymbolsExports ? "_API=DLLEXPORT" : "_API="));
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Key.ToUpperInvariant() + (target.UseSymbolsExports ? "_API=" + toolchain.DllExport : "_API="));
}
}
@@ -715,7 +715,7 @@ namespace Flax.Build
if (buildData.Target.LinkType == TargetLinkType.Modular)
{
// Import symbols from referenced binary module
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Name.ToUpperInvariant() + "_API=DLLIMPORT");
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Name.ToUpperInvariant() + "_API=" + toolchain.DllImport);
// Link against the referenced binary module
if (toolchain.UseImportLibraryWhenLinking)
@@ -726,7 +726,7 @@ namespace Flax.Build
else if (target.UseSymbolsExports)
{
// Export symbols from referenced binary module to be visible further
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Name.ToUpperInvariant() + "_API=DLLEXPORT");
moduleOptions.CompileEnv.PreprocessorDefinitions.Add(q.Name.ToUpperInvariant() + "_API=" + toolchain.DllExport);
}
else
{

View File

@@ -41,6 +41,16 @@ namespace Flax.Build
/// </summary>
public virtual bool GeneratesImportLibraryWhenLinking => false;
/// <summary>
/// Gets the compiler attribute for symbols exported to shared library (dll file).
/// </summary>
public abstract string DllExport { get; }
/// <summary>
/// Gets the compiler attribute for symbols imported from shared library (dll file).
/// </summary>
public abstract string DllImport { get; }
/// <summary>
/// Initializes a new instance of the <see cref="Toolchain"/> class.
/// </summary>

View File

@@ -195,6 +195,12 @@ namespace Flax.Build.Platforms
}
}
/// <inheritdoc />
public override string DllExport => "__attribute__ ((__visibility__ (\"default\")))";
/// <inheritdoc />
public override string DllImport => "";
/// <inheritdoc />
public override void LogInfo()
{

View File

@@ -330,6 +330,12 @@ namespace Flax.Build.Platforms
/// <inheritdoc />
public override bool GeneratesImportLibraryWhenLinking => true;
/// <inheritdoc />
public override string DllExport => "__declspec(dllexport)";
/// <inheritdoc />
public override string DllImport => "__declspec(dllimport)";
/// <inheritdoc />
public override void LogInfo()
{