Refactor engine configuration to support platform-specific namespaces in config files

This commit is contained in:
Wojtek Figat
2026-03-26 23:27:51 +01:00
parent 557dc9b649
commit 78052fbaec
24 changed files with 196 additions and 82 deletions

View File

@@ -20,6 +20,7 @@
#define RAPIDJSON_NEW(x) New<x>
#define RAPIDJSON_DELETE(x) Delete(x)
#define RAPIDJSON_NOMEMBERITERATORCLASS
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseTrailingCommasFlag
//#define RAPIDJSON_MALLOC(size) ::malloc(size)
//#define RAPIDJSON_REALLOC(ptr, new_size) ::realloc(ptr, new_size)
//#define RAPIDJSON_FREE(ptr) ::free(ptr)

View File

@@ -6,6 +6,8 @@ using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Flax.Build
{
@@ -407,6 +409,15 @@ namespace Flax.Build
Configure(GetMembers(obj), obj, configuration);
}
internal static void ConfigureChild(Type type, Dictionary<string, string> configuration, string name = null)
{
if (configuration.TryGetValue(name ?? type.Name, out var subConfig) && subConfig?.Length != 0)
{
var child = JsonSerializer.Deserialize<Dictionary<string, string>>(subConfig.AsSpan(), ProjectInfo.JsonOptions);
Configure(type, child);
}
}
private static void Configure(Dictionary<CommandLineAttribute, MemberInfo> members, object instance, string commandLine)
{
if (commandLine == null)

View File

@@ -259,6 +259,42 @@ namespace Flax.Build
}
}
/// <summary>
/// Platform-specific configuration for Windows.
/// </summary>
public static partial class WindowsConfiguration
{
/// <summary>
/// [Windows] True if SDL support should be enabled.
/// </summary>
[CommandLine("useSdl", "1 to enable SDL support in build on Windows")]
public static bool UseSDL = false;
}
/// <summary>
/// Platform-specific configuration for Linux.
/// </summary>
public static partial class LinuxConfiguration
{
/// <summary>
/// [Linux] True if SDL support should be enabled.
/// </summary>
[CommandLine("useSdl", "1 to enable SDL support in build on Linux")]
public static bool UseSDL = false;
}
/// <summary>
/// Platform-specific configuration for Mac.
/// </summary>
public static partial class MacConfiguration
{
/// <summary>
/// [Mac] True if SDL support should be enabled.
/// </summary>
[CommandLine("useSdl", "1 to enable SDL support in build on Mac")]
public static bool UseSDL = false;
}
/// <summary>
/// The engine configuration options.
/// </summary>
@@ -317,9 +353,11 @@ namespace Flax.Build
switch (options.Platform.Target)
{
case TargetPlatform.Windows:
case TargetPlatform.Linux:
return UseSDL && WindowsConfiguration.UseSDL;
case TargetPlatform.Mac:
return UseSDL;
return UseSDL && MacConfiguration.UseSDL;
case TargetPlatform.Linux:
return UseSDL && LinuxConfiguration.UseSDL;
case TargetPlatform.Web:
return true;
default: return false;

View File

@@ -153,9 +153,9 @@ namespace Flax.Deps.Dependencies
{
var envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer },
{ "CXX", "clang-" + Configuration.LinuxClangMinVer },
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CXX", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel },
};

View File

@@ -148,13 +148,13 @@ namespace Flax.Deps.Dependencies
cmakeArgs += " -DTARGET_BUILD_PLATFORM=linux -DNVCLOTH_CXX_FLAGS=\"-Wno-error=poison-system-directories -Wno-error=missing-include-dirs\"";
cmakeName = "linux";
binariesPrefix = "lib";
envVars.Add("CC", "clang-" + Configuration.LinuxClangMinVer);
envVars.Add("CXX", "clang++-" + Configuration.LinuxClangMinVer);
envVars.Add("CC", "clang-" + LinuxConfiguration.ClangMinVer);
envVars.Add("CXX", "clang++-" + LinuxConfiguration.ClangMinVer);
break;
case TargetPlatform.Web:
cmakeArgs += " -DTARGET_BUILD_PLATFORM=web";
cmakeArgs += $" -DCMAKE_TOOLCHAIN_FILE=\"{EmscriptenSdk.Instance.CMakeToolchainPath}\"";
if (Configuration.WebThreads)
if (WebConfiguration.Threads)
cmakeArgs += " -DNVCLOTH_CXX_FLAGS=\"-pthread\"";
cmakeName = "web";
binariesPrefix = "lib";

View File

@@ -160,9 +160,9 @@ namespace Flax.Deps.Dependencies
};
var envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer },
{ "CXX", "clang++-" + Configuration.LinuxClangMinVer },
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CXX", "clang++-" + LinuxConfiguration.ClangMinVer },
{ "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel },
};
var config = $"-DALSOFT_REQUIRE_ALSA=ON " +

View File

@@ -74,20 +74,20 @@ namespace Flax.Deps.Dependencies
ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", "\"-Wno-error=format -Wno-error=unused-but-set-variable -Wno-error=switch-default -Wno-error=invalid-offsetof -Wno-error=unsafe-buffer-usage -Wno-error=unsafe-buffer-usage-in-libc-call -Wno-error=missing-include-dirs\"");
break;
case TargetPlatform.Android:
ConfigureCmakeSwitch(cmakeParams, "CMAKE_INSTALL_PREFIX", $"install/android-{Configuration.AndroidPlatformApi}/PhysX");
ConfigureCmakeSwitch(cmakeParams, "ANDROID_NATIVE_API_LEVEL", $"android-{Configuration.AndroidPlatformApi}");
ConfigureCmakeSwitch(cmakeParams, "CMAKE_INSTALL_PREFIX", $"install/android-{AndroidConfiguration.PlatformApi}/PhysX");
ConfigureCmakeSwitch(cmakeParams, "ANDROID_NATIVE_API_LEVEL", $"android-{AndroidConfiguration.PlatformApi}");
ConfigureCmakeSwitch(cmakeParams, "ANDROID_ABI", AndroidToolchain.GetAbiName(architecture));
break;
case TargetPlatform.Mac:
ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", Configuration.MacOSXMinVer);
ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer);
ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", "\"-Wno-error=format -Wno-error=unused-but-set-variable -Wno-error=switch-default -Wno-error=invalid-offsetof -Wno-error=unsafe-buffer-usage -Wno-error=unsafe-buffer-usage-in-libc-call -Wno-error=missing-include-dirs\"");
break;
case TargetPlatform.iOS:
ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", Configuration.iOSMinVer);
ConfigureCmakeSwitch(cmakeParams, "CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET", Configuration.iOSMinVer);
ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", iOSConfiguration.MinVer);
ConfigureCmakeSwitch(cmakeParams, "CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET", iOSConfiguration.MinVer);
break;
case TargetPlatform.Web:
ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", Configuration.WebThreads ? "\"-pthread\"" : "");
ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", WebConfiguration.Threads ? "\"-pthread\"" : "");
break;
}
@@ -181,12 +181,12 @@ namespace Flax.Deps.Dependencies
default: throw new InvalidArchitectureException(architecture);
}
binariesPrefix = "lib";
envVars.Add("MACOSX_DEPLOYMENT_TARGET", Configuration.MacOSXMinVer);
envVars.Add("MACOSX_DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer);
break;
case TargetPlatform.iOS:
binariesSubDir = "ios.arm_64";
binariesPrefix = "lib";
envVars.Add("IPHONEOS_DEPLOYMENT_TARGET", Configuration.iOSMinVer);
envVars.Add("IPHONEOS_DEPLOYMENT_TARGET", iOSConfiguration.MinVer);
break;
case TargetPlatform.Web:
binariesSubDir = "web32";
@@ -211,9 +211,9 @@ namespace Flax.Deps.Dependencies
break;
}
case TargetPlatform.Linux:
envVars.Add("CC", "clang-" + Configuration.LinuxClangMinVer);
envVars.Add("CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer);
envVars.Add("CXX", "clang++-" + Configuration.LinuxClangMinVer);
envVars.Add("CC", "clang-" + LinuxConfiguration.ClangMinVer);
envVars.Add("CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer);
envVars.Add("CXX", "clang++-" + LinuxConfiguration.ClangMinVer);
break;
case TargetPlatform.Mac: break;
default: throw new InvalidPlatformException(BuildPlatform);

View File

@@ -123,7 +123,7 @@ namespace Flax.Deps.Dependencies
foreach (var define in defines)
cmakeArgs += $"-D{define.Key}={define.Value} ";
}
if (platform == TargetPlatform.Web && Configuration.WebThreads)
if (platform == TargetPlatform.Web && WebConfiguration.Threads)
cmakeArgs += "-pthread ";
cmakeArgs += "\"";

View File

@@ -134,8 +134,8 @@ namespace Flax.Deps.Dependencies
};
var envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer },
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel },
};
var buildDir = Path.Combine(root, "build");
@@ -168,7 +168,7 @@ namespace Flax.Deps.Dependencies
var archName = arch + "-apple-darwin19";
if (architecture == TargetArchitecture.ARM64)
archName = "arm-apple-darwin19"; // for configure
var compilerFlags = string.Format("-mmacosx-version-min={0} -arch {1}", Configuration.MacOSXMinVer, arch);
var compilerFlags = string.Format("-mmacosx-version-min={0} -arch {1}", MacConfiguration.MacOSXMinVer, arch);
var envVars = new Dictionary<string, string>
{
{ "CC", "clang" },
@@ -178,7 +178,7 @@ namespace Flax.Deps.Dependencies
{ "CPPFLAGS", compilerFlags },
{ "ARCH", arch },
{ "SDK", "macosx" },
{ "DEPLOYMENT_TARGET", Configuration.MacOSXMinVer },
{ "DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer },
};
var buildDir = Path.Combine(root, "build");
SetupDirectory(buildDir, true);

View File

@@ -81,8 +81,8 @@ namespace Flax.Deps.Dependencies
{
var envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer },
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel },
};

View File

@@ -591,8 +591,8 @@ namespace Flax.Deps.Dependencies
{
var envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CXX", "clang++-" + Configuration.LinuxClangMinVer }
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CXX", "clang++-" + LinuxConfiguration.ClangMinVer }
};
var monoOptions = new[]
{
@@ -662,7 +662,7 @@ namespace Flax.Deps.Dependencies
{
var sdk = AndroidSdk.Instance.RootPath;
var ndk = AndroidNdk.Instance.RootPath;
var apiLevel = Configuration.AndroidPlatformApi.ToString();
var apiLevel = AndroidConfiguration.PlatformApi.ToString();
var archName = UnixToolchain.GetToolchainName(platform, TargetArchitecture.ARM64);
var toolchainRoot = Path.Combine(ndk, "toolchains", "llvm", "prebuilt", AndroidSdk.GetHostName());
var ndkBin = Path.Combine(toolchainRoot, "bin");
@@ -779,7 +779,7 @@ namespace Flax.Deps.Dependencies
}
case TargetPlatform.Mac:
{
var compilerFlags = string.Format("-mmacosx-version-min={0}", Configuration.MacOSXMinVer);
var compilerFlags = string.Format("-mmacosx-version-min={0}", MacConfiguration.MacOSXMinVer);
var envVars = new Dictionary<string, string>
{
{ "CFLAGS", compilerFlags },

View File

@@ -136,9 +136,9 @@ namespace Flax.Deps.Dependencies
libName = "msdfgen-core.lib";
break;
case TargetPlatform.Linux:
envVars["CC"] = "clang-" + Configuration.LinuxClangMinVer;
envVars["CC_FOR_BUILD"] = "clang-" + Configuration.LinuxClangMinVer;
envVars["CXX"] = "clang++-" + Configuration.LinuxClangMinVer;
envVars["CC"] = "clang-" + LinuxConfiguration.ClangMinVer;
envVars["CC_FOR_BUILD"] = "clang-" + LinuxConfiguration.ClangMinVer;
envVars["CXX"] = "clang++-" + LinuxConfiguration.ClangMinVer;
cmakeArgs += " -DCMAKE_POSITION_INDEPENDENT_CODE=ON";
break;
}

View File

@@ -250,9 +250,9 @@ namespace Flax.Deps.Dependencies
vorbisConfig += " -DCMAKE_POSITION_INDEPENDENT_CODE=ON";
envVars = new Dictionary<string, string>
{
{ "CC", "clang-" + Configuration.LinuxClangMinVer },
{ "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer },
{ "CXX", "clang++-" + Configuration.LinuxClangMinVer },
{ "CC", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer },
{ "CXX", "clang++-" + LinuxConfiguration.ClangMinVer },
{ "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel },
};
ext = ".a";

View File

@@ -547,19 +547,19 @@ namespace Flax.Deps
var ndk = AndroidNdk.Instance.RootPath;
var abi = AndroidToolchain.GetAbiName(architecture);
var hostName = AndroidSdk.GetHostName();
cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{0}/build/cmake/android.toolchain.cmake\" -DANDROID_NDK=\"{0}\" -DANDROID_STL=c++_shared -DANDROID_ABI={1} -DANDROID_PLATFORM=android-{2} -G \"MinGW Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}/prebuilt/{3}/bin/make.exe\"", ndk, abi, Configuration.AndroidPlatformApi, hostName);
cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{0}/build/cmake/android.toolchain.cmake\" -DANDROID_NDK=\"{0}\" -DANDROID_STL=c++_shared -DANDROID_ABI={1} -DANDROID_PLATFORM=android-{2} -G \"MinGW Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}/prebuilt/{3}/bin/make.exe\"", ndk, abi, AndroidConfiguration.PlatformApi, hostName);
break;
}
case TargetPlatform.Mac:
{
var arch = GetAppleArchName(architecture);
cmdLine = string.Format("CMakeLists.txt -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", Configuration.MacOSXMinVer, arch);
cmdLine = string.Format("CMakeLists.txt -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", MacConfiguration.MacOSXMinVer, arch);
break;
}
case TargetPlatform.iOS:
{
var arch = GetAppleArchName(architecture);
cmdLine = string.Format("CMakeLists.txt -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", Configuration.iOSMinVer, arch);
cmdLine = string.Format("CMakeLists.txt -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", iOSConfiguration.MinVer, arch);
break;
}
case TargetPlatform.Web:

View File

@@ -8,13 +8,13 @@ using Flax.Build.NativeCpp;
namespace Flax.Build
{
partial class Configuration
partial class AndroidConfiguration
{
/// <summary>
/// Specifies the Android API level to use (eg. 24).
/// </summary>
[CommandLine("androidPlatformApi", "<version>", "Specifies the Android API level to use (eg. 24).")]
public static int AndroidPlatformApi = 24;
[CommandLine("platformApi", "<version>", "Specifies the Android API level to use (eg. 24).")]
public static int PlatformApi = 24;
}
}
@@ -66,7 +66,7 @@ namespace Flax.Build.Platforms
base.SetupEnvironment(options);
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_ANDROID");
options.CompileEnv.PreprocessorDefinitions.Add(string.Format("__ANDROID_API__={0}", Configuration.AndroidPlatformApi));
options.CompileEnv.PreprocessorDefinitions.Add(string.Format("__ANDROID_API__={0}", AndroidConfiguration.PlatformApi));
options.LinkEnv.InputLibraries.Add("c");
options.LinkEnv.InputLibraries.Add("z");
@@ -108,7 +108,7 @@ namespace Flax.Build.Platforms
{
case TargetArchitecture.x86:
args.Add("-march=atom");
if (Configuration.AndroidPlatformApi < 24)
if (AndroidConfiguration.PlatformApi < 24)
args.Add("-mstackrealign");
break;
case TargetArchitecture.x64:
@@ -167,7 +167,7 @@ namespace Flax.Build.Platforms
var toolchain = ToolsetRoot.Replace('\\', '/');
args.Add(string.Format("--sysroot=\"{0}/sysroot\"", toolchain));
args.Add(string.Format("--gcc-toolchain=\"{0}\"", toolchain));
args.Add("--target=" + target + Configuration.AndroidPlatformApi);
args.Add("--target=" + target + AndroidConfiguration.PlatformApi);
}
/// <inheritdoc />

View File

@@ -8,13 +8,13 @@ using System.IO;
namespace Flax.Build
{
partial class Configuration
partial class LinuxConfiguration
{
/// <summary>
/// Specifies the minimum Clang compiler version to use on Linux (eg. 10).
/// </summary>
[CommandLine("linuxClangMinVer", "<version>", "Specifies the minimum Clang compiler version to use on Linux (eg. 10).")]
public static string LinuxClangMinVer = "14";
[CommandLine("clangMinVer", "<version>", "Specifies the minimum Clang compiler version to use on Linux (eg. 10).")]
public static string ClangMinVer = "14";
}
}
@@ -36,7 +36,7 @@ namespace Flax.Build.Platforms
: base(platform, architecture, platform.ToolchainRoot, platform.Compiler)
{
// Check version
if (Utilities.ParseVersion(Configuration.LinuxClangMinVer, out var minClangVer) && ClangVersion < minClangVer)
if (Utilities.ParseVersion(LinuxConfiguration.ClangMinVer, out var minClangVer) && ClangVersion < minClangVer)
Log.Error($"Old Clang version {ClangVersion}. Minimum supported is {minClangVer}.");
// Setup system paths

View File

@@ -5,7 +5,7 @@ using Flax.Build.NativeCpp;
namespace Flax.Build
{
partial class Configuration
partial class MacConfiguration
{
/// <summary>
/// Specifies the minimum Mac OSX version to use (eg. 10.14).
@@ -69,7 +69,7 @@ namespace Flax.Build.Platforms
{
base.AddArgsCommon(options, args);
args.Add("-mmacosx-version-min=" + Configuration.MacOSXMinVer);
args.Add("-mmacosx-version-min=" + MacConfiguration.MacOSXMinVer);
}
}
}

View File

@@ -244,14 +244,14 @@ namespace Flax.Build.Platforms
case TargetPlatform.Mac:
switch (architecture)
{
case TargetArchitecture.x64: return "x86_64-apple-macos" + Configuration.MacOSXMinVer;
case TargetArchitecture.ARM64: return "aarch64-apple-macos" + Configuration.MacOSXMinVer;
case TargetArchitecture.x64: return "x86_64-apple-macos" + MacConfiguration.MacOSXMinVer;
case TargetArchitecture.ARM64: return "aarch64-apple-macos" + MacConfiguration.MacOSXMinVer;
default: throw new InvalidArchitectureException(architecture);
}
case TargetPlatform.iOS:
switch (architecture)
{
case TargetArchitecture.ARM64: return "aarch64-apple-ios" + Configuration.iOSMinVer;
case TargetArchitecture.ARM64: return "aarch64-apple-ios" + iOSConfiguration.MinVer;
default: throw new InvalidArchitectureException(architecture);
}
default: throw new InvalidPlatformException(platform);

View File

@@ -9,19 +9,19 @@ using Flax.Build.NativeCpp;
namespace Flax.Build
{
partial class Configuration
partial class WebConfiguration
{
/// <summary>
/// Specifies the initial memory size (in MB) to use by Web app.
/// </summary>
[CommandLine("webInitialMemory", "<size_mb>", "Specifies the initial memory size (in MB) to use by Web app.")]
public static int WebInitialMemory = 32;
[CommandLine("initialMemory", "<size_mb>", "Specifies the initial memory size (in MB) to use by Web app.")]
public static int InitialMemory = 32;
/// <summary>
/// Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.
/// </summary>
[CommandLine("webThreads", "0/1", "Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.")]
public static bool WebThreads = false;
[CommandLine("threads", "0/1", "Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.")]
public static bool Threads = false;
}
}
@@ -105,7 +105,7 @@ namespace Flax.Build.Platforms
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_WEB");
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_UNIX");
options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN__");
if (Configuration.WebThreads)
if (WebConfiguration.Threads)
options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN_PTHREADS__");
options.CompileEnv.EnableExceptions = WithExceptions(options);
options.CompileEnv.CpuArchitecture = CpuArchitecture.SSE4_2;
@@ -183,7 +183,7 @@ namespace Flax.Build.Platforms
if (sanitizers == Sanitizer.None && options.Configuration != TargetConfiguration.Release)
args.Add("-fsanitize=null -fsanitize-minimal-runtime"); // Minimal Runtime
if (Configuration.WebThreads)
if (WebConfiguration.Threads)
args.Add("-pthread");
}
@@ -308,7 +308,7 @@ namespace Flax.Build.Platforms
args.Add("-sERROR_ON_UNDEFINED_SYMBOLS=0");
// Setup memory
var initialMemory = Configuration.WebInitialMemory;
var initialMemory = WebConfiguration.InitialMemory;
if (options.CompileEnv.Sanitizers.HasFlag(Sanitizer.Address))
initialMemory = Math.Max(initialMemory, 64); // Address Sanitizer needs more memory
args.Add($"-sINITIAL_MEMORY={initialMemory}MB");

View File

@@ -8,19 +8,19 @@ using Flax.Build.NativeCpp;
namespace Flax.Build
{
partial class Configuration
partial class WindowsConfiguration
{
/// <summary>
/// Specifies the minimum Windows version to use (eg. 10).
/// </summary>
[CommandLine("winMinVer", "<version>", "Specifies the minimum Windows version to use (eg. 10).")]
public static string WindowsMinVer = "10";
[CommandLine("minVer", "<version>", "Specifies the minimum Windows version to use (eg. 10).")]
public static string MinVer = "10";
/// <summary>
/// Specifies the minimum CPU architecture type to support (on x86/x64).
/// </summary>
[CommandLine("winCpuArch", "<arch>", "Specifies the minimum CPU architecture type to support (on x86/x64).")]
public static CpuArchitecture WindowsCpuArch = CpuArchitecture.SSE4_2; // 99.78% support on PC according to Steam Hardware & Software Survey: September 2025 (https://store.steampowered.com/hwsurvey/)
[CommandLine("cpuArch", "<arch>", "Specifies the minimum CPU architecture type to support (on x86/x64).")]
public static CpuArchitecture CpuArch = CpuArchitecture.SSE4_2; // 99.78% support on PC according to Steam Hardware & Software Survey: September 2025 (https://store.steampowered.com/hwsurvey/)
}
}
@@ -44,7 +44,7 @@ namespace Flax.Build.Platforms
: base(platform, architecture, WindowsPlatformToolset.Latest, WindowsPlatformSDK.Latest)
{
// Select minimum Windows version
if (!Utilities.ParseVersion(Configuration.WindowsMinVer, out _minVersion))
if (!Utilities.ParseVersion(WindowsConfiguration.MinVer, out _minVersion))
_minVersion = new Version(7, 0);
}
@@ -76,7 +76,7 @@ namespace Flax.Build.Platforms
options.LinkEnv.InputLibraries.Add("oleaut32.lib");
options.LinkEnv.InputLibraries.Add("delayimp.lib");
options.CompileEnv.CpuArchitecture = Configuration.WindowsCpuArch;
options.CompileEnv.CpuArchitecture = WindowsConfiguration.CpuArch;
if (options.Architecture == TargetArchitecture.x64)
{

View File

@@ -6,13 +6,13 @@ using Flax.Build.NativeCpp;
namespace Flax.Build
{
partial class Configuration
partial class iOSConfiguration
{
/// <summary>
/// Specifies the minimum iOS version to use (eg. 14).
/// </summary>
[CommandLine("iOSMinVer", "<version>", "Specifies the minimum iOS version to use (eg. 14).")]
public static string iOSMinVer = "15";
[CommandLine("MinVer", "<version>", "Specifies the minimum iOS version to use (eg. 14).")]
public static string MinVer = "15";
}
}
@@ -60,7 +60,7 @@ namespace Flax.Build.Platforms
{
base.AddArgsCommon(options, args);
args.Add("-miphoneos-version-min=" + Configuration.iOSMinVer);
args.Add("-miphoneos-version-min=" + iOSConfiguration.MinVer);
}
public override bool CompileCSharp(ref CSharpOptions options)

View File

@@ -85,6 +85,11 @@ namespace Flax.Build
{
CommandLine.Configure(typeof(EngineConfiguration), engineProject.Configuration);
CommandLine.Configure(typeof(Configuration), engineProject.Configuration);
CommandLine.ConfigureChild(typeof(WindowsConfiguration), engineProject.Configuration, "Windows");
CommandLine.ConfigureChild(typeof(LinuxConfiguration), engineProject.Configuration, "Linux");
CommandLine.ConfigureChild(typeof(MacConfiguration), engineProject.Configuration, "Mac");
CommandLine.ConfigureChild(typeof(iOSConfiguration), engineProject.Configuration, "iOS");
CommandLine.ConfigureChild(typeof(WebConfiguration), engineProject.Configuration, "Web");
}
CommandLine.Configure(typeof(EngineConfiguration));
}

View File

@@ -113,6 +113,55 @@ namespace Flax.Build
value = "true";
else if (reader.TokenType == JsonTokenType.False)
value = "false";
else if (reader.TokenType == JsonTokenType.StartObject)
{
value = "{";
int depth = 1;
while (depth > 0 && reader.Read())
{
switch (reader.TokenType)
{
case JsonTokenType.StartObject:
depth++;
value += "{";
break;
case JsonTokenType.EndObject:
if (value.Last() == ',')
value = value.Substring(0, value.Length - 1);
value += "}";
if (depth != 1)
value += ",";
depth--;
break;
case JsonTokenType.StartArray:
value += "[";
break;
case JsonTokenType.EndArray:
value += "],";
break;
case JsonTokenType.PropertyName:
value += $"\"{reader.GetString()}\":";
break;
case JsonTokenType.String:
value += $"\"{reader.GetString()}\",";
break;
case JsonTokenType.Number:
value += $"{reader.GetString()},";
break;
case JsonTokenType.True:
value += "true,";
break;
case JsonTokenType.False:
value += "false,";
break;
case JsonTokenType.Null:
value += "null,";
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
else
value = reader.GetString();
dictionary.Add(key, value);
@@ -147,6 +196,19 @@ namespace Flax.Build
private static List<ProjectInfo> _projectsCache;
private string _versionControlCommit, _versionControlBranch;
internal static JsonSerializerOptions JsonOptions = new JsonSerializerOptions
{
Converters =
{
new FlaxVersionConverter(),
new ConfigurationDictionaryConverter(),
},
IncludeFields = true,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
TypeInfoResolver = ProjectInfoSourceGenerationContext.Default,
};
/// <summary>
/// The project reference.
/// </summary>
@@ -230,7 +292,6 @@ namespace Flax.Build
/// <summary>
/// The custom build configuration entries loaded from project file.
/// </summary>
[System.Text.Json.Serialization.JsonConverter(typeof(ConfigurationDictionaryConverter))]
public Dictionary<string, string> Configuration;
/// <summary>
@@ -264,7 +325,6 @@ namespace Flax.Build
/// </summary>
public string VersionControlInfo
{
get
{
if (_versionControlCommit == null)
@@ -356,7 +416,7 @@ namespace Flax.Build
/// </summary>
public void Save()
{
var contents = JsonSerializer.Serialize<ProjectInfo>(this, new JsonSerializerOptions() { Converters = { new FlaxVersionConverter() }, TypeInfoResolver = ProjectInfoSourceGenerationContext.Default });
var contents = JsonSerializer.Serialize<ProjectInfo>(this, JsonOptions);
File.WriteAllText(ProjectPath, contents);
}
@@ -382,8 +442,7 @@ namespace Flax.Build
// Load
Log.Verbose("Loading project file from \"" + path + "\"...");
var contents = File.ReadAllText(path);
var project = JsonSerializer.Deserialize<ProjectInfo>(contents.AsSpan(),
new JsonSerializerOptions() { Converters = { new FlaxVersionConverter() }, IncludeFields = true, TypeInfoResolver = ProjectInfoSourceGenerationContext.Default });
var project = JsonSerializer.Deserialize<ProjectInfo>(contents.AsSpan(), JsonOptions);
project.ProjectPath = path;
project.ProjectFolderPath = Path.GetDirectoryName(path);

View File

@@ -49,7 +49,7 @@ namespace Flax.Build.Projects.VisualStudio
vcProjectFileContent.AppendLine(string.Format(" <ProjectGuid>{0}</ProjectGuid>", ProjectGuid.ToString("B").ToUpperInvariant()));
vcProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", BaseName));
vcProjectFileContent.AppendLine(string.Format(" <MinimumVisualStudioVersion>{0}</MinimumVisualStudioVersion>", projectFileToolVersion));
vcProjectFileContent.AppendLine(string.Format(" <AndroidAPILevel>{0}</AndroidAPILevel>", Configuration.AndroidPlatformApi));
vcProjectFileContent.AppendLine(string.Format(" <AndroidAPILevel>{0}</AndroidAPILevel>", AndroidConfiguration.PlatformApi));
vcProjectFileContent.AppendLine(string.Format(" <AndroidSupportedAbis>{0}</AndroidSupportedAbis>", "arm64-v8a"));
vcProjectFileContent.AppendLine(" <ConfigurationType>Application</ConfigurationType>");
vcProjectFileContent.AppendLine(" <AntPackage>");