Fix Web (and consoles) to run without exceptions throw/catch support
This commit is contained in:
@@ -111,6 +111,10 @@
|
||||
#define _DEPRECATED(_0, _1, LASTARG, ...) LASTARG
|
||||
#define DEPRECATED(...) _DEPRECATED(, ##__VA_ARGS__, _DEPRECATED_1(__VA_ARGS__), _DEPRECATED_0())
|
||||
|
||||
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
|
||||
#define HAS_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
// C++ 17
|
||||
#if __cplusplus >= 201703L
|
||||
#define IF_CONSTEXPR constexpr
|
||||
|
||||
@@ -262,6 +262,7 @@ void LocalizationService::OnLocalizationChanged()
|
||||
localeName[currentCulture.Length() + 5] = '8';
|
||||
localeName[currentCulture.Length() + 6] = 0;
|
||||
}
|
||||
#if HAS_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
std::locale::global(std::locale(localeName));
|
||||
@@ -272,6 +273,9 @@ void LocalizationService::OnLocalizationChanged()
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
#else
|
||||
std::locale::global(std::locale(localeName));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using Flax.Build;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
/// <summary>
|
||||
/// Flax.Build.Tests project build configuration.
|
||||
@@ -33,4 +34,12 @@ public class FlaxBuildTestsTarget : Target
|
||||
};
|
||||
CustomExternalProjectFilePath = System.IO.Path.Combine(FolderPath, "Flax.Build.Tests.csproj");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetupTargetEnvironment(BuildOptions options)
|
||||
{
|
||||
base.SetupTargetEnvironment(options);
|
||||
|
||||
options.CompileEnv.EnableExceptions = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,8 +267,21 @@ namespace Flax.Build
|
||||
break;
|
||||
}
|
||||
|
||||
options.CompileEnv.EnableExceptions = true; // TODO: try to disable this!
|
||||
options.CompileEnv.Sanitizers = Configuration.Sanitizers;
|
||||
switch (options.Platform.Target)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
case TargetPlatform.XboxOne:
|
||||
case TargetPlatform.XboxScarlett:
|
||||
case TargetPlatform.UWP:
|
||||
case TargetPlatform.Linux:
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.Mac:
|
||||
// TODO: try to disable this on more platforms! (eg. LocalizationService::OnLocalizationChanged uses it)
|
||||
options.CompileEnv.EnableExceptions = true;
|
||||
break;
|
||||
}
|
||||
options.CompileEnv.RuntimeTypeInfo = true; // TODO: try migrating from dynamic_cast to casting via ScriptingType and skip RTTI
|
||||
options.CompileEnv.Sanitizers |= Configuration.Sanitizers;
|
||||
switch (options.Configuration)
|
||||
{
|
||||
case TargetConfiguration.Debug:
|
||||
|
||||
@@ -86,21 +86,36 @@ namespace Flax.Build.Platforms
|
||||
options.CompileEnv.CpuArchitecture = CpuArchitecture.None; // TODO: try SIMD support in Emscripten
|
||||
}
|
||||
|
||||
private void AddSharedArgs(List<string> args, bool debugInformation, bool optimization, FavorSizeOrSpeed favorSizeOrSpeed)
|
||||
private void AddSharedArgs(List<string> args, BuildOptions options, bool debugInformation, bool optimization)
|
||||
{
|
||||
if (debugInformation)
|
||||
args.Add("-g2");
|
||||
else
|
||||
args.Add("-g0");
|
||||
|
||||
if (favorSizeOrSpeed == FavorSizeOrSpeed.SmallCode)
|
||||
if (options.CompileEnv.FavorSizeOrSpeed == FavorSizeOrSpeed.SmallCode)
|
||||
args.Add("-Os");
|
||||
if (favorSizeOrSpeed == FavorSizeOrSpeed.FastCode)
|
||||
if (options.CompileEnv.FavorSizeOrSpeed == FavorSizeOrSpeed.FastCode)
|
||||
args.Add("-O3");
|
||||
else if (optimization && options.Configuration == TargetConfiguration.Release)
|
||||
args.Add("-O3");
|
||||
else if (optimization)
|
||||
args.Add("-O2");
|
||||
else
|
||||
args.Add("-O0");
|
||||
|
||||
if (options.CompileEnv.RuntimeTypeInfo)
|
||||
args.Add("-frtti");
|
||||
else
|
||||
args.Add("-fno-rtti");
|
||||
|
||||
if (options.CompileEnv.TreatWarningsAsErrors)
|
||||
args.Add("-Wall -Werror");
|
||||
|
||||
if (options.CompileEnv.EnableExceptions)
|
||||
args.Add("-fexceptions");
|
||||
else
|
||||
args.Add("-fno-exceptions");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -114,7 +129,7 @@ namespace Flax.Build.Platforms
|
||||
{
|
||||
commonArgs.Add("-c");
|
||||
|
||||
AddSharedArgs(commonArgs, options.CompileEnv.DebugInformation, options.CompileEnv.Optimization, options.CompileEnv.FavorSizeOrSpeed);
|
||||
AddSharedArgs(commonArgs, options, options.CompileEnv.DebugInformation, options.CompileEnv.Optimization);
|
||||
}
|
||||
|
||||
// Add preprocessor definitions
|
||||
@@ -204,7 +219,8 @@ namespace Flax.Build.Platforms
|
||||
{
|
||||
args.Add(string.Format("-o \"{0}\"", outputFilePath.Replace('\\', '/')));
|
||||
|
||||
AddSharedArgs(args, options.LinkEnv.DebugInformation, options.LinkEnv.Optimization, options.CompileEnv.FavorSizeOrSpeed);
|
||||
AddSharedArgs(args, options, options.LinkEnv.DebugInformation, options.LinkEnv.Optimization);
|
||||
|
||||
}
|
||||
|
||||
args.Add("-Wl,--start-group");
|
||||
|
||||
Reference in New Issue
Block a user