diff --git a/Source/Tools/Flax.Build/Build/Assembler.cs b/Source/Tools/Flax.Build/Build/Assembler.cs index 3a798144d..26f19774e 100644 --- a/Source/Tools/Flax.Build/Build/Assembler.cs +++ b/Source/Tools/Flax.Build/Build/Assembler.cs @@ -39,15 +39,20 @@ namespace Flax.Build public readonly List SourceFiles = new List(); /// - /// The external user assembly references to use while compiling + /// The external user assembly references to use while compiling. /// public readonly List Assemblies = new List(); /// - /// The external user assembly file names to use while compiling + /// The external user assembly file names to use while compiling. /// public readonly List References = new List(); + /// + /// The C# preprocessor symbols to use while compiling. + /// + public readonly List PreprocessorSymbols = new List(); + public Assembler(List 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(); 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); } diff --git a/Source/Tools/Flax.Build/Build/Builder.Rules.cs b/Source/Tools/Flax.Build/Build/Builder.Rules.cs index d4fb9aa7f..d3e84d613 100644 --- a/Source/Tools/Flax.Build/Build/Builder.Rules.cs +++ b/Source/Tools/Flax.Build/Build/Builder.Rules.cs @@ -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(); } diff --git a/Source/Tools/Flax.Build/Build/EngineTarget.cs b/Source/Tools/Flax.Build/Build/EngineTarget.cs index e2fd54ae6..30e0c92f8 100644 --- a/Source/Tools/Flax.Build/Build/EngineTarget.cs +++ b/Source/Tools/Flax.Build/Build/EngineTarget.cs @@ -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 } } + /// + /// Adds the version defines for the preprocessor (eg. FLAX_1_6_OR_NEWER). + /// + /// Output list. + public static void AddVersionDefines(ICollection 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)); + } + /// public override void Init() { diff --git a/Source/Tools/Flax.Build/Build/GameModule.cs b/Source/Tools/Flax.Build/Build/GameModule.cs index 82ce9593d..42063e88e 100644 --- a/Source/Tools/Flax.Build/Build/GameModule.cs +++ b/Source/Tools/Flax.Build/Build/GameModule.cs @@ -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 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)); - } } ///