From 5e32e40c73853fa197393966191525a2136a1fdc Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 2 Sep 2026 21:04:22 +0300 Subject: [PATCH] Improve Rider projects C++ preprocessor definitions All known preprocessor definitions from the compiler are now exposed to Rider language server through MSBuild .props files in order to fix most error squiggles caused by missing or invalid definitions. This should fix some common errors like unable to resolve C++ and C standard library types and macros like `assert`. --- .../VisualStudio/VCProjectGenerator.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VCProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VCProjectGenerator.cs index a4d772e0d..53a6ab243 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VCProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VCProjectGenerator.cs @@ -386,7 +386,9 @@ namespace Flax.Build.Projects.VisualStudio // Override MSBuild .targets file with one that runs NMake commands (workaround for Rider not finding "Microsoft.Cpp.Default.props" file) var cppTargetsFileContent = new StringBuilder(); + cppTargetsFileContent.AppendLine(""); cppTargetsFileContent.AppendLine(""); + cppTargetsFileContent.AppendLine(" "); cppTargetsFileContent.AppendLine(" "); cppTargetsFileContent.AppendLine(" "); cppTargetsFileContent.AppendLine(" "); @@ -408,10 +410,48 @@ namespace Flax.Build.Projects.VisualStudio cppTargetsFileContent.AppendLine(string.Format(" {0}", debuggerWorkingDirectory)); cppTargetsFileContent.AppendLine(" "); cppTargetsFileContent.AppendLine(""); + + // Workarounds for Rider language server to not show errors over well known symbols + Dictionary preprocessor = new Dictionary() + { + {"__attribute__(x)", ""}, + {"__null", "0"}, + {"__extension__", ""}, + {"__asm__", "__asm"}, + {"_SIZE_T", "1"}, + }; + // Undefine hardcoded MSVC definitions + HashSet undefine = new HashSet() + { + "_MSC_VER", + "_MSC_EXTENSIONS", + "_M_IX86", + "_WIN32", + }; + + // Expose all known preprocessor definitions known by the compiler to language server + var clangDefinitions = Utilities.ReadProcessOutput("clang++", "-dM -E -x c++ /dev/null"); + foreach (var (def, val) in clangDefinitions.Split('\n').Select(x => (x.Split(' ')[1], x.Split(' ')[2]))) + preprocessor.Add(def, val); + + var workaroundsFileContent = new StringBuilder(); + workaroundsFileContent.AppendLine($""); + workaroundsFileContent.AppendLine($""); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($" {string.Join(' ', undefine.Select(x => $"/U {x}"))} %(AdditionalOptions)"); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($" /usr/include/c++/16/aarch64-redhat-linux/;$(NMakeIncludeSearchPath)"); + workaroundsFileContent.AppendLine($" {string.Join(';', preprocessor.Select(x => $"{x.Key}={x.Value}"))};$(NMakePreprocessorDefinitions)"); + workaroundsFileContent.AppendLine($" "); + workaroundsFileContent.AppendLine($""); Utilities.WriteFileIfChanged(Path.Combine(projectDirectory, "Microsoft.Cpp.targets"), cppTargetsFileContent.ToString()); Utilities.WriteFileIfChanged(Path.Combine(projectDirectory, "Microsoft.Cpp.Default.props"), vcUserFileContent.ToString()); Utilities.WriteFileIfChanged(Path.Combine(projectDirectory, "Microsoft.Cpp.props"), vcUserFileContent.ToString()); + Utilities.WriteFileIfChanged(Path.Combine(projectDirectory, "Rider.Workarounds.Cpp.props"), workaroundsFileContent.ToString()); } // Save the files