Add engine version defines for build scripts (eg. FLAX_1_6_OR_NEWER)
This commit is contained in:
@@ -39,15 +39,20 @@ namespace Flax.Build
|
||||
public readonly List<string> SourceFiles = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// The external user assembly references to use while compiling
|
||||
/// The external user assembly references to use while compiling.
|
||||
/// </summary>
|
||||
public readonly List<Assembly> Assemblies = new List<Assembly>();
|
||||
|
||||
/// <summary>
|
||||
/// The external user assembly file names to use while compiling
|
||||
/// The external user assembly file names to use while compiling.
|
||||
/// </summary>
|
||||
public readonly List<string> References = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// The C# preprocessor symbols to use while compiling.
|
||||
/// </summary>
|
||||
public readonly List<string> PreprocessorSymbols = new List<string>();
|
||||
|
||||
public Assembler(List<string> sourceFiles, string cacheFolderPath = null)
|
||||
{
|
||||
SourceFiles.AddRange(sourceFiles);
|
||||
@@ -127,10 +132,11 @@ namespace Flax.Build
|
||||
if (!assembly.IsDynamic)
|
||||
references.Add(assembly.Location);
|
||||
}
|
||||
references.Add(Path.Combine(Directory.GetParent(DefaultReferences[0].Location).FullName, "System.dll"));
|
||||
references.Add(Path.Combine(Directory.GetParent(DefaultReferences[0].Location).FullName, "System.Runtime.dll"));
|
||||
references.Add(Path.Combine(Directory.GetParent(DefaultReferences[0].Location).FullName, "System.Collections.dll"));
|
||||
references.Add(Path.Combine(Directory.GetParent(DefaultReferences[0].Location).FullName, "Microsoft.Win32.Registry.dll"));
|
||||
var stdLibPath = Directory.GetParent(DefaultReferences[0].Location).FullName;
|
||||
references.Add(Path.Combine(stdLibPath, "System.dll"));
|
||||
references.Add(Path.Combine(stdLibPath, "System.Runtime.dll"));
|
||||
references.Add(Path.Combine(stdLibPath, "System.Collections.dll"));
|
||||
references.Add(Path.Combine(stdLibPath, "Microsoft.Win32.Registry.dll"));
|
||||
|
||||
// HACK: C# will give compilation errors if a LIB variable contains non-existing directories
|
||||
Environment.SetEnvironmentVariable("LIB", null);
|
||||
@@ -147,13 +153,12 @@ namespace Flax.Build
|
||||
|
||||
// Run the compilation
|
||||
using var memoryStream = new MemoryStream();
|
||||
|
||||
CSharpParseOptions parseOptions = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp11).WithPreprocessorSymbols(PreprocessorSymbols);
|
||||
var syntaxTrees = new List<SyntaxTree>();
|
||||
foreach (var sourceFile in SourceFiles)
|
||||
{
|
||||
var stringText = SourceText.From(File.ReadAllText(sourceFile), Encoding.UTF8);
|
||||
var parsedSyntaxTree = SyntaxFactory.ParseSyntaxTree(stringText,
|
||||
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp9), sourceFile);
|
||||
var parsedSyntaxTree = SyntaxFactory.ParseSyntaxTree(stringText, parseOptions, sourceFile);
|
||||
syntaxTrees.Add(parsedSyntaxTree);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ namespace Flax.Build
|
||||
using (new ProfileEventScope("CompileRules"))
|
||||
{
|
||||
var assembler = new Assembler(files, Path.Combine(Globals.Root, Configuration.IntermediateFolder));
|
||||
EngineTarget.AddVersionDefines(assembler.PreprocessorSymbols);
|
||||
assembly = assembler.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Flax.Build.Graph;
|
||||
using Flax.Build.NativeCpp;
|
||||
@@ -36,6 +37,19 @@ namespace Flax.Build
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the version defines for the preprocessor (eg. FLAX_1_6_OR_NEWER).
|
||||
/// </summary>
|
||||
/// <param name="defines">Output list.</param>
|
||||
public static void AddVersionDefines(ICollection<string> defines)
|
||||
{
|
||||
var engineVersion = EngineVersion;
|
||||
defines.Add(string.Format("FLAX_{0}", engineVersion.Major));
|
||||
defines.Add(string.Format("FLAX_{0}_{1}", engineVersion.Major, engineVersion.Minor));
|
||||
for (int minor = 1; minor <= engineVersion.Minor; minor++)
|
||||
defines.Add(string.Format("FLAX_{0}_{1}_OR_NEWER", engineVersion.Major, minor));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
|
||||
@@ -24,9 +24,8 @@ namespace Flax.Build
|
||||
options.PublicDependencies.Add("Scripting");
|
||||
|
||||
// Setup scripting API environment
|
||||
var engineVersion = EngineTarget.EngineVersion;
|
||||
AddEngineVersionDefines(engineVersion, options.ScriptingAPI.Defines);
|
||||
AddEngineVersionDefines(engineVersion, options.CompileEnv.PreprocessorDefinitions);
|
||||
EngineTarget.AddVersionDefines(options.ScriptingAPI.Defines);
|
||||
EngineTarget.AddVersionDefines(options.CompileEnv.PreprocessorDefinitions);
|
||||
options.ScriptingAPI.Defines.Add("FLAX");
|
||||
options.ScriptingAPI.Defines.Add("FLAX_ASSERTIONS");
|
||||
if (options.Target.IsEditor)
|
||||
@@ -38,14 +37,6 @@ namespace Flax.Build
|
||||
options.ScriptingAPI.Defines.Add("FLAX_GAME");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddEngineVersionDefines(Version engineVersion, HashSet<string> defines)
|
||||
{
|
||||
defines.Add(string.Format("FLAX_{0}", engineVersion.Major));
|
||||
defines.Add(string.Format("FLAX_{0}_{1}", engineVersion.Major, engineVersion.Minor));
|
||||
for (int minor = 1; minor <= engineVersion.Minor; minor++)
|
||||
defines.Add(string.Format("FLAX_{0}_{1}_OR_NEWER", engineVersion.Major, minor));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user