Skip to content

Commit

Permalink
Fix project generation logic for Rider to support any OS without MSVC…
Browse files Browse the repository at this point in the history
… toolchain
  • Loading branch information
van800 committed Mar 1, 2025
1 parent 0e3dbba commit f85f82e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ indent_style = space

[*.svg]
insert_final_newline = false

[{*.props,*.vcxproj}]
indent_style = space
indent_size = 2
40 changes: 39 additions & 1 deletion methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ def get_dependencies(file, env, exts, headers, sources, others):
properties.append(
"<ActiveProjectItemList_%s>;%s;</ActiveProjectItemList_%s>" % (x, ";".join(itemlist[x]), x)
)
output = f"bin\\godot{env['PROGSUFFIX']}"
output = os.path.join("bin", f"godot{env['PROGSUFFIX']}")

with open("misc/msvs/props.template", "r", encoding="utf-8") as file:
props_template = file.read()
Expand Down Expand Up @@ -1389,6 +1389,21 @@ def get_dependencies(file, env, exts, headers, sources, others):
proj_template = proj_template.replace("%%DEFAULT_ITEMS%%", "\n ".join(all_items))
proj_template = proj_template.replace("%%PROPERTIES%%", "\n ".join(properties))

toolset = "v143"
if not env.msvc:
toolset = "CLang"
proj_template = proj_template.replace("%%PlatformToolset%%", toolset)

if not env.msvc:
proplist = [str(j) for j in env["CPPPATH"]]
proplist += [str(j) for j in env.get("VSHINT_INCLUDES", [])]
proplist += [str(j) for j in get_default_include_directories(env)]
proj_template = proj_template.replace("%%INCLUDES%%", ";".join(proplist))

proplist = [format_key_value(v) for v in list(env["CPPDEFINES"])]
proplist += [format_key_value(j) for j in env.get("VSHINT_DEFINES", [])]
proj_template = proj_template.replace("%%DEFINES%%", ";".join(proplist))

with open(f"{project_name}.vcxproj", "w", encoding="utf-8", newline="\r\n") as f:
f.write(proj_template)

Expand Down Expand Up @@ -1554,3 +1569,26 @@ def to_raw_cstring(value: Union[str, List[str]]) -> str:
split += [segment]

return " ".join(f'R"<!>({x.decode()})<!>"' for x in split)


def get_default_include_directories(env):
output = subprocess.Popen(
[env["CXX"], "-x", "c++", "-E", "-v", "-"],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
)
stderr = output.stderr.read().decode()
start = False
paths = []
for line in stderr.splitlines():
line = line.strip() # Remove leading/trailing spaces
if not start:
if line == "#include <...> search starts here:":
start = True
elif start:
if line == "End of search list.":
break
else:
paths.append(os.path.abspath(line))
return paths
1 change: 1 addition & 0 deletions misc/msvs/props.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<NMakeReBuildCommandLine>%%REBUILD%%</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>%%CLEAN%%</NMakeCleanCommandLine>
<NMakeOutput Condition="'$(NMakeOutput)' == ''">%%OUTPUT%%</NMakeOutput>
<LocalDebuggerCommand>$(NMakeOutput)</LocalDebuggerCommand>
<NMakePreprocessorDefinitions>%%DEFINES%%;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath>%%INCLUDES%%;$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath>
<NMakeForcedIncludes>$(NMakeForcedIncludes)</NMakeForcedIncludes>
Expand Down
31 changes: 27 additions & 4 deletions misc/msvs/vcxproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
</PropertyGroup>
%%PROPERTIES%%
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>%%PlatformToolset%%</PlatformToolset>
<DefaultPlatformToolset>$(PlatformToolset)</DefaultPlatformToolset>
<OutDir>$(SolutionDir)\bin\$(GodotPlatform)\$(GodotConfiguration)\</OutDir>
<IntDir>obj\$(GodotPlatform)\$(GodotConfiguration)\</IntDir>
<LayoutDir>$(OutDir)\Layout</LayoutDir>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" Condition=" '$(PlatformToolset)' != 'Clang' "/>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" Condition=" '$(PlatformToolset)' != 'Clang' "/>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
Expand All @@ -34,9 +35,31 @@
<ItemGroup Condition="'$(IncludeListImported)'==''">
%%DEFAULT_ITEMS%%
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" Condition=" '$(PlatformToolset)' != 'Clang' "/>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

<Target Name="Build" Condition=" '$(PlatformToolset)' == 'Clang' ">
<Exec Command="scons vsproj=yes dev_build=yes" Condition="'$(OS)' != 'Windows_NT'"/>
<Exec Command="scons use_mingw=yes use_llvm=yes vsproj=yes dev_build=yes" Condition="'$(OS)' == 'Windows_NT'"/>
</Target>
<Target Name="Rebuild" DependsOnTargets="Clean;Build" Condition=" '$(PlatformToolset)' == 'Clang' "/>
<Target Name="Clean" Condition=" '$(PlatformToolset)' == 'Clang' ">
<Exec Command="scons --clean vsproj=yes dev_build=yes" Condition="'$(OS)' != 'Windows_NT'"/>
<Exec Command="scons --clean use_mingw=yes use_llvm=yes vsproj=yes dev_build=yes" Condition="'$(OS)' == 'Windows_NT'"/>
</Target>

<ItemDefinitionGroup Condition=" '$(PlatformToolset)' == 'Clang' ">
<ClCompile>
<AdditionalIncludeDirectories>
%%INCLUDES%%;
%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
%%DEFINES%%;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
<!-- CHECKSUM
%%HASH%%
Expand Down
12 changes: 12 additions & 0 deletions platform/linuxbsd/msvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tuples with the name of the arch
def get_platforms():
return [("arm64", "arm64"), ("x86_64", "x86_64")]


def get_configurations():
return ["editor", "template_debug", "template_release"]


# results are not needed on Mac and Linux
def get_build_prefix(env):
return []
12 changes: 12 additions & 0 deletions platform/macos/msvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tuples with the name of the arch
def get_platforms():
return [("arm64", "arm64"), ("x86_64", "x86_64")]


def get_configurations():
return ["editor", "template_debug", "template_release"]


# results are not needed on Mac and Linux
def get_build_prefix(env):
return []

0 comments on commit f85f82e

Please # to comment.