Skip to content

Commit 134b198

Browse files
authored
[mono] Improve mono.proj, auto-detect build configurations (dotnet#31739)
* Auto-detect build configuration in Makefile * Improve RunCoreClrTests target * Clone .dotnet to .dotnet-mono * Implement Console
1 parent e8dc3a1 commit 134b198

File tree

7 files changed

+95
-56
lines changed

7 files changed

+95
-56
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ syntax: glob
44

55
# Tool Runtime Dir
66
.dotnet/
7+
.dotnet-mono/
78
.packages/
89
.tools/
910

src/mono/mono.proj

+34-34
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<DotNetExec Condition="'$(DotNetExec)' == ''">dotnet</DotNetExec>
1010
<LocalDotnetDir>..\..\.dotnet</LocalDotnetDir>
1111
<LocalDotnet>$(LocalDotnetDir)\$(DotNetExec)</LocalDotnet>
12+
<LocalMonoDotnetDir>..\..\.dotnet-mono</LocalMonoDotnetDir>
13+
<LocalMonoDotnet>$(LocalMonoDotnetDir)\$(DotNetExec)</LocalMonoDotnet>
1214
<ScriptExt Condition="'$(OS)' == 'Windows_NT'">.cmd</ScriptExt>
1315
<ScriptExt Condition="'$(OS)' != 'Windows_NT'">.sh</ScriptExt>
1416
<_CoreClrFileName Condition="'$(TargetsWindows)' == 'true'">coreclr.dll</_CoreClrFileName>
@@ -56,6 +58,12 @@
5658
<Exec Command="msvc\run-msbuild.bat build $(_MonoBuildPlatform) $(Configuration) sgen &quot;$(_MonoBuildParams)&quot; msvc\mono-netcore.sln" IgnoreStandardErrorWarningFormat="true" />
5759
</Target>
5860

61+
<Target Name="BuildCoreLib">
62+
<MSBuild Projects="$(MonoProjectRoot)netcore\System.Private.CoreLib\System.Private.CoreLib.csproj"
63+
Properties="Configuration=$(Configuration)"
64+
Targets="Build" />
65+
</Target>
66+
5967
<!-- General targets -->
6068
<Target Name="Build" DependsOnTargets="BuildMonoRuntimeUnix;BuildMonoRuntimeWindows">
6169
<PropertyGroup>
@@ -88,25 +96,19 @@
8896

8997
<Target Name="Test" />
9098

91-
<!-- Copy Mono runtime bits to the local .dotnet dir for local experiments (temp solution) -->
92-
<Target Name="PatchLocalDotnet" DependsOnTargets="ValidateLocalDotnet">
93-
<PropertyGroup>
94-
<LocalDotnetRuntimeDir>$([System.IO.Directory]::GetDirectories("$(LocalDotnetDir)\shared\Microsoft.NETCore.App")[0])</LocalDotnetRuntimeDir>
95-
</PropertyGroup>
99+
<!-- Copy Mono runtime bits to the local .dotnet-mono (clone of .dotnet) dir for local experiments (temp solution) -->
100+
<Target Name="PatchLocalMonoDotnet" DependsOnTargets="ValidateLocalDotnet">
96101
<ItemGroup>
102+
<_LocalDotnetFiles Include="$(LocalDotnetDir)\**\*.*" />
97103
<_MonoRuntimeArtifacts Include="$(BinDir)\*.*" />
98104
</ItemGroup>
99-
<Copy SourceFiles="$(_MonoRuntimeArtifacts)"
100-
DestinationFolder="$(LocalDotnetRuntimeDir)"
105+
<Error Condition="@(_MonoRuntimeArtifacts->Count()) &lt; 2" Text="Mono artifacts were not found at $(BinDir)" />
106+
<!-- copy .dotnet to .dotnet-mono if it doesn't exist -->
107+
<Copy SourceFiles="@(_LocalDotnetFiles)"
108+
DestinationFolder="$(LocalMonoDotnetDir)\%(RecursiveDir)"
101109
SkipUnchangedFiles="true" />
102-
</Target>
103-
104-
<!-- Copy Coreclr runtime bits to the local .dotnet dir -->
105-
<Target Name="RestoreLocalDotnet" DependsOnTargets="ValidateLocalDotnet">
106-
<Copy SourceFiles="$(CoreCLRArtifactsPath)\System.Private.CoreLib.dll"
107-
DestinationFiles="$(LocalDotnetRuntimeDir)\System.Private.CoreLib.dll" />
108-
<Copy SourceFiles="$(CoreCLRArtifactsPath)\$(_CoreClrFileName)"
109-
DestinationFiles="$(LocalDotnetRuntimeDir)\$(_CoreClrFileName)" />
110+
<Copy SourceFiles="@(_MonoRuntimeArtifacts)"
111+
DestinationFolder="$([System.IO.Directory]::GetDirectories('$(LocalMonoDotnetDir)\shared\Microsoft.NETCore.App')[0])" />
110112
</Target>
111113

112114
<!-- Copy Mono runtime bits to the coreclr's Core_Root in order to run runtime tests -->
@@ -115,9 +117,9 @@
115117
<ItemGroup>
116118
<_MonoRuntimeArtifacts Include="$(BinDir)\*.*" />
117119
</ItemGroup>
120+
<Error Condition="@(_MonoRuntimeArtifacts->Count()) &lt; 2" Text="Mono artifacts were not found at $(BinDir)" />
118121
<Copy SourceFiles="@(_MonoRuntimeArtifacts)"
119-
DestinationFolder="$(CoreClrTestCoreRoot)"
120-
SkipUnchangedFiles="true"/>
122+
DestinationFolder="$(CoreClrTestCoreRoot)" />
121123
</Target>
122124

123125
<!-- Copy Coreclr runtime bits back to Core_Root -->
@@ -129,8 +131,16 @@
129131
</Target>
130132

131133
<!-- Run netcore\sample\HelloWorld sample using Mono Runtime -->
132-
<Target Name="RunSample" DependsOnTargets="PatchLocalDotnet">
133-
<Exec Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) -p $(MonoProjectRoot)netcore\sample\HelloWorld" />
134+
<Target Name="RunSample" DependsOnTargets="PatchLocalMonoDotnet">
135+
<PropertyGroup>
136+
<EnvVars Condition="'$(OS)' != 'Windows_NT'"><![CDATA[
137+
COMPlus_DebugWriteToStdErr=1 \
138+
MONO_ENV_OPTIONS="" \
139+
]]>
140+
</EnvVars>
141+
</PropertyGroup>
142+
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="$(EnvVars) $(LocalMonoDotnet) run -c $(Configuration) -p $(MonoProjectRoot)netcore/sample/HelloWorld" />
143+
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="$(EnvVars) $(LocalMonoDotnet) run -c $(Configuration) -p $(MonoProjectRoot)netcore\sample\HelloWorld" />
134144
</Target>
135145

136146
<!-- Run CoreCLR runtime test using testhost -->
@@ -139,25 +149,15 @@
139149
<Exec Command="$(CoreClrTest) -coreroot=&quot;$(CoreClrTestCoreRoot)&quot;"/>
140150
</Target>
141151

142-
<!-- Make sure coreclr tests are built (in $(CoreClrTestConfig) configuration), e.g.
143-
*nix: `cd ../coreclr && ./build.sh -release && ./build-testh.sh -release`
144-
Windows: `cd ../coreclr && build.cmd -release` -->
152+
<!-- Run coreclr tests using runtest.py -->
145153
<Target Name="RunCoreClrTests" DependsOnTargets="ValidateLocalDotnet;PatchCoreClrCoreRoot">
146-
<ItemGroup>
147-
<CoreClrTests Include="$(ArtifactsDir)tests\coreclr\$(OSGroup).$(Platform).$(CoreClrTestConfig)\**\*$(ScriptExt)" />
148-
</ItemGroup>
149-
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="&quot;%(CoreClrTests.Identity)&quot; -coreroot &quot;$(CoreClrTestCoreRoot)&quot;" ContinueOnError="WarnAndContinue" />
150-
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="bash &quot;%(CoreClrTests.Identity)&quot; -coreroot=&quot;$(CoreClrTestCoreRoot)&quot;" ContinueOnError="WarnAndContinue" />
151-
</Target>
152-
153-
<!-- Show summary for coreclr tests -->
154-
<Target Name="CoreClrTestsSummary">
155-
<Exec Command="python $(MonoProjectRoot)..\coreclr\tests\runtest.py --analyze_results_only -test_location $(ArtifactsDir)tests\coreclr\$(OSGroup).$(Platform).$(CoreClrTestConfig) -build_type $(CoreClrTestConfig)" />
154+
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="$(MonoProjectRoot)..\coreclr\tests\runtest.cmd $(CoreClrTestConfig)" ContinueOnError="ErrorAndContinue" />
155+
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="$(MonoProjectRoot)../coreclr/tests/./runtest.sh $(CoreClrTestConfig)" ContinueOnError="ErrorAndContinue" />
156156
</Target>
157157

158-
<Target Name="RunBenchmarks">
158+
<Target Name="RunBenchmarks" DependsOnTargets="PatchLocalMonoDotnet">
159159
<Error Condition="$(BenchmarksRepo) == ''" Text="BenchmarksRepo variable is not set" />
160-
<Exec WorkingDirectory="$(BenchmarksRepo)\src\benchmarks\micro" Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) --cli $(LocalDotnet)" />
160+
<Exec WorkingDirectory="$(BenchmarksRepo)\src\benchmarks\micro" Command="$(LocalDotnet) run -c Release -f $(NetCoreAppCurrent) --cli $(LocalMonoDotnet)" />
161161
</Target>
162162

163163
<Target Name="ValidateLocalDotnet">

src/mono/netcore/Makefile

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1-
DOTNET=../../../.dotnet/dotnet
1+
DOTNET := $(shell bash init-tools.sh | tail -1)
2+
# DOTNET_MONO is a copy of DOTNET (local .dotnet) with Mono Runtime bits (see patch-mono-dotnet rule)
3+
DOTNET_MONO = ../../../.dotnet-mono/dotnet
24

3-
# run sample using local .dotnet (will be patched with Mono Runtime)
4-
run-sample:
5-
$(DOTNET) msbuild /t:RunSample ../mono.proj
5+
CORECLR_TESTS_CONFIG=Release
6+
MONO_RUNTIME_CONFIG=Release
7+
8+
# auto detect configurations for mono runtime and coreclr tests
9+
ifeq ($(words $(wildcard ../../../artifacts/bin/mono/*.*.*)), 1)
10+
MONO_RUNTIME_CONFIG := $(word 3,$(subst ., ,$(notdir $(wildcard ../../../artifacts/bin/mono/*.*.*))))
11+
endif
12+
13+
ifeq ($(words $(wildcard ../../../artifacts/tests/coreclr/*.*.*)), 1)
14+
CORECLR_TESTS_CONFIG := $(word 3,$(subst ., ,$(notdir $(wildcard ../../../artifacts/tests/coreclr/*.*.*))))
15+
endif
16+
17+
MONO_PROJ=/p:CoreClrTestConfig=$(CORECLR_TESTS_CONFIG) /p:Configuration=$(MONO_RUNTIME_CONFIG) ../mono.proj
18+
19+
# run sample using local .dotnet-mono
20+
run-sample: patch-mono-dotnet
21+
COMPlus_DebugWriteToStdErr=1 $(DOTNET_MONO) run -c Debug -p sample/HelloWorld
622

7-
# run sample using dotnet from PATH
823
run-sample-coreclr:
9-
dotnet run -c Release -p sample/HelloWorld -f netcoreapp3.1
24+
$(DOTNET) run -c Debug -p sample/HelloWorld
1025

11-
runtime:
12-
$(DOTNET) msbuild /t:Build ../mono.proj
26+
bcl corelib:
27+
$(DOTNET) msbuild /t:BuildCoreLib $(MONO_PROJ)
1328

14-
# temp: makes $(DOTNET) to use mono runtime (to run real-world apps using '$(DOTNET) run')
15-
patch-local-dotnet:
16-
$(DOTNET) msbuild /t:PatchLocalDotnet ../mono.proj
29+
runtime:
30+
$(DOTNET) msbuild /t:Build $(MONO_PROJ)
1731

18-
restore-local-dotnet:
19-
$(DOTNET) msbuild /t:RestoreLocalDotnet ../mono.proj
32+
# call it if you want to use $(DOTNET_MONO) in this Makefile
33+
patch-mono-dotnet:
34+
$(DOTNET) msbuild /t:PatchLocalMonoDotnet $(MONO_PROJ)
2035

2136
# run specific coreclr test, e.g.:
22-
# make run-tests-coreclr CoreClrTest="bash ../../artifacts/tests/coreclr/OSX.x64.Checked/JIT/opt/InstructionCombining/DivToMul/DivToMul.sh"
37+
# make run-tests-coreclr CoreClrTest="bash ../../artifacts/tests/coreclr/OSX.x64.Release/JIT/opt/InstructionCombining/DivToMul/DivToMul.sh"
2338
run-tests-coreclr:
24-
$(DOTNET) msbuild /t:RunCoreClrTest /p:CoreClrTest="$(CoreClrTest)" ../mono.proj
39+
$(DOTNET) msbuild /t:RunCoreClrTest /p:CoreClrTest="$(CoreClrTest)" $(MONO_PROJ)
2540

2641
# run all coreclr tests
2742
run-tests-coreclr-all:
28-
$(DOTNET) msbuild /t:RunCoreClrTests ../mono.proj
29-
30-
# show summary for coreclr tests
31-
tests-coreclr-summary:
32-
$(DOTNET) msbuild /t:CoreClrTestsSummary ../mono.proj
43+
$(DOTNET) msbuild /t:RunCoreClrTests $(MONO_PROJ)
3344

3445
# run 'dotnet/performance' benchmarks
3546
# e.g. 'make run-benchmarks BenchmarksRepo=/prj/performance'
3647
# you can append BDN parameters at the end, e.g. ` -- --filter Burgers --keepFiles`
3748
run-benchmarks: patch-local-dotnet
38-
$(DOTNET) msbuild /t:RunBenchmarks /p:BenchmarksRepo=$(BenchmarksRepo)
49+
$(DOTNET) msbuild /t:RunBenchmarks /p:BenchmarksRepo=$(BenchmarksRepo)

src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143

144144
<!-- Sources -->
145145
<ItemGroup>
146+
<Compile Include="$(BclSourcesRoot)\Mono\Console.Mono.cs" />
146147
<Compile Include="$(BclSourcesRoot)\Mono\MonoListItem.cs" />
147148
<Compile Include="$(BclSourcesRoot)\Mono\MonoDomain.cs" />
148149
<Compile Include="$(BclSourcesRoot)\Mono\MonoDomainSetup.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics;
7+
8+
namespace Internal
9+
{
10+
// Some CoreCLR tests use it for internal printf-style debugging in System.Private.CoreLib
11+
public static class Console
12+
{
13+
public static void Write(string? s) => DebugProvider.WriteCore(s);
14+
15+
public static void WriteLine(string? s) => Write(s + Environment.NewLineConst);
16+
17+
public static void WriteLine() => Write(Environment.NewLineConst);
18+
}
19+
}

src/mono/netcore/init-tools.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# always ignore system dotnet
4+
export use_installed_dotnet_cli=false
5+
. "../../../eng/common/tools.sh"
6+
InitializeDotNetCli true
7+
which dotnet

src/mono/netcore/sample/HelloWorld/HelloWorld.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<OutputPath>bin</OutputPath>
6-
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1</TargetFrameworks>
6+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
77
<DebugType>full</DebugType>
88
</PropertyGroup>
99

0 commit comments

Comments
 (0)