Skip to content

Commit 0c9f83b

Browse files
grendellojonpryor
authored andcommitted
[build] Remove Mono submodule (#3371)
Context: https://github.com/xamarin/xamarin-android/projects/10 One of the goals behind the Mono SDK archive was to enable product builds without having the entire Mono source tree present, which means it should be possible to remove the Mono git submodule and build the entire xamarin-android repo without any issues. At the same time, we want to keep the ability to build Mono from source, if necessary, for situations when a developer works on the BCL or the runtime itself and there's no appropriate binary archive present. To support these two requirements: * Remove the Mono submodule * Put Mono repo commit reference into the `.external` file * Make distinction between "commercial" and "regular" bits in the `.external` file so that we don't attempt to check out everything mentioned in there in situations when a developer doesn't have access to the commercial bits. * Use Mono linker sources from the archive * Remove `zlib-helper.c` from the `libmonodroid` build - the API implemented in there is no longer used by Mono. * `Xamarin.Android.Cecil.dll` and `Xamarin.Android.Cecil.Mdb.dll` are no longer built from source. Instead we use Cecil to reshape `Mono.Cecil` and conjure the two renamed and re-signed assemblies. * All the code which used `Xamarin.Android.Cecil` project reference now simply references the conjured assemblies (which are also added to the bundle) * Third Party Notices are generated from licenses found in the Mono archive. * Windows build downloads also the Darwin archive - in order to be able to use Mono Linker sources as well as licenses contained in this archive.
1 parent 694617e commit 0c9f83b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+636
-240
lines changed

.external

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
xamarin/monodroid:master@237e0bd9f105b9842778ef82161a20c6d4497a40
2+
mono/mono:2019-06@afcf28a3660b069721e5c441dfe5bb7548e3204f

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
bin
44
Configuration.Override.props
55
Configuration.OperatingSystem.props
6-
msfinal.pub
76
obj
87
packages
98
.DS_Store

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
path = external/mman-win32
2323
url = https://github.com/witwall/mman-win32.git
2424
branch = master
25-
[submodule "external/mono"]
26-
path = external/mono
27-
url = https://github.com/mono/mono.git
28-
branch = 2019-06
2925
[submodule "external/mxe"]
3026
path = external/mxe
3127
url = https://github.com/xamarin/mxe.git

Configuration.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<MonoRequiredMaximumVersion Condition=" '$(MonoRequiredMaximumVersion)' == '' ">6.5.0</MonoRequiredMaximumVersion>
8989
<IgnoreMaxMonoVersion Condition=" '$(IgnoreMaxMonoVersion)' == '' ">True</IgnoreMaxMonoVersion>
9090
<MonoRequiredDarwinMinimumVersion>$(MonoRequiredMinimumVersion).98</MonoRequiredDarwinMinimumVersion>
91-
<LinkerSourceDirectory>$(MSBuildThisFileDirectory)external\mono\external\linker\src</LinkerSourceDirectory>
91+
<LinkerSourceDirectory>$(MSBuildThisFileDirectory)external\mono\sdks\out\android-sources\external\linker\src</LinkerSourceDirectory>
9292
<OpenTKSourceDirectory>$(MSBuildThisFileDirectory)external\opentk</OpenTKSourceDirectory>
9393
<MingwZlibRootDirectory Condition=" '$(ZlibRootDirectory)' == '' And '$(HostOS)' == 'Linux' ">\usr</MingwZlibRootDirectory>
9494
<MingwZlibRootDirectory Condition=" '$(ZlibRootDirectory)' == '' And '$(HostOS)' == 'Darwin' ">$(HostHomebrewPrefix)\opt\mingw-zlib\usr</MingwZlibRootDirectory>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
6+
using Mono.Cecil;
7+
8+
public class ConjureXamarinAndroidCecil
9+
{
10+
const string BaseNameReplacement = "Xamarin.Android.Cecil";
11+
const string CecilAssemblyName = BaseNameReplacement;
12+
const string CecilMdbAssemblyName = BaseNameReplacement + ".Mdb";
13+
14+
static readonly List<string> internalsVisibleTo = new List<string> {
15+
"Xamarin.Android.Cecil.Pdb, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db",
16+
"Xamarin.Android.Cecil.Mdb, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db"
17+
};
18+
19+
public static int Main (string[] args)
20+
{
21+
if (args.Length < 2) {
22+
Console.WriteLine ("Usage: <input directory> <output directory>");
23+
Console.WriteLine (" <input directory> must have Mono.Cecil.dll and Mono.Cecil.Mdb.dll assemblies");
24+
return 1;
25+
}
26+
27+
string inputDir = args [0];
28+
string inputFilePath = Path.Combine (inputDir, "Mono.Cecil.dll");
29+
string outputDirPath = args [1];
30+
31+
var resolver = new DefaultAssemblyResolver ();
32+
resolver.AddSearchDirectory (Path.GetDirectoryName (inputFilePath));
33+
var rp = new ReaderParameters () {
34+
AssemblyResolver = resolver,
35+
ReadSymbols = true
36+
};
37+
var monoCecil = AssemblyDefinition.ReadAssembly (inputFilePath, rp);
38+
monoCecil.Name.Name = CecilAssemblyName;
39+
40+
var ivtCtor = monoCecil.MainModule.ImportReference (typeof (System.Runtime.CompilerServices.InternalsVisibleToAttribute).GetConstructor (new []{typeof(string)}));
41+
foreach (string ivtParam in internalsVisibleTo) {
42+
var ca = new CustomAttribute (ivtCtor);
43+
ca.ConstructorArguments.Add (new CustomAttributeArgument (monoCecil.MainModule.TypeSystem.String, ivtParam));
44+
monoCecil.CustomAttributes.Add (ca);
45+
}
46+
47+
var wp = new WriterParameters {
48+
WriteSymbols = true
49+
};
50+
51+
monoCecil.Write (Path.Combine (outputDirPath, $"{CecilAssemblyName}.dll"), wp);
52+
53+
inputFilePath = Path.Combine (inputDir, "Mono.Cecil.Mdb.dll");
54+
var monoCecilMdb = AssemblyDefinition.ReadAssembly (inputFilePath, rp);
55+
monoCecilMdb.Name.Name = CecilMdbAssemblyName;
56+
57+
AssemblyNameReference monoCecilRef = monoCecilMdb.MainModule.AssemblyReferences.Single (r => String.Compare ("Mono.Cecil", r.Name, StringComparison.Ordinal) == 0);
58+
monoCecilRef.Name = CecilAssemblyName;
59+
monoCecilMdb.Write (Path.Combine (outputDirPath, $"{CecilMdbAssemblyName}.dll"), wp);
60+
61+
return 0;
62+
}
63+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{C876DA71-8573-4CEF-9149-716D72455ED4}</ProjectGuid>
7+
<OutputType>Exe</OutputType>
8+
<RootNamespace>Xamarin.Android.Prepare</RootNamespace>
9+
<AssemblyName>conjure-xamarin-android-cecil</AssemblyName>
10+
</PropertyGroup>
11+
<Import Project="..\..\Configuration.props" />
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<Optimize>false</Optimize>
15+
<OutputPath>..\..\bin\BuildDebug</OutputPath>
16+
<DefineConstants>DEBUG;</DefineConstants>
17+
<ErrorReport>prompt</ErrorReport>
18+
<WarningLevel>4</WarningLevel>
19+
<ExternalConsole>true</ExternalConsole>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
<Optimize>true</Optimize>
23+
<OutputPath>..\..\bin\BuildRelease</OutputPath>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<ExternalConsole>true</ExternalConsole>
27+
</PropertyGroup>
28+
<ItemGroup>
29+
<Reference Include="System" />
30+
<Reference Include="Mono.Cecil">
31+
<HintPath>$(XamarinAndroidSourcePath)external\mono\sdks\out\android-bcl\monodroid_tools\Mono.Cecil.dll</HintPath>
32+
</Reference>
33+
</ItemGroup>
34+
<ItemGroup>
35+
<Compile Include="conjure-xamarin-android-cecil.cs" />
36+
</ItemGroup>
37+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
38+
</Project>

build-tools/remap-assembly-ref/remap-assembly-ref.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</PropertyGroup>
2828
<ItemGroup>
2929
<Reference Include="System" />
30-
<ProjectReference Include="..\..\external\Java.Interop\src\Xamarin.Android.Cecil\Xamarin.Android.Cecil.csproj">
31-
<Project>{15945D4B-FF56-4BCC-B598-2718D199DD08}</Project>
32-
<Name>Xamarin.Android.Cecil</Name>
33-
</ProjectReference> </ItemGroup>
30+
<Reference Include="Mono.Cecil">
31+
<HintPath>$(XamarinAndroidSourcePath)external\mono\sdks\out\android-bcl\monodroid_tools\Mono.Cecil.dll</HintPath>
32+
</Reference>
33+
</ItemGroup>
3434
<ItemGroup>
3535
<Compile Include="remap-assembly-ref.cs" />
3636
</ItemGroup>

build-tools/scripts/XAVersionInfo.targets

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitsInRange" />
77
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitTime" />
88
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.GitCommitInfo" />
9+
<Import Project="..\..\bin\Build$(Configuration)\MonoGitHash.props" />
910
<Target Name="_GetSubmodulesVersionInfo">
1011
<ItemGroup>
1112
<!-- If anything changes in this list, make sure to update:
1213
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets (the _GenerateXACommonProps target)
1314
build-tools/create-vsix/create-vsix.targets (the _CreateDependencies target)
1415
-->
15-
<_SubmoduleBranchInfo Include="external/mono">
16-
<OutputPropertyName>_BuildInfo_MonoCommit</OutputPropertyName>
17-
</_SubmoduleBranchInfo>
1816
<_SubmoduleBranchInfo Include="external/Java.Interop">
1917
<OutputPropertyName>_BuildInfo_JavaInteropCommit</OutputPropertyName>
2018
</_SubmoduleBranchInfo>

build-tools/xaprepare/xaprepare/Application/BuildInfo.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ void DetermineBundleHashes (Context context)
105105
LibZipHash = EnsureHash ("LibZip", Utilities.ShortenGitHash (FullLibZipHash));
106106

107107
Log.StatusLine ($" {context.Characters.Bullet} Mono commit hash", ConsoleColor.Gray);
108-
FullMonoHash = git.GetTopCommitHash (context.Properties.GetRequiredValue (KnownProperties.MonoSourceFullPath), shortHash: false);
108+
List<ExternalGitDependency> externalDependencies = ExternalGitDependency.GetDependencies (context, Configurables.Paths.ExternalGitDepsFilePath, quiet: true);
109+
ExternalGitDependency mono = externalDependencies?.Where (
110+
eg => eg != null &&
111+
String.Compare ("mono", eg.Owner, StringComparison.Ordinal) == 0 &&
112+
String.Compare ("mono", eg.Name, StringComparison.Ordinal) == 0).FirstOrDefault ();
113+
114+
FullMonoHash = mono?.Commit?.Trim ();
109115
MonoHash = EnsureHash ("Mono", Utilities.ShortenGitHash (FullMonoHash));
110116

111117
if (Configurables.Paths.BundleVersionHashFiles == null || Configurables.Paths.BundleVersionHashFiles.Count == 0) {

build-tools/xaprepare/xaprepare/Application/Context.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ public string DebugFileExtension {
329329
/// </summary>
330330
public RefreshableComponent ComponentsToRefresh { get; set; }
331331

332+
/// <summary>
333+
/// Set by <see cref="Step_DownloadMonoArchive"/> if the archive has been downloaded and validated, so
334+
/// that the <see cref="Step_BuildMonoRuntimes"/> step doesn't have to re-download the archive, should
335+
/// bundle be absent and <see cref="Step_PrepareBundle"/> fails.
336+
/// </summary>
337+
public bool MonoAlreadyBuilt { get; set; }
338+
332339
static Context ()
333340
{
334341
Instance = new Context ();
@@ -742,8 +749,10 @@ public async Task<bool> Init (string scenarioName = null)
742749
Banner ("Updating Git submodules");
743750

744751
var git = new GitRunner (this);
745-
if (!await git.SubmoduleUpdate ())
746-
Log.WarningLine ("Failed to update Git submodules");
752+
if (!await git.SubmoduleUpdate ()) {
753+
Log.ErrorLine ("Failed to update Git submodules");
754+
return false;
755+
}
747756

748757
BuildInfo = new BuildInfo ();
749758
await BuildInfo.GatherGitInfo (this);

0 commit comments

Comments
 (0)