Skip to content

Commit

Permalink
Merge pull request #64089 from neikeq/dotnet6
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Aug 22, 2022
2 parents 8471830 + 9c34a02 commit 8a1e598
Show file tree
Hide file tree
Showing 242 changed files with 20,579 additions and 18,349 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ env:
# Only used for the cache key. Increment version to force clean build.
GODOT_BASE_BRANCH: master-v2
SCONSFLAGS: verbose=yes warnings=extra werror=yes module_text_server_fb_enabled=yes
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: false

concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-linux
Expand Down Expand Up @@ -99,6 +101,12 @@ jobs:
- name: Setup python and scons
uses: ./.github/actions/godot-deps

- name: Set up .NET Sdk
uses: actions/setup-dotnet@v1
if: ${{ matrix.build-mono }}
with:
dotnet-version: '6.0.x'

- name: Compilation
uses: ./.github/actions/godot-build
with:
Expand All @@ -108,10 +116,15 @@ jobs:
tools: ${{ matrix.tools }}
tests: ${{ matrix.tests }}

- name: Generate Mono glue
- name: Generate C# glue
if: ${{ matrix.build-mono }}
run: |
${{ matrix.bin }} --headless --generate-mono-glue ./modules/mono/glue || true
- name: Build .NET solutions
if: ${{ matrix.build-mono }}
run: |
${{ matrix.bin }} --headless --generate-mono-glue modules/mono/glue || true
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=linuxbsd
# Rebuild with mono
- name: Compilation (mono_glue=yes)
Expand Down
14 changes: 0 additions & 14 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1433,20 +1433,6 @@
<member name="memory/limits/multithreaded_server/rid_pool_prealloc" type="int" setter="" getter="" default="60">
This is used by servers when used in multi-threading mode (servers and visual). RIDs are preallocated to avoid stalling the server requesting them on threads. If servers get stalled too often when loading resources in a thread, increase this number.
</member>
<member name="mono/debugger_agent/port" type="int" setter="" getter="" default="23685">
</member>
<member name="mono/debugger_agent/wait_for_debugger" type="bool" setter="" getter="" default="false">
</member>
<member name="mono/debugger_agent/wait_timeout" type="int" setter="" getter="" default="3000">
</member>
<member name="mono/profiler/args" type="String" setter="" getter="" default="&quot;log:calls,alloc,sample,output=output.mlpd&quot;">
</member>
<member name="mono/profiler/enabled" type="bool" setter="" getter="" default="false">
</member>
<member name="mono/runtime/unhandled_exception_policy" type="int" setter="" getter="" default="0">
The policy to use for unhandled Mono (C#) exceptions. The default "Terminate Application" exits the project as soon as an unhandled exception is thrown. "Log Error" logs an error message to the console instead, and will not interrupt the project execution when an unhandled exception is thrown.
[b]Note:[/b] The unhandled exception policy is always set to "Log Error" in the editor, which also includes C# [code]tool[/code] scripts running within the editor as well as editor plugin code.
</member>
<member name="navigation/2d/default_cell_size" type="int" setter="" getter="" default="1">
Default cell size for 2D navigation maps. See [method NavigationServer2D.map_set_cell_size].
</member>
Expand Down
12 changes: 0 additions & 12 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,18 +2255,6 @@ bool Main::start() {
ERR_FAIL_COND_V_MSG(da.is_null(), false, "Argument supplied to --doctool must be a valid directory path.");
}

#ifndef MODULE_MONO_ENABLED
// Hack to define Mono-specific project settings even on non-Mono builds,
// so that we don't lose their descriptions and default values in DocData.
// Default values should be synced with mono_gd/gd_mono.cpp.
GLOBAL_DEF("mono/debugger_agent/port", 23685);
GLOBAL_DEF("mono/debugger_agent/wait_for_debugger", false);
GLOBAL_DEF("mono/debugger_agent/wait_timeout", 3000);
GLOBAL_DEF("mono/profiler/args", "log:calls,alloc,sample,output=output.mlpd");
GLOBAL_DEF("mono/profiler/enabled", false);
GLOBAL_DEF("mono/runtime/unhandled_exception_policy", 0);
#endif

Error err;
DocTools doc;
doc.generate(doc_base);
Expand Down
17 changes: 10 additions & 7 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,18 +818,21 @@ def __getitem__(self, k: str):
module_configs = ModuleConfigs()

if env.get("module_mono_enabled"):
import modules.mono.build_scripts.mono_reg_utils as mono_reg
import modules.mono.build_scripts.mono_configure as mono_configure

mono_root = env.get("mono_prefix") or mono_reg.find_mono_root_dir(env["bits"])
if mono_root:
app_host_dir = mono_configure.find_dotnet_app_host_dir(env)
if app_host_dir and os.path.isdir(app_host_dir):
mono_defines = [("NETHOST_USE_AS_STATIC",)]
if env["tools"]:
mono_defines += [("GD_MONO_HOT_RELOAD",)]
module_configs.add_mode(
"mono",
includes=os.path.join(mono_root, "include", "mono-2.0"),
cli_args="module_mono_enabled=yes mono_glue=yes",
defines=[("MONO_GLUE_ENABLED",)],
includes=app_host_dir,
cli_args="module_mono_enabled=yes",
defines=mono_defines,
)
else:
print("Mono installation directory not found. Generated project will not have build variants for Mono.")
print(".NET App Host directory not found. Generated project will not have build variants for .NET.")

env["MSVSBUILDCOM"] = module_configs.build_commandline("scons")
env["MSVSREBUILDCOM"] = module_configs.build_commandline("scons vsproj=yes")
Expand Down
29 changes: 29 additions & 0 deletions modules/mono/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,32 @@ insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120
csharp_indent_case_contents_when_block = false

[*.cs]
# CA1707: Identifiers should not contain underscores
# TODO:
# Maybe we could disable this selectively only
# where it's not desired and for generated code.
dotnet_diagnostic.CA1707.severity = none
# CA1711: Identifiers should not have incorrect suffix
# Disable warning for suffixes like EventHandler, Flags, Enum, etc.
dotnet_diagnostic.CA1711.severity = none
# CA1716: Identifiers should not match keywords
# TODO: We should look into this.
dotnet_diagnostic.CA1716.severity = warning
# CA1720: Identifiers should not contain type names
dotnet_diagnostic.CA1720.severity = none
# CA1805: Do not initialize unnecessarily
# Don't tell me what to do.
dotnet_diagnostic.CA1805.severity = none
# CA1304: Specify CultureInfo
# TODO: We should look into this.
dotnet_diagnostic.CA1304.severity = warning
# CA1305: Specify IFormatProvider
# TODO: We should look into this. Disabled for now because it's annoying.
dotnet_diagnostic.CA1305.severity = none
# CA1310: Specify StringComparison for correctness
# TODO: We should look into this. Disabled for now because it's annoying.
dotnet_diagnostic.CA1310.severity = none
# Diagnostics to prevent defensive copies of `in` struct parameters
resharper_possibly_impure_method_call_on_readonly_variable_highlighting = error
5 changes: 4 additions & 1 deletion modules/mono/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)\SdkPackageVersions.props" />
<PropertyGroup>
<GodotSdkPackageVersionsFilePath>$(MSBuildThisFileDirectory)\SdkPackageVersions.props</GodotSdkPackageVersionsFilePath>
</PropertyGroup>
<Import Project="$(GodotSdkPackageVersionsFilePath)" />
</Project>
22 changes: 22 additions & 0 deletions modules/mono/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project>
<PropertyGroup>
<_HasNuGetPackage Condition=" '$(_HasNuGetPackage)' == '' And '$(PackageId)' != '' And '$(GeneratePackageOnBuild.ToLower())' == 'true' ">true</_HasNuGetPackage>
<_HasNuGetPackage Condition=" '$(_HasNuGetPackage)' == '' ">false</_HasNuGetPackage>
</PropertyGroup>
<Target Name="CopyNupkgToSConsOutputDir" AfterTargets="Pack"
Condition=" '$(_HasNuGetPackage)' == 'true' ">
<PropertyGroup>
<GodotSourceRootPath>$(MSBuildThisFileDirectory)\..\..\</GodotSourceRootPath>
<GodotOutputDataDir>$(GodotSourceRootPath)\bin\GodotSharp\</GodotOutputDataDir>
</PropertyGroup>
<Copy SourceFiles="$(PackageOutputPath)$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$(GodotOutputDataDir)Tools\nupkgs\" />
</Target>
<Target Name="PushNuGetPackagesToLocalSource" BeforeTargets="Pack"
Condition=" '$(_HasNuGetPackage)' == 'true' And '$(PushNuGetToLocalSource)' != '' ">
<Copy SourceFiles="$(PackageOutputPath)$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$(PushNuGetToLocalSource)\" />
</Target>
<Target Name="ClearNuGetLocalPackageCache" BeforeTargets="Pack"
Condition=" '$(_HasNuGetPackage)' == 'true' And '$(ClearNuGetLocalCache.ToLower())' == 'true' ">
<RemoveDir Directories="$(NugetPackageRoot)/$(PackageId.ToLower())/$(PackageVersion)"/>
</Target>
</Project>
45 changes: 45 additions & 0 deletions modules/mono/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# How to build and run

1. Build Godot with the module enabled: `module_mono_enabled=yes`.
2. After building Godot, use it to generate the C# glue code:
```sh
<godot_binary> --generate-mono-glue ./modules/mono/glue
```
3. Build the C# solutions:
```sh
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin
```

The paths specified in these examples assume the command is being run from
the Godot source root.

# How to deal with NuGet packages

We distribute the API assemblies, our source generators, and our custom
MSBuild project SDK as NuGet packages. This is all transparent to the user,
but it can make things complicated during development.

In order to use Godot with a development of those packages, we must create
a local NuGet source where MSBuild can find them. This can be done with
the .NET CLI:

```sh
dotnet nuget add source ~/MyLocalNugetSource --name MyLocalNugetSource
```

The Godot NuGet packages must be added to that local source. Additionally,
we must make sure there are no other versions of the package in the NuGet
cache, as MSBuild may pick one of those instead.

In order to simplify this process, the `build_assemblies.py` script provides
the following `--push-nupkgs-local` option:

```sh
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin \
--push-nupkgs-local ~/MyLocalNugetSource
```

This option ensures the packages will be added to the specified local NuGet
source and that conflicting versions of the package are removed from the
NuGet cache. It's recommended to always use this option when building the
C# solutions during development to avoid mistakes.
35 changes: 0 additions & 35 deletions modules/mono/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,14 @@ Import("env_modules")

env_mono = env_modules.Clone()

if env_mono["tools"]:
# NOTE: It is safe to generate this file here, since this is still executed serially
import build_scripts.gen_cs_glue_version as gen_cs_glue_version

gen_cs_glue_version.generate_header("glue/GodotSharp", "glue/cs_glue_version.gen.h")

# Glue sources
if env_mono["mono_glue"]:
env_mono.Append(CPPDEFINES=["MONO_GLUE_ENABLED"])

import os.path

if not os.path.isfile("glue/mono_glue.gen.cpp"):
raise RuntimeError("Mono glue sources not found. Did you forget to run '--generate-mono-glue'?")

if env_mono["tools"] or env_mono["target"] != "release":
env_mono.Append(CPPDEFINES=["GD_MONO_HOT_RELOAD"])

# Configure Mono

mono_configure.configure(env, env_mono)

if env_mono["tools"] and env_mono["mono_glue"] and env_mono["build_cil"]:
# Build Godot API solution
import build_scripts.api_solution_build as api_solution_build

api_sln_cmd = api_solution_build.build(env_mono)

# Build GodotTools
import build_scripts.godot_tools_build as godot_tools_build

godot_tools_build.build(env_mono, api_sln_cmd)

# Build Godot.NET.Sdk
import build_scripts.godot_net_sdk_build as godot_net_sdk_build

godot_net_sdk_build.build(env_mono)

# Add sources

env_mono.add_source_files(env.modules_sources, "*.cpp")
env_mono.add_source_files(env.modules_sources, "glue/*.cpp")
env_mono.add_source_files(env.modules_sources, "glue/mono_glue.gen.cpp")
env_mono.add_source_files(env.modules_sources, "mono_gd/*.cpp")
env_mono.add_source_files(env.modules_sources, "utils/*.cpp")

Expand Down
5 changes: 3 additions & 2 deletions modules/mono/SdkPackageVersions.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project>
<PropertyGroup>
<PackageFloatingVersion_Godot>4.0.*-*</PackageFloatingVersion_Godot>
<PackageVersion_Godot_NET_Sdk>4.0.0-dev6</PackageVersion_Godot_NET_Sdk>
<PackageVersion_Godot_SourceGenerators>4.0.0-dev3</PackageVersion_Godot_SourceGenerators>
<PackageVersion_GodotSharp>4.0.0-dev</PackageVersion_GodotSharp>
<PackageVersion_Godot_NET_Sdk>4.0.0-dev8</PackageVersion_Godot_NET_Sdk>
<PackageVersion_Godot_SourceGenerators>4.0.0-dev8</PackageVersion_Godot_SourceGenerators>
</PropertyGroup>
</Project>
80 changes: 0 additions & 80 deletions modules/mono/build_scripts/api_solution_build.py

This file was deleted.

Loading

0 comments on commit 8a1e598

Please sign in to comment.