diff --git a/Make.config b/Make.config index 196e0d87e9d9..1c476a8acb7b 100644 --- a/Make.config +++ b/Make.config @@ -69,9 +69,9 @@ include $(TOP)/mk/mono.mk MONO_HASH := $(NEEDED_MONO_VERSION) # Minimum Mono version for building XI/XM -MIN_MONO_VERSION=6.10.0.1 +MIN_MONO_VERSION=6.10.0.91 MAX_MONO_VERSION=6.10.99 -MIN_MONO_URL=https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2019-12/3/7eb7a82f09094facd8772dcb745fd16c7bd401c1/MonoFramework-MDK-6.10.0.1.macos10.xamarin.universal.pkg +MIN_MONO_URL=https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2019-12/94/b27b2d7f6118dff79cc238a22040ee93da39bab4/MonoFramework-MDK-6.10.0.91.macos10.xamarin.universal.pkg # Minimum Mono version for Xamarin.Mac apps using the system mono MIN_XM_MONO_VERSION=6.4.0.94 @@ -374,6 +374,10 @@ endif DOTNET_VERSION=3.1.100 DOTNET_URL=https://download.visualstudio.microsoft.com/download/pr/787e81f1-f0da-4e3b-a989-8a199132ed8c/61a8dba81fbf2b3d533562d7b96443ec/dotnet-sdk-3.1.100-osx-x64.pkg +DOTNET=/usr/local/share/dotnet/dotnet +DOTNET_BCL_REF_URL=https://www.nuget.org/api/v2/package/Microsoft.NETCore.App.Ref/3.1.0 +DOTNET_BCL_REF_NAME=microsoft.netcore.app.ref.3.1.0.nupkg +DOTNET_BCL_DIR:=$(abspath $(TOP)/builds/downloads/$(basename $(DOTNET_BCL_REF_NAME)))/ref/netcoreapp3.1 .SUFFIXES: MAKEFLAGS += --no-builtin-rules diff --git a/builds/Makefile b/builds/Makefile index 5ef9382e0b99..0e0344b4e85c 100644 --- a/builds/Makefile +++ b/builds/Makefile @@ -15,14 +15,20 @@ download-mono: downloads/$(basename $(MONO_IOS_FILENAME)) downloads/$(basename $ downloads/$(basename $(MONO_IOS_FILENAME)): MONO_URL=$(MONO_IOS_URL) downloads/$(basename $(MONO_MAC_FILENAME)): MONO_URL=$(MONO_MAC_URL) +downloads/$(DOTNET_BCL_REF_NAME): MONO_URL=$(DOTNET_BCL_REF_URL) include $(TOP)/mk/colors.mk +DOWNLOADS = \ + downloads/$(MONO_IOS_FILENAME) \ + downloads/$(MONO_MAC_FILENAME) \ + downloads/$(DOTNET_BCL_REF_NAME) \ + # This target downloads the mono archives, there's one for Xamarin.iOS and one for Xamarin.Mac. # If doing many clean builds, it's possible to copy the downloaded zip file to ~/Library/Caches/xamarin-macios # to avoid having to download it every time. The zip files have to be copied manually, otherwise # we'd end up filling up a lot of hard drives around the world. -downloads/$(MONO_IOS_FILENAME) downloads/$(MONO_MAC_FILENAME): +$(DOWNLOADS): $(Q) mkdir -p downloads $(Q) echo "Downloading $(MONO_URL)..." $(Q) if test -f ~/Library/Caches/xamarin-macios/$(notdir $@); then \ @@ -49,9 +55,25 @@ downloads/%: downloads/%.7z $(Q) mv $@.tmp $@ $(Q) echo "Unzipped $*." +downloads/%: downloads/%.nupkg + $(Q) echo "Unzipping $*..." + $(Q) rm -Rf $@.tmp + $(Q) unzip -d $@.tmp $< + $(Q) find $@.tmp -exec touch {} + + $(Q) mv $@.tmp $@ + $(Q) echo "Unzipped $*." + .stamp-download-mono: download-mono $(TOP)/Make.config $(TOP)/mk/mono.mk $(Q) touch $@ +DOTNET_DOWNLOADS = \ + downloads/$(basename $(DOTNET_BCL_REF_NAME)) \ + +dotnet: $(DOTNET_DOWNLOADS) +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_DOWNLOADS) +endif + clean-local:: $(Q) rm -Rf downloads .stamp-download-mono diff --git a/mk/quiet.mk b/mk/quiet.mk index 78ac89c21b4c..fc8dcfb6825a 100644 --- a/mk/quiet.mk +++ b/mk/quiet.mk @@ -31,6 +31,9 @@ Q_XBUILD=$(if $(V),,@echo "XBUILD $(@F)";) Q_TT= $(if $(V),,@echo "TT $(@F)";) Q_BUILD=$(if $(V),,@echo "BUILD $(@F)";) +Q_DOTNET_BUILD=$(if $(V),,@echo "CSC [dotnet] $(@F)";) +Q_DOTNET_GEN =$(if $(V),,@echo "GEN [dotnet] $(@F)";) + Q_PROF_MCS = $(if $(V),,@echo "MCS [$(1)] $(@F)";) Q_PROF_CSC = $(if $(V),,@echo "CSC [$(1)] $(@F)";) Q_PROF_GEN = $(if $(V),,@echo "GEN [$(1)] $(@F)";) diff --git a/src/CFNetwork/Content.cs b/src/CFNetwork/Content.cs index 630c4b367a08..e281d1a04574 100644 --- a/src/CFNetwork/Content.cs +++ b/src/CFNetwork/Content.cs @@ -46,7 +46,7 @@ internal Content (WebResponseStream stream) this.responseStream = stream; } -#if MONOMAC && XAMCORE_2_0 +#if (MONOMAC && XAMCORE_2_0) && !NET internal #endif protected override bool TryComputeLength (out long length) diff --git a/src/CFNetwork/MessageHandler.cs b/src/CFNetwork/MessageHandler.cs index 7e4faeb71505..081ae2a31691 100644 --- a/src/CFNetwork/MessageHandler.cs +++ b/src/CFNetwork/MessageHandler.cs @@ -78,7 +78,7 @@ public WorkerThread WorkerThread { CFHTTPAuthentication auth; #region implemented abstract members of HttpMessageHandler -#if MONOMAC && XAMCORE_2_0 +#if (MONOMAC && XAMCORE_2_0) && !NET internal #endif protected override async Task SendAsync (HttpRequestMessage request, diff --git a/src/Compression/TaskToApm.cs b/src/Compression/TaskToApm.cs new file mode 100644 index 000000000000..8ca02686ca2e --- /dev/null +++ b/src/Compression/TaskToApm.cs @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// Helper methods for using Tasks to implement the APM pattern. +// +// Example usage, wrapping a Task-returning FooAsync method with Begin/EndFoo methods: +// +// public IAsyncResult BeginFoo(..., AsyncCallback callback, object state) => +// TaskToApm.Begin(FooAsync(...), callback, state); +// +// public int EndFoo(IAsyncResult asyncResult) => +// TaskToApm.End(asyncResult); + +// +// Xamarin: +// This is a copy of this file: https://github.com/dotnet/runtime/blob/25d316cefafc4c3884f38acf7bdef971d2b9fe4b/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs +// We need it to be backwards compatible in .NET 5 for the implementations of Compression.[Begin|End]|[Read|Write]. +// + +#if NET +#nullable enable +using System.Diagnostics; + +namespace System.Threading.Tasks +{ + /// + /// Provides support for efficiently using Tasks to implement the APM (Begin/End) pattern. + /// + internal static class TaskToApm + { + /// + /// Marshals the Task as an IAsyncResult, using the supplied callback and state + /// to implement the APM pattern. + /// + /// The Task to be marshaled. + /// The callback to be invoked upon completion. + /// The state to be stored in the IAsyncResult. + /// An IAsyncResult to represent the task's asynchronous operation. + public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state) => + new TaskAsyncResult(task, state, callback); + + /// Processes an IAsyncResult returned by Begin. + /// The IAsyncResult to unwrap. + public static void End(IAsyncResult asyncResult) + { + if (asyncResult is TaskAsyncResult twar) + { + twar._task.GetAwaiter().GetResult(); + return; + } + + throw new ArgumentNullException(); + } + + /// Processes an IAsyncResult returned by Begin. + /// The IAsyncResult to unwrap. + public static TResult End(IAsyncResult asyncResult) + { + if (asyncResult is TaskAsyncResult twar && twar._task is Task task) + { + return task.GetAwaiter().GetResult(); + } + + throw new ArgumentNullException(); + } + + /// Provides a simple IAsyncResult that wraps a Task. + /// + /// We could use the Task as the IAsyncResult if the Task's AsyncState is the same as the object state, + /// but that's very rare, in particular in a situation where someone cares about allocation, and always + /// using TaskAsyncResult simplifies things and enables additional optimizations. + /// + internal sealed class TaskAsyncResult : IAsyncResult + { + /// The wrapped Task. + internal readonly Task _task; + /// Callback to invoke when the wrapped task completes. + private readonly AsyncCallback? _callback; + + /// Initializes the IAsyncResult with the Task to wrap and the associated object state. + /// The Task to wrap. + /// The new AsyncState value. + /// Callback to invoke when the wrapped task completes. + internal TaskAsyncResult(Task task, object? state, AsyncCallback? callback) + { + Debug.Assert(task != null); + _task = task; + AsyncState = state; + + if (task.IsCompleted) + { + // Synchronous completion. Invoke the callback. No need to store it. + CompletedSynchronously = true; + callback?.Invoke(this); + } + else if (callback != null) + { + // Asynchronous completion, and we have a callback; schedule it. We use OnCompleted rather than ContinueWith in + // order to avoid running synchronously if the task has already completed by the time we get here but still run + // synchronously as part of the task's completion if the task completes after (the more common case). + _callback = callback; + _task.ConfigureAwait(continueOnCapturedContext: false) + .GetAwaiter() + .OnCompleted(InvokeCallback); // allocates a delegate, but avoids a closure + } + } + + /// Invokes the callback. + private void InvokeCallback() + { + Debug.Assert(!CompletedSynchronously); + Debug.Assert(_callback != null); + _callback.Invoke(this); + } + + /// Gets a user-defined object that qualifies or contains information about an asynchronous operation. + public object? AsyncState { get; } + /// Gets a value that indicates whether the asynchronous operation completed synchronously. + /// This is set lazily based on whether the has completed by the time this object is created. + public bool CompletedSynchronously { get; } + /// Gets a value that indicates whether the asynchronous operation has completed. + public bool IsCompleted => _task.IsCompleted; + /// Gets a that is used to wait for an asynchronous operation to complete. + public WaitHandle AsyncWaitHandle => ((IAsyncResult)_task).AsyncWaitHandle; + } + } +} +#endif diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index 777ea3c81e72..1e54392f7673 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -473,7 +473,7 @@ async Task CreateRequest (HttpRequestMessage request) return nsrequest; } -#if SYSTEM_NET_HTTP || MONOMAC +#if (SYSTEM_NET_HTTP || MONOMAC) && !NET internal #endif protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) @@ -935,7 +935,10 @@ protected override Task SerializeToStreamAsync (Stream stream, TransportContext return content.CopyToAsync (stream, bufferSize, cancellationToken); } - protected internal override bool TryComputeLength (out long length) +#if !NET + internal +#endif + protected override bool TryComputeLength (out long length) { if (!content.CanSeek) { length = 0; diff --git a/src/Makefile b/src/Makefile index a937b0648e00..a5ad48944331 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,6 +2,7 @@ TOP=.. include $(TOP)/Make.config BUILD_DIR=build +DOTNET_BUILD_DIR=build/dotnet PROJECT_DIR=. include $(TOP)/src/frameworks.sources @@ -17,6 +18,49 @@ IOS_BUILD_DIR=$(BUILD_DIR)/ios WATCH_BUILD_DIR=$(BUILD_DIR)/watch TVOS_BUILD_DIR=$(BUILD_DIR)/tvos +MACOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/macos +IOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/ios +WATCHOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/watchos +TVOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/tvos + +GENERATOR_FLAGS=-process-enums -core -nologo -nostdlib -noconfig -native-exception-marshalling --ns:ObjCRuntime + +DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /target:library /debug /unsafe /define:NET /define:NET_TODO \ + /r:$(DOTNET_BCL_DIR)/System.Buffers.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.Concurrent.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.NonGeneric.dll \ + /r:$(DOTNET_BCL_DIR)/System.Console.dll \ + /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Debug.dll \ + /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Tools.dll \ + /r:$(DOTNET_BCL_DIR)/System.Drawing.Primitives.dll \ + /r:$(DOTNET_BCL_DIR)/System.IO.Compression.dll \ + /r:$(DOTNET_BCL_DIR)/System.IO.FileSystem.dll \ + /r:$(DOTNET_BCL_DIR)/System.Linq.dll \ + /r:$(DOTNET_BCL_DIR)/System.Memory.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Http.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.NameResolution.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Primitives.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Requests.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Security.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.ServicePoint.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Sockets.dll \ + /r:$(DOTNET_BCL_DIR)/System.Resources.ResourceManager.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.Extensions.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.InteropServices.dll \ + /r:$(DOTNET_BCL_DIR)/System.Security.Cryptography.X509Certificates.dll \ + /r:$(DOTNET_BCL_DIR)/System.Text.RegularExpressions.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.Tasks.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.Thread.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.ReaderWriter.dll \ + +DOTNET_GENERATOR_FLAGS=$(GENERATOR_FLAGS) -compiler=$(SYSTEM_CSC) $(DOTNET_FLAGS) --lib=$(DOTNET_BCL_DIR) -attributelib:$(DOTNET_BINDING_ATTRIBUTES) +DOTNET_GENERATOR=$(DOTNET_BUILD_DIR)/bgen/bgen +DOTNET_BINDING_ATTRIBUTES=$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll + include $(TOP)/opentk/Makefile.include # @@ -78,6 +122,10 @@ IOS_GENERATOR_FLAGS = -inline-selectors -d:IOS -process-enums -warnaserror:$(IOS IOS_DEFINES = -define:IPHONE -define:IOS -define:MONOTOUCH -d:__IOS__ $(APPLETLS_DEFINES) -d:SYSTEM_NET_HTTP -d:XAMCORE_2_0 -d:__UNIFIED__ IOS_GENERATOR=$(BUILD_DIR)/common/bgen.exe IOS_GENERATE=$(SYSTEM_MONO) --debug $(IOS_GENERATOR) + +IOS_CORE_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) +IOS_CORE_DEFINES=-define:COREBUILD $(IOS_DEFINES) $(IOS_native_DEFINES) + $(IOS_BUILD_DIR)/Constants.cs: Constants.iOS.cs.in Makefile $(TOP)/Make.config.inc | $(IOS_BUILD_DIR) $(call Q_PROF_GEN,ios) sed \ -e "s/@VERSION@/$(IOS_PACKAGE_VERSION_MAJOR).$(IOS_PACKAGE_VERSION_MINOR).$(IOS_PACKAGE_VERSION_REV)/g" \ @@ -101,6 +149,19 @@ $(IOS_BUILD_DIR)/native/core.dll: $(IOS_CORE_SOURCES) frameworks.sources $(IOS_BUILD_DIR)/native/generated_sources: $(IOS_GENERATOR) $(IOS_APIS) $(IOS_BUILD_DIR)/native/core.dll $(IOS_BUILD_DIR)/native/Xamarin.iOS.BindingAttributes.dll $(BUILD_DIR)/ios.rsp $(call Q_PROF_GEN,ios) $(IOS_GENERATE) @$(BUILD_DIR)/ios.rsp +### .NET ### + +$(IOS_DOTNET_BUILD_DIR)/core-ios.dll: $(IOS_CORE_SOURCES) frameworks.sources | $(IOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(IOS_CORE_WARNINGS_TO_FIX) \ + $(IOS_CORE_DEFINES) \ + $(IOS_CORE_SOURCES) \ + -out:$@ + +$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources: $(DOTNET_GENERATOR) $(IOS_APIS) $(IOS_DOTNET_BUILD_DIR)/core-ios.dll $(DOTNET_BINDING_ATTRIBUTES) $(IOS_DOTNET_BUILD_DIR)/ios.rsp | $(IOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(IOS_DOTNET_BUILD_DIR)/ios.rsp + $(BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources $(Q_GEN) echo \ $(IOS_GENERATOR_FLAGS) \ @@ -117,6 +178,21 @@ $(BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources $(IOS_APIS) \ > $@ +$(IOS_DOTNET_BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources | $(IOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(IOS_GENERATOR_FLAGS) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(IOS_GENERATOR_WARNASERROR) \ + -sourceonly=$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources \ + -tmpdir=$(IOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(IOS_DOTNET_BUILD_DIR)/core-ios.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=ios \ + $(IOS_APIS) \ + > $@ + +$(IOS_DOTNET_BUILD_DIR)/Xamarin.iOS.dll: $(IOS_DOTNET_BUILD_DIR)/64/Xamarin.iOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + define IOS_TARGETS_template # Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.pdb: $$(IOS_SOURCES) $(IOS_BUILD_DIR)/native/generated_sources $(PRODUCT_KEY_PATH) @@ -129,6 +205,16 @@ $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamari $$(IOS_CSC_FLAGS_XI) \ $$(IOS_SOURCES) @$(IOS_BUILD_DIR)/native/generated_sources +$(IOS_DOTNET_BUILD_DIR)/$(1)/Xamarin.iOS.dll: $$(IOS_SOURCES) $$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources $(PRODUCT_KEY_PATH) | $(IOS_DOTNET_BUILD_DIR)/$(1) + $$(call Q_PROF_CSC,dotnet/$(1)-bit) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$$@ -unsafe -optimize \ + $$(ARGS_$(1)) \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $$(IOS_DEFINES) \ + $$(IOS_native_DEFINES) \ + $$(IOS_CORE_WARNINGS_TO_FIX) \ + $$(IOS_CSC_FLAGS_XI) \ + $$(IOS_SOURCES) @$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources + endef $(IOS_BUILD_DIR)/compat/%: $(MACIOS_BINARIES_PATH)/% | $(IOS_BUILD_DIR)/compat @@ -219,6 +305,17 @@ IOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/64bits/Xamarin.iOS.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/64bits/Xamarin.iOS.pdb \ +DOTNET_TARGETS += \ + $(IOS_DOTNET_BUILD_DIR)/32/Xamarin.iOS.dll \ + $(IOS_DOTNET_BUILD_DIR)/64/Xamarin.iOS.dll \ + $(IOS_DOTNET_BUILD_DIR)/Xamarin.iOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(IOS_DOTNET_BUILD_DIR) \ + $(IOS_DOTNET_BUILD_DIR)/32 \ + $(IOS_DOTNET_BUILD_DIR)/64 \ + $(IOS_DOTNET_BUILD_DIR)/generated-sources \ + $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1/%.dll: $(IOS_BUILD_DIR)/compat/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1 $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1/Facades $(Q) install -m 0755 $< $@ @@ -290,6 +387,9 @@ MAC_mobile_ARGS = MAC_BOOTSTRAP_DEFINES = $(MAC_COMMON_DEFINES),COREBUILD MAC_GENERATED_DEFINES = -d:MONOMAC -d:XAMCORE_2_0 -d:__UNIFIED__ +MAC_CORE_DEFINES = $(MAC_BOOTSTRAP_DEFINES) +MAC_CORE_WARNINGS_TO_FIX = -nowarn:3021,612,618,1635 + $(MAC_BUILD_DIR)/$(1)/$(3).pdb: $(MAC_BUILD_DIR)/$(1)/$(3).dll SN_KEY = $(PRODUCT_KEY_PATH) @@ -419,6 +519,55 @@ $(MAC_BUILD_DIR)/%-reference/Xamarin.Mac.pdb: $(MAC_BUILD_DIR)/%-64/Xamarin.Mac. @mkdir -p $(@D) $(Q) $(CP) $^ $@ +### .NET ### + +$(MACOS_DOTNET_BUILD_DIR)/core-macos.dll: $(MAC_CORE_SOURCES) frameworks.sources | $(MACOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ \ + $(MAC_CORE_WARNINGS_TO_FIX) \ + $(MAC_CORE_DEFINES) \ + $(MAC_CORE_SOURCES) \ + -out:$@ \ + +$(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources: $(DOTNET_GENERATOR) $(MAC_APIS) $(MACOS_DOTNET_BUILD_DIR)/core-macos.dll $(DOTNET_BINDING_ATTRIBUTES) $(MACOS_DOTNET_BUILD_DIR)/macos.rsp | $(MACOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(MACOS_DOTNET_BUILD_DIR)/macos.rsp + +$(MACOS_DOTNET_BUILD_DIR)/macos.rsp: Makefile Makefile.generator frameworks.sources | $(MACOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(MAC_GENERATED_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) \ + -warnaserror:$(MAC_GENERATOR_WARNASERROR) \ + -sourceonly:$(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources \ + -tmpdir:$(MACOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib:$(MACOS_DOTNET_BUILD_DIR)/core-macos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=macos \ + $(MAC_APIS) \ + > $@ + +$(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll: $(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources $(MAC_SOURCES) $(MAC_CFNETWORK_SOURCES) $(SN_KEY) | $(MACOS_DOTNET_BUILD_DIR)/64 + $(Q_DOTNET_BUILD) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(SN_KEY) \ + $(MAC_COMMON_DEFINES) \ + $(ARGS_64) \ + -nowarn:3021,1635,612,618,0219,0414,$(MAC_WARNINGS_TO_FIX) \ + $(MAC_CSC_FLAGS_XM) \ + $(MAC_CFNETWORK_SOURCES) $(MAC_HTTP_SOURCES) $(SHARED_SYSTEM_DRAWING_SOURCES) $(APPLETLS_DEFINES) -D:XAMARIN_MODERN -D:UNIFIED -D:__UNIFIED__ \ + $(MAC_SOURCES) \ + @$< + +$(MACOS_DOTNET_BUILD_DIR)/Xamarin.Mac.dll: $(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + +DOTNET_TARGETS += \ + $(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll \ + $(MACOS_DOTNET_BUILD_DIR)/Xamarin.Mac.dll \ + +DOTNET_TARGETS_DIRS += \ + $(MACOS_DOTNET_BUILD_DIR) \ + $(MACOS_DOTNET_BUILD_DIR)/generated-sources \ + $(MACOS_DOTNET_BUILD_DIR)/64 \ + MAC_VARIANTS_TARGETS = \ $(MAC_BUILD_DIR)/mobile-64/Xamarin.Mac.dll \ $(MAC_BUILD_DIR)/full-64/Xamarin.Mac.dll \ @@ -516,6 +665,11 @@ WATCH_GENERATOR=$(BUILD_DIR)/common/bgen.exe WATCH_GENERATE=$(SYSTEM_MONO) --debug $(WATCH_GENERATOR) WATCH_GENERATED_DEFINES= -d:WATCH -d:XAMCORE_3_0 -d:XAMCORE_2_0 -d:__UNIFIED__ +WATCHOS_CORE_DEFINES = $(WATCH_DEFINES) -define:COREBUILD +WATCHOS_CORE_WARNINGS_TO_FIX = -nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + +WATCHOS_WARNINGS_TO_FIX = -nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + WATCHOS_EXTRA_CORE_SOURCES = \ $(WATCH_BUILD_DIR)/Constants.cs \ $(WATCH_BUILD_DIR)/AssemblyInfo.cs \ @@ -589,6 +743,45 @@ $(BUILD_DIR)/watchos.rsp: Makefile Makefile.generator frameworks.sources --target-framework=Xamarin.WatchOS,v1.0 \ > $@ +### .NET ### + +$(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll: $(WATCHOS_CORE_SOURCES) frameworks.sources | $(WATCHOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(WATCHOS_CORE_WARNINGS_TO_FIX) \ + $(WATCHOS_CORE_DEFINES) \ + $(WATCHOS_CORE_SOURCES) \ + -out:$@ \ + +$(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources: $(DOTNET_GENERATOR) $(WATCHOS_APIS) $(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll $(DOTNET_BINDING_ATTRIBUTES) $(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp | $(WATCHOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp + +$(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp: Makefile Makefile.generator frameworks.sources | $(WATCHOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(WATCH_GENERATED_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(WATCH_GENERATOR_WARNASERROR) \ + -sourceonly=$(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources \ + -tmpdir=$(WATCHOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=watchos \ + $(WATCHOS_APIS) \ + > $@ + +$(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll: $(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources $(WATCHOS_SOURCES) $(PRODUCT_KEY_PATH) | $(WATCHOS_DOTNET_BUILD_DIR)/32 + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $(WATCH_DEFINES) \ + $(ARGS_32) \ + $(WATCHOS_WARNINGS_TO_FIX) \ + $(IOS_CSC_FLAGS_XI) \ + $(WATCHOS_SOURCES) \ + @$< + +$(WATCHOS_DOTNET_BUILD_DIR)/Xamarin.WatchOS.dll: $(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + $(WATCH_BUILD_DIR)/watch-32/Xamarin.WatchOS%dll $(WATCH_BUILD_DIR)/watch-32/Xamarin.WatchOS%pdb: $(WATCHOS_SOURCES) $(WATCH_BUILD_DIR)/watch/generated_sources $(PRODUCT_KEY_PATH) | $(WATCH_BUILD_DIR)/watch-32 $(call Q_PROF_CSC,watch) $(WATCH_CSC) -nologo -out:$(basename $@).dll -target:library -debug -unsafe -optimize \ -publicsign -keyfile:$(PRODUCT_KEY_PATH) $(WATCH_DEFINES) \ @@ -643,6 +836,15 @@ WATCH_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/MonoTouch.NUnitLite.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/MonoTouch.NUnitLite.pdb +DOTNET_TARGETS += \ + $(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll \ + $(WATCHOS_DOTNET_BUILD_DIR)/Xamarin.WatchOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(WATCHOS_DOTNET_BUILD_DIR) \ + $(WATCHOS_DOTNET_BUILD_DIR)/generated-sources \ + $(WATCHOS_DOTNET_BUILD_DIR)/32 \ + # reference assemblies, this is just for compilation with XS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/%.dll: $(WATCH_BUILD_DIR)/reference/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/Facades $(Q) install -m 0755 $< $@ @@ -680,6 +882,11 @@ TVOS_GENERATOR=$(BUILD_DIR)/common/bgen.exe TVOS_GENERATE=$(SYSTEM_MONO) --debug $(TVOS_GENERATOR) TVOS_GENERATED_DEFINES= -d:TVOS -d:XAMCORE_3_0 -d:XAMCORE_2_0 -d:__UNIFIED__ +TVOS_CORE_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) +TVOS_CORE_DEFINES=$(TVOS_DEFINES) -d:COREBUILD +TVOS_GENERATOR_DEFINES = $(TVOS_GENERATED_DEFINES) +TVOS_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + TVOS_EXTRA_CORE_SOURCES = \ $(TVOS_BUILD_DIR)/Constants.cs \ $(TVOS_BUILD_DIR)/AssemblyInfo.cs \ @@ -752,6 +959,45 @@ $(BUILD_DIR)/tvos.rsp: Makefile Makefile.generator frameworks.sources --target-framework=Xamarin.TVOS,v1.0 \ > $@ +### .NET ### + +$(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll: $(TVOS_CORE_SOURCES) frameworks.sources Makefile | $(TVOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(TVOS_CORE_WARNINGS_TO_FIX) \ + $(TVOS_CORE_DEFINES) \ + $(TVOS_CORE_SOURCES) \ + -out:$@ \ + +$(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources: $(DOTNET_GENERATOR) $(TVOS_APIS) $(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll $(DOTNET_BINDING_ATTRIBUTES) $(TVOS_DOTNET_BUILD_DIR)/tvos.rsp | $(TVOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(TVOS_DOTNET_BUILD_DIR)/tvos.rsp + +$(TVOS_DOTNET_BUILD_DIR)/tvos.rsp: Makefile Makefile.generator frameworks.sources + $(Q) echo \ + $(TVOS_GENERATOR_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(TVOS_GENERATOR_WARNASERROR) \ + -sourceonly=$(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources \ + -tmpdir=$(TVOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=tvos \ + $(TVOS_APIS) \ + > $@ + +$(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll: $(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources $(TVOS_SOURCES) $(PRODUCT_KEY_PATH) | $(TVOS_DOTNET_BUILD_DIR)/64 + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $(TVOS_DEFINES) \ + $(ARGS_64) \ + $(TVOS_WARNINGS_TO_FIX) \ + $(IOS_CSC_FLAGS_XI) \ + $(TVOS_SOURCES) \ + @$< + +$(TVOS_DOTNET_BUILD_DIR)/Xamarin.TVOS.dll: $(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + $(TVOS_BUILD_DIR)/tvos-64/Xamarin.TVOS%dll $(TVOS_BUILD_DIR)/tvos-64/Xamarin.TVOS%pdb: $(TVOS_SOURCES) $(TVOS_BUILD_DIR)/tvos/generated_sources $(PRODUCT_KEY_PATH) | $(TVOS_BUILD_DIR)/tvos-64 $(call Q_PROF_CSC,tvos) $(TV_CSC) -nologo -out:$(basename $@).dll -target:library -debug -unsafe -optimize \ -publicsign -keyfile:$(PRODUCT_KEY_PATH) $(TVOS_DEFINES) \ @@ -820,6 +1066,15 @@ TVOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/MonoTouch.NUnitLite.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/MonoTouch.NUnitLite.pdb +DOTNET_TARGETS += \ + $(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll \ + $(TVOS_DOTNET_BUILD_DIR)/Xamarin.TVOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(TVOS_DOTNET_BUILD_DIR) \ + $(TVOS_DOTNET_BUILD_DIR)/generated-sources \ + $(TVOS_DOTNET_BUILD_DIR)/64 \ + # reference assemblies, this is just for compilation with XS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/%.dll: $(TVOS_BUILD_DIR)/reference/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/Facades $(Q) install -m 0755 $< $@ @@ -865,6 +1120,18 @@ $(COMMON_TARGET_DIRS): install-local:: $(INSTALL_TARGETS) all-local:: $(ALL_TARGETS) +$(DOTNET_TARGETS_DIRS): + $(Q) mkdir -p $@ + +dotnet: $(DOTNET_TARGETS) +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_TARGETS) +endif + +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_TARGETS) +endif + project-files: $(PROJECT_FILES) # Using .SECONDARY can cause make to go into an infinite loop. diff --git a/src/Makefile.generator b/src/Makefile.generator index cc590b3178f4..bafdcb69917a 100644 --- a/src/Makefile.generator +++ b/src/Makefile.generator @@ -11,6 +11,17 @@ $(BUILD_DIR)/generator.csproj.inc: Makefile.generator $(TOP)/tools/common/create $(BUILD_DIR)/common/bgen.exe: $(generator_dependencies) Makefile.generator $(BUILD_DIR)/generator-frameworks.g.cs $(Q_GEN) $(SYSTEM_MSBUILD) $(XBUILD_VERBOSITY) /p:Configuration=Debug generator.csproj /p:IntermediateOutputPath=$(BUILD_DIR)/IDE/obj/common/ /p:OutputPath=$(BUILD_DIR)/common +$(DOTNET_BUILD_DIR)/bgen/bgen: $(generator_dependencies) Makefile.generator $(BUILD_DIR)/generator-frameworks.g.cs | $(DOTNET_BUILD_DIR)/bgen + $(Q_DOTNET_BUILD) $(DOTNET) build $(XBUILD_VERBOSITY) /p:Configuration=Debug bgen/bgen.csproj + $(Q) $(CP) bgen/bin/Debug/netcoreapp3.1/bgen* $(dir $@) + +DOTNET_TARGETS += \ + $(DOTNET_BUILD_DIR)/bgen/bgen \ + +DOTNET_TARGETS_DIRS += \ + $(DOTNET_BUILD_DIR) \ + $(DOTNET_BUILD_DIR)/bgen \ + # # Common # @@ -19,6 +30,9 @@ $(BUILD_DIR)/generator-frameworks.g.cs: frameworks.sources Makefile.generator ge @mkdir -p $(dir $@) @./generate-frameworks.csharp '$(IOS_FRAMEWORKS)' '$(MAC_FRAMEWORKS)' '$(WATCHOS_FRAMEWORKS)' '$(TVOS_FRAMEWORKS)' > $@ +$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll: generator-attributes.cs Makefile.generator | $(DOTNET_BUILD_DIR) + $(Q_DOTNET_BUILD) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ $< + # # Xamarin.iOS (btouch) # @@ -36,7 +50,7 @@ IOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch-native \ -$(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/bgen: bgen | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin +$(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/bgen: bgen/bgen | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin $(Q) $(CP) $< $@ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch: Makefile.generator | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin @@ -124,7 +138,7 @@ MAC_TARGETS += \ MAC_TARGETS += \ $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bmac \ -$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen: bgen | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin +$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen: bgen/bgen | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin $(Q) $(CP) $< $@ $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen-classic: Makefile.generator | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 1fa55aa45c02..1b14c9f798f5 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -253,10 +253,16 @@ unsafe static void Initialize (InitializationOptions* options) Registrar = new DynamicRegistrar (); RegisterDelegates (options); Class.Initialize (options); +#if !NET + // This is not needed for .NET 5: + // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-588331822 + // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-589356481 Mono.SystemDependencyProvider.Initialize (); +#endif InitializePlatform (options); -#if !XAMMAC_SYSTEM_MONO +#if !XAMMAC_SYSTEM_MONO && !NET_TODO + // NET_TODO: https://github.com/dotnet/runtime/issues/32543 UseAutoreleasePoolInThreadPool = true; #endif IsARM64CallingConvention = GetIsARM64CallingConvention (); // Can only be done after Runtime.Arch is set (i.e. InitializePlatform has been called). @@ -270,7 +276,8 @@ unsafe static void Initialize (InitializationOptions* options) #endif } -#if !XAMMAC_SYSTEM_MONO +#if !XAMMAC_SYSTEM_MONO && !NET_TODO + // NET_TODO: https://github.com/dotnet/runtime/issues/32543 static bool has_autoreleasepool_in_thread_pool; public static bool UseAutoreleasePoolInThreadPool { get { diff --git a/src/Resources.Designer.cs b/src/Resources.Designer.cs index 83c1cdd205ff..7dfbcb130d4a 100644 --- a/src/Resources.Designer.cs +++ b/src/Resources.Designer.cs @@ -605,6 +605,12 @@ internal static string BI1080 { } } + internal static string BI1081 { + get { + return ResourceManager.GetString("BI1081", resourceCulture); + } + } + internal static string BI1101 { get { return ResourceManager.GetString("BI1101", resourceCulture); diff --git a/src/Resources.resx b/src/Resources.resx index 7daf260182c7..1b414190d074 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -766,6 +766,12 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/Security/Certificate.cs b/src/Security/Certificate.cs index 8053e492c0c1..0c0b70260ade 100644 --- a/src/Security/Certificate.cs +++ b/src/Security/Certificate.cs @@ -28,7 +28,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if XAMARIN_APPLETLS || WATCH +#if (XAMARIN_APPLETLS || WATCH) && !NET #define NATIVE_APPLE_CERTIFICATE #endif diff --git a/src/System.Net.Http/CFContentStream.cs b/src/System.Net.Http/CFContentStream.cs index bdd3518ad57b..6b671f018fcf 100644 --- a/src/System.Net.Http/CFContentStream.cs +++ b/src/System.Net.Http/CFContentStream.cs @@ -147,7 +147,10 @@ protected override async Task SerializeToStreamAsync (Stream stream, TransportCo } } - protected internal override bool TryComputeLength (out long length) +#if !NET + internal +#endif + protected override bool TryComputeLength (out long length) { length = 0; return false; diff --git a/src/System.Net.Http/CFNetworkHandler.cs b/src/System.Net.Http/CFNetworkHandler.cs index 60e252ea49b0..d7a8abc23d32 100644 --- a/src/System.Net.Http/CFNetworkHandler.cs +++ b/src/System.Net.Http/CFNetworkHandler.cs @@ -194,7 +194,10 @@ CFHTTPMessage CreateWebRequestAsync (HttpRequestMessage request) return req; } - protected internal override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) +#if !NET + internal +#endif + protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) { return await SendAsync (request, cancellationToken, true).ConfigureAwait (false); } @@ -381,6 +384,10 @@ void HandleHasBytesAvailableEvent (object sender, CFStream.StreamEventArgs e) void AddCookie (string value, Uri uri, string header) { +#if !NET_TODO + // NET_TODO: CookieCollection.CookieCutter is internal to mscorlib: + // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/System/net/System/Net/cookiecontainer.cs#L632 + // https://github.com/xamarin/xamarin-macios/issues/8072 CookieCollection cookies1 = null; try { cookies1 = cookies.CookieCutter (uri, header, value, false); @@ -389,6 +396,7 @@ void AddCookie (string value, Uri uri, string header) if (cookies1 != null && cookies1.Count != 0) cookies.Add (cookies1); +#endif } static bool IsContentHeader (string header) diff --git a/src/bgen b/src/bgen/bgen similarity index 100% rename from src/bgen rename to src/bgen/bgen diff --git a/src/bgen/bgen.csproj b/src/bgen/bgen.csproj new file mode 100644 index 000000000000..fcebddf9e6ca --- /dev/null +++ b/src/bgen/bgen.csproj @@ -0,0 +1,390 @@ + + + + + netcoreapp3.1 + Exe + DEBUG;BGENERATOR;NET_4_0;NO_AUTHENTICODE;STATIC;NO_SYMBOL_WRITER + + + + + + + + + + $(MSBuildThisFileDirectory)/../.. + $(MSBuildThisFileDirectory)/../build/dotnet + $(RepositoryPath)/builds + $(BUILD_DIR)\ + ..\build\ + + + + + generator-errors.md + + + ikvm\ITypeOwner.cs + + + ikvm\SymbolSupport.cs + + + ikvm\CryptoConvert.cs + + + ikvm\AmbiguousMatchException.cs + + + ikvm\Assembly.cs + + + ikvm\AssemblyName.cs + + + ikvm\BadImageFormatException.cs + + + ikvm\Binder.cs + + + ikvm\ConstructorInfo.cs + + + ikvm\CustomAttributeData.cs + + + ikvm\CustomAttributeNamedArgument.cs + + + ikvm\CustomAttributeTypedArgument.cs + + + ikvm\CustomModifiers.cs + + + ikvm\Enums.cs + + + ikvm\EventInfo.cs + + + ikvm\ExceptionHandlingClause.cs + + + ikvm\FieldInfo.cs + + + ikvm\FieldSignature.cs + + + ikvm\Fusion.cs + + + ikvm\GenericWrappers.cs + + + ikvm\InterfaceMapping.cs + + + ikvm\LocalVariableInfo.cs + + + ikvm\ManifestResourceInfo.cs + + + ikvm\MarshalSpec.cs + + + ikvm\MemberInfo.cs + + + ikvm\MethodBase.cs + + + ikvm\MethodBody.cs + + + ikvm\MethodImplMap.cs + + + ikvm\MethodInfo.cs + + + ikvm\MethodSignature.cs + + + ikvm\Missing.cs + + + ikvm\Module.cs + + + ikvm\ParameterInfo.cs + + + ikvm\ParameterModifier.cs + + + ikvm\Projection.cs + + + ikvm\PropertyInfo.cs + + + ikvm\PropertySignature.cs + + + ikvm\Signature.cs + + + ikvm\StandAloneMethodSig.cs + + + ikvm\StrongNameKeyPair.cs + + + ikvm\Type.cs + + + ikvm\TypeInfo.cs + + + ikvm\TypeNameParser.cs + + + ikvm\Universe.cs + + + ikvm\Util.cs + + + ikvm\coreclr.cs + + + ikvm\AssemblyBuilder.cs + + + ikvm\ConstructorBuilder.cs + + + ikvm\CustomAttributeBuilder.cs + + + ikvm\CustomModifiersBuilder.cs + + + ikvm\EnumBuilder.cs + + + ikvm\Enums.cs + + + ikvm\EventBuilder.cs + + + ikvm\ExceptionHandler.cs + + + ikvm\FieldBuilder.cs + + + ikvm\ILGenerator.cs + + + ikvm\MethodBuilder.cs + + + ikvm\ModuleBuilder.cs + + + ikvm\OpCode.cs + + + ikvm\OpCodes.cs + + + ikvm\ParameterBuilder.cs + + + ikvm\PropertyBuilder.cs + + + ikvm\SignatureHelper.cs + + + ikvm\Tokens.cs + + + ikvm\TypeBuilder.cs + + + ikvm\CliHeader.cs + + + ikvm\MetadataRW.cs + + + ikvm\Tables.cs + + + ikvm\AssemblyReader.cs + + + ikvm\Authenticode.cs + + + ikvm\ByteReader.cs + + + ikvm\EventInfoImpl.cs + + + ikvm\Field.cs + + + ikvm\GenericTypeParameter.cs + + + ikvm\MetadataReader.cs + + + ikvm\Method.cs + + + ikvm\ModuleReader.cs + + + ikvm\PEReader.cs + + + ikvm\PropertyInfoImpl.cs + + + ikvm\ResourceModule.cs + + + ikvm\TypeDefImpl.cs + + + ikvm\ByteBuffer.cs + + + ikvm\Heaps.cs + + + ikvm\MetadataWriter.cs + + + ikvm\ModuleWriter.cs + + + ikvm\PEWriter.cs + + + ikvm\ResourceSection.cs + + + ikvm\TextSection.cs + + + ikvm\VersionInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execution.cs + + + ..\Resources.resx + + + + + ResXFileCodeGenerator + ..\Resources.Designer.cs + + + + + Project + + $(ProjectDir) + true + + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + + + + diff --git a/src/bgen/bgen.sln b/src/bgen/bgen.sln new file mode 100644 index 000000000000..f2f8607d4df9 --- /dev/null +++ b/src/bgen/bgen.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bgen", "bgen.csproj", "{B42BBC30-27F6-4C49-8727-216DC75B042C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bgen-tests", "..\..\tests\bgen\bgen-tests.csproj", "{5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.Build.0 = Release|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/btouch.cs b/src/btouch.cs index 6b798b88dfb7..656761092b06 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -70,6 +70,10 @@ public static string ToolName { get { return "bgen"; } } + bool IsDotNet { + get { return TargetFramework.IsDotNet; } + } + static void ShowHelp (OptionSet os) { Console.WriteLine ("{0} - Mono Objective-C API binder", ToolName); @@ -117,31 +121,33 @@ string GetAttributeLibraryPath () IEnumerable GetLibraryDirectories () { - switch (CurrentPlatform) { - case PlatformName.iOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.iOS"); - break; - case PlatformName.WatchOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.WatchOS"); - break; - case PlatformName.TvOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.TVOS"); - break; - case PlatformName.MacOSX: - if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) { - yield return Path.Combine (GetSDKRoot (), "lib", "reference", "full"); - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); - } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { - yield return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5"; - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); - } else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) { - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac"); - } else { - throw ErrorHelper.CreateError (1053, target_framework); + if (!IsDotNet) { + switch (CurrentPlatform) { + case PlatformName.iOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.iOS"); + break; + case PlatformName.WatchOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.WatchOS"); + break; + case PlatformName.TvOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.TVOS"); + break; + case PlatformName.MacOSX: + if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) { + yield return Path.Combine (GetSDKRoot (), "lib", "reference", "full"); + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); + } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { + yield return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5"; + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); + } else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) { + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac"); + } else { + throw ErrorHelper.CreateError (1053, target_framework); + } + break; + default: + throw new BindingException (1047, CurrentPlatform); } - break; - default: - throw new BindingException (1047, CurrentPlatform); } foreach (var lib in libs) yield return lib; @@ -334,24 +340,30 @@ int Main3 (string [] args) nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.iOS/Xamarin.iOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.iOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.iOS", references); + } break; case ApplePlatform.TVOS: CurrentPlatform = PlatformName.TvOS; nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.TVOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.TVOS", references); + } break; case ApplePlatform.WatchOS: CurrentPlatform = PlatformName.WatchOS; nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.WatchOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.WatchOS", references); + } break; case ApplePlatform.MacOSX: CurrentPlatform = PlatformName.MacOSX; @@ -375,6 +387,8 @@ int Main3 (string [] args) } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { skipSystemDrawing = false; ReferenceFixer.FixSDKReferences ("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5", references, forceSystemDrawing : true); + } else if (target_framework == TargetFramework.DotNet_5_0_macOS) { + skipSystemDrawing = false; } else { throw ErrorHelper.CreateError (1053, target_framework); } @@ -441,6 +455,39 @@ int Main3 (string [] args) universe = new Universe (UniverseOptions.EnableFunctionPointers | UniverseOptions.ResolveMissingMembers | UniverseOptions.MetadataOnly); + if (IsDotNet) { + // IKVM tries uses reflection to locate assemblies on disk, but .NET doesn't include reflection so that fails. + // Instead intercept assembly resolution and look for assemblies where we know they are. + var resolved_assemblies = new Dictionary (); + universe.AssemblyResolve += (object sender, IKVM.Reflection.ResolveEventArgs rea) => { + var an = new AssemblyName (rea.Name); + + // Check if we've already found this assembly + if (resolved_assemblies.TryGetValue (an.Name, out var rv)) + return rv; + + // Check if the assembly has already been loaded into IKVM + var assemblies = universe.GetAssemblies (); + foreach (var asm in assemblies) { + if (asm.GetName ().Name == an.Name) { + resolved_assemblies [an.Name] = asm; + return asm; + } + } + + // Look in the references to find a matching one and get the path from there. + foreach (var r in references) { + var fn = Path.GetFileNameWithoutExtension (r); + if (fn == an.Name) { + rv = universe.LoadFile (r); + resolved_assemblies [an.Name] = rv; + return rv; + } + } + + throw ErrorHelper.CreateError (1081, rea.Name); + }; + } Assembly api; try { @@ -481,6 +528,18 @@ int Main3 (string [] args) } foreach (var r in references) { + // IKVM has a bug where it doesn't correctly compare assemblies, which means it + // can end up loading the same assembly (in particular any System.Runtime whose + // version > 4.0, but likely others as well) more than once. This is bad, because + // we compare types based on reference equality, which breaks down when there are + // multiple instances of the same type. + // + // So just don't ask IKVM to load assemblies that have already been loaded. + var fn = Path.GetFileNameWithoutExtension (r); + var assemblies = universe.GetAssemblies (); + if (assemblies.Any ((v) => v.GetName ().Name == fn)) + continue; + if (File.Exists (r)) { try { universe.LoadFile (r); diff --git a/src/frameworks.sources b/src/frameworks.sources index 95e18b5fbc17..fd9ce631fa53 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -351,6 +351,7 @@ COMPRESSION_SOURCES = \ Compression/Deflater.cs \ Compression/Enums.cs \ Compression/Inflater.cs \ + Compression/TaskToApm.cs \ # Contacts diff --git a/src/xlf/Resources.cs.xlf b/src/xlf/Resources.cs.xlf index 492cbda7464f..d6799ffefeab 100644 --- a/src/xlf/Resources.cs.xlf +++ b/src/xlf/Resources.cs.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.de.xlf b/src/xlf/Resources.de.xlf index a2d5352b8575..3cd6db26e77e 100644 --- a/src/xlf/Resources.de.xlf +++ b/src/xlf/Resources.de.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.es.xlf b/src/xlf/Resources.es.xlf index 5985b82bc31c..32b94f25400e 100644 --- a/src/xlf/Resources.es.xlf +++ b/src/xlf/Resources.es.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.fr.xlf b/src/xlf/Resources.fr.xlf index 7d66a9157a1d..d89f13e67c63 100644 --- a/src/xlf/Resources.fr.xlf +++ b/src/xlf/Resources.fr.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.it.xlf b/src/xlf/Resources.it.xlf index c6872587853c..70f8de50cbb6 100644 --- a/src/xlf/Resources.it.xlf +++ b/src/xlf/Resources.it.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ja.xlf b/src/xlf/Resources.ja.xlf index f991fb3e6a8e..8daac048a46a 100644 --- a/src/xlf/Resources.ja.xlf +++ b/src/xlf/Resources.ja.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ko.xlf b/src/xlf/Resources.ko.xlf index 2b31a5fda8e3..236d7e8be8c3 100644 --- a/src/xlf/Resources.ko.xlf +++ b/src/xlf/Resources.ko.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.pl.xlf b/src/xlf/Resources.pl.xlf index 9b93f48c6a50..28d154ef75b1 100644 --- a/src/xlf/Resources.pl.xlf +++ b/src/xlf/Resources.pl.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.pt-BR.xlf b/src/xlf/Resources.pt-BR.xlf index 022853d3abf0..d3108891ed35 100644 --- a/src/xlf/Resources.pt-BR.xlf +++ b/src/xlf/Resources.pt-BR.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ru.xlf b/src/xlf/Resources.ru.xlf index 203333416d95..fbc267c05e30 100644 --- a/src/xlf/Resources.ru.xlf +++ b/src/xlf/Resources.ru.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.tr.xlf b/src/xlf/Resources.tr.xlf index 2380420a8e13..d73ff2f83e99 100644 --- a/src/xlf/Resources.tr.xlf +++ b/src/xlf/Resources.tr.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.zh-Hans.xlf b/src/xlf/Resources.zh-Hans.xlf index 6cf316a00a94..b1014ea85d71 100644 --- a/src/xlf/Resources.zh-Hans.xlf +++ b/src/xlf/Resources.zh-Hans.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.zh-Hant.xlf b/src/xlf/Resources.zh-Hant.xlf index 5b8a61413e56..af789b5a43f6 100644 --- a/src/xlf/Resources.zh-Hant.xlf +++ b/src/xlf/Resources.zh-Hant.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/tests/Makefile b/tests/Makefile index e13dc2b7218b..2fb37bb66b16 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -95,6 +95,7 @@ test.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @echo "MONO_IOS_SDK_DESTDIR=$(MONO_IOS_SDK_DESTDIR)" >> $@ @echo "MONO_MAC_SDK_DESTDIR=$(MONO_MAC_SDK_DESTDIR)" >> $@ @echo "ENABLE_XAMARIN=$(ENABLE_XAMARIN)" >> $@ + @echo "DOTNET=$(DOTNET)" >> $@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @rm -f $@ @@ -105,6 +106,7 @@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @echo "INCLUDE_DEVICE=$(INCLUDE_DEVICE)" >> $@ @echo "MONO_IOS_SDK_DESTDIR=$(MONO_IOS_SDK_DESTDIR)" >> $@ @echo "MONO_MAC_SDK_DESTDIR=$(MONO_MAC_SDK_DESTDIR)" >> $@ + @echo "DOTNET=$(DOTNET)" >> $@ clean-local:: $(Q) $(SYSTEM_XBUILD) /t:Clean /p:Platform=iPhoneSimulator /p:Configuration=$(CONFIG) $(XBUILD_VERBOSITY) tests.sln diff --git a/tests/bgen/bgen-tests.csproj b/tests/bgen/bgen-tests.csproj new file mode 100644 index 000000000000..9a70dc9ce8e3 --- /dev/null +++ b/tests/bgen/bgen-tests.csproj @@ -0,0 +1,52 @@ + + + + netcoreapp3.1 + bgen_tests + + false + + + + + + + + + + + + + + + Asserts.cs + + + BGenTests.cs + + + BGenTool.cs + + + ErrorTests.cs + + + GeneratorTests.cs + + + Configuration.cs + + + ExecutionHelper.cs + + + Profile.cs + + + Cache.cs + + + StringUtils.cs + + + diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 1b48e68aed4c..7c7396815db5 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -105,6 +105,7 @@ public static string RootDirectory { public string MONO_MAC_SDK_DESTDIR { get; set; } public bool IncludeMac32 { get; set; } public bool ENABLE_XAMARIN { get; set; } + public string DOTNET { get; set; } // Run public AppRunnerTarget Target { get; set; } @@ -270,6 +271,7 @@ void LoadConfig () MONO_IOS_SDK_DESTDIR = make_config ["MONO_IOS_SDK_DESTDIR"]; MONO_MAC_SDK_DESTDIR = make_config ["MONO_MAC_SDK_DESTDIR"]; ENABLE_XAMARIN = make_config.ContainsKey ("ENABLE_XAMARIN") && !string.IsNullOrEmpty (make_config ["ENABLE_XAMARIN"]); + DOTNET = make_config ["DOTNET"]; } int AutoConfigureMac (bool generate_projects) diff --git a/tests/xharness/Jenkins/Jenkins.cs b/tests/xharness/Jenkins/Jenkins.cs index b9b3a5044447..e480a72f1288 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -743,6 +743,7 @@ void SelectTestsByModifiedFiles (int pull_request) "src/generator.cs", "src/generator-", "src/Makefile.generator", + "tests/bgen", "tests/generator", "tests/common", }; @@ -1096,11 +1097,28 @@ Task PopulateTasksAsync () TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "generator", "generator-tests.csproj"))), Platform = TestPlatform.iOS, TestName = "Generator tests", + Mode = "NUnit", Timeout = TimeSpan.FromMinutes (10), Ignored = !IncludeBtouch, }; Tasks.Add (runGenerator); + var buildDotNetGenerator = new DotNetBuildTask { + Jenkins = this, + TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "bgen", "bgen-tests.csproj"))), + SpecifyPlatform = false, + SpecifyConfiguration = false, + Platform = TestPlatform.iOS, + }; + var runDotNetGenerator = new DotNetTestTask (buildDotNetGenerator) { + TestProject = buildDotNetGenerator.TestProject, + Platform = TestPlatform.iOS, + TestName = "Generator tests", + Mode = ".NET", + Ignored = !IncludeBtouch, + }; + Tasks.Add (runDotNetGenerator); + var run_mmp = new MakeTask { Jenkins = this, @@ -1751,6 +1769,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) var allNUnitTasks = new List (); var allMakeTasks = new List (); var allDeviceTasks = new List (); + var allDotNetTestTasks = new List (); foreach (var task in Tasks) { var aggregated = task as AggregatedRunSimulatorTask; if (aggregated != null) { @@ -1782,6 +1801,11 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) continue; } + if (task is DotNetTestTask dotnet) { + allDotNetTestTasks.Add (dotnet); + continue; + } + throw new NotImplementedException (); } @@ -1792,6 +1816,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) allTasks.AddRange (allNUnitTasks); allTasks.AddRange (allMakeTasks); allTasks.AddRange (allDeviceTasks); + allTasks.AddRange (allDotNetTestTasks); } var failedTests = allTasks.Where ((v) => v.Failed); diff --git a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs new file mode 100644 index 000000000000..3a59966be35a --- /dev/null +++ b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Diagnostics; + +namespace Xharness.Jenkins.TestTasks { + class DotNetBuildTask : MSBuildTask { + + public DotNetBuildTask () + { + SetDotNetEnvironmentVariables (Environment); + } + + protected override string ToolName { + get { return Harness.DOTNET; } + } + + protected override List ToolArguments { + get { + var args = base.ToolArguments; + // 'dotnet build' takes almost the same arguments as 'msbuild', so just massage a little bit. + args.Remove ("--"); + args.Insert (0, "build"); + return args; + } + } + + + public static void SetDotNetEnvironmentVariables (Dictionary environment) + { + environment ["MSBUILD_EXE_PATH"] = null; + environment ["MSBuildExtensionsPathFallbackPathsOverride"] = null; + environment ["MSBuildSDKsPath"] = null; + environment ["TargetFrameworkFallbackSearchPaths"] = null; + environment ["MSBuildExtensionsPathFallbackPathsOverride"] = null; + } + } +} diff --git a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs new file mode 100644 index 000000000000..e018691e38af --- /dev/null +++ b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Xharness.Logging; + +namespace Xharness.Jenkins.TestTasks { + class DotNetTestTask : RunTestTask { + public DotNetTestTask (DotNetBuildTask build_task) + : base (build_task) + { + DotNetBuildTask.SetDotNetEnvironmentVariables (Environment); + } + + protected override async Task RunTestAsync () + { + using (var resource = await NotifyAndAcquireDesktopResourceAsync ()) { + var trx = Logs.Create ($"results-{Timestamp}.trx", LogType.TrxLog.ToString ()); + var html = Logs.Create ($"results-{Timestamp}.html", LogType.HtmlLog.ToString ()); + + var args = new List { + "test", + BuildTask.ProjectFile, + "--results-directory:" + Logs.Directory, + "--logger:console;verbosity=detailed", + "--logger:trx;LogFileName=" + Path.GetFileName (trx.FullPath), + "--logger:html;LogFileName=" + Path.GetFileName (html.FullPath) + }; + + await ExecuteProcessAsync (Harness.DOTNET, args); + } + } + } +} diff --git a/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs b/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs index 8da4f79ad9d4..ec76713216e2 100644 --- a/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs +++ b/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs @@ -12,26 +12,37 @@ class MSBuildTask : BuildProjectTask { public ILog BuildLog; + protected virtual string ToolName { + get { return Harness.XIBuildPath; } + } + + protected virtual List ToolArguments { + get { + var binlogPath = BuildLog.FullPath.Replace (".txt", ".binlog"); + + var args = new List (); + args.Add ("--"); + args.Add ("/verbosity:diagnostic"); + args.Add ($"/bl:{binlogPath}"); + if (SpecifyPlatform) + args.Add ($"/p:Platform={ProjectPlatform}"); + if (SpecifyConfiguration) + args.Add ($"/p:Configuration={ProjectConfiguration}"); + args.Add (ProjectFile); + return args; + } + } + protected override async Task ExecuteAsync () { using (var resource = await NotifyAndAcquireDesktopResourceAsync ()) { BuildLog = Logs.Create ($"build-{Platform}-{Timestamp}.txt", LogType.BuildLog.ToString ()); - var binlogPath = BuildLog.FullPath.Replace (".txt", ".binlog"); await RestoreNugetsAsync (BuildLog, resource, useXIBuild: true); using (var xbuild = new Process ()) { - xbuild.StartInfo.FileName = Harness.XIBuildPath; - var args = new List (); - args.Add ("--"); - args.Add ("/verbosity:diagnostic"); - args.Add ($"/bl:{binlogPath}"); - if (SpecifyPlatform) - args.Add ($"/p:Platform={ProjectPlatform}"); - if (SpecifyConfiguration) - args.Add ($"/p:Configuration={ProjectConfiguration}"); - args.Add (ProjectFile); - xbuild.StartInfo.Arguments = StringUtils.FormatArguments (args); + xbuild.StartInfo.FileName = ToolName; + xbuild.StartInfo.Arguments = StringUtils.FormatArguments (ToolArguments); SetEnvironmentVariables (xbuild); xbuild.StartInfo.EnvironmentVariables ["MSBuildExtensionsPath"] = null; LogEvent (BuildLog, "Building {0} ({1})", TestName, Mode); diff --git a/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs b/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs index 7748727fb1cb..3bc600632cac 100644 --- a/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs +++ b/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs @@ -16,11 +16,8 @@ class NUnitExecuteTask : RunTestTask { public string TestLibrary; public string TestExecutable; - public string WorkingDirectory; public bool ProduceHtmlReport = true; public bool InProcess; - public TimeSpan Timeout = TimeSpan.FromMinutes (10); - IProcessManager ProcessManager { get; set; } = new ProcessManager (); public NUnitExecuteTask (BuildToolTask build_task) : base (build_task) @@ -119,45 +116,22 @@ protected override async Task RunTestAsync () var xmlLog = Logs.CreateFile ($"log-{Timestamp}.xml", LogType.XmlLog.ToString ()); var log = Logs.Create ($"execute-{Timestamp}.txt", LogType.ExecutionLog.ToString ()); FindNUnitConsoleExecutable (log); - using (var proc = new Process ()) { - proc.StartInfo.WorkingDirectory = WorkingDirectory; - proc.StartInfo.FileName = Harness.XIBuildPath; - var args = new List (); - args.Add ("-t"); - args.Add ("--"); - args.Add (Path.GetFullPath (TestExecutable)); - args.Add (Path.GetFullPath (TestLibrary)); - if (IsNUnit3) { - args.Add ("-result=" + xmlLog + ";format=nunit2"); - args.Add ("--labels=All"); - if (InProcess) - args.Add ("--inprocess"); - } else { - args.Add ("-xml=" + xmlLog); - args.Add ("-labels"); - } - proc.StartInfo.Arguments = StringUtils.FormatArguments (args); - SetEnvironmentVariables (proc); - foreach (DictionaryEntry de in proc.StartInfo.EnvironmentVariables) - log.WriteLine ($"export {de.Key}={de.Value}"); - Jenkins.MainLog.WriteLine ("Executing {0} ({1})", TestName, Mode); - if (!Harness.DryRun) { - ExecutionResult = TestExecutingResult.Running; - var result = await ProcessManager.RunAsync (proc, log, Timeout); - if (result.TimedOut) { - FailureMessage = $"Execution timed out after {Timeout.TotalMinutes} minutes."; - log.WriteLine (FailureMessage); - ExecutionResult = TestExecutingResult.TimedOut; - } else if (result.Succeeded) { - ExecutionResult = TestExecutingResult.Succeeded; - } else { - ExecutionResult = TestExecutingResult.Failed; - FailureMessage = $"Execution failed with exit code {result.ExitCode}"; - } - } - Jenkins.MainLog.WriteLine ("Executed {0} ({1})", TestName, Mode); + var args = new List (); + args.Add ("-t"); + args.Add ("--"); + args.Add (Path.GetFullPath (TestExecutable)); + args.Add (Path.GetFullPath (TestLibrary)); + if (IsNUnit3) { + args.Add ("-result=" + xmlLog + ";format=nunit2"); + args.Add ("--labels=All"); + if (InProcess) + args.Add ("--inprocess"); + } else { + args.Add ("-xml=" + xmlLog); + args.Add ("-labels"); } + await ExecuteProcessAsync (log, Harness.XIBuildPath, args); if (ProduceHtmlReport) { try { diff --git a/tests/xharness/Jenkins/TestTasks/RunTestTask.cs b/tests/xharness/Jenkins/TestTasks/RunTestTask.cs index 652b3a729658..ad2e4b9a0051 100644 --- a/tests/xharness/Jenkins/TestTasks/RunTestTask.cs +++ b/tests/xharness/Jenkins/TestTasks/RunTestTask.cs @@ -1,14 +1,22 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Xharness.Execution; using Xharness.Logging; +using Xharness.Utilities; namespace Xharness.Jenkins.TestTasks { internal abstract class RunTestTask : TestTask { public readonly BuildToolTask BuildTask; + public TimeSpan Timeout = TimeSpan.FromMinutes (10); public double TimeoutMultiplier { get; set; } = 1; + IProcessManager ProcessManager { get; } = new ProcessManager (); + public string WorkingDirectory; public RunTestTask (BuildToolTask build_task) { @@ -105,5 +113,41 @@ public override void Reset () base.Reset (); BuildTask.Reset (); } + + protected Task ExecuteProcessAsync (string filename, List arguments) + { + return ExecuteProcessAsync (null, filename, arguments); + } + + protected async Task ExecuteProcessAsync (ILog log, string filename, List arguments) + { + if (log == null) + log = Logs.Create ($"execute-{Timestamp}.txt", LogType.ExecutionLog.ToString ()); + + using var proc = new Process (); + proc.StartInfo.FileName = filename; + proc.StartInfo.Arguments = StringUtils.FormatArguments (arguments); + if (!string.IsNullOrEmpty (WorkingDirectory)) + proc.StartInfo.WorkingDirectory = WorkingDirectory; + SetEnvironmentVariables (proc); + foreach (DictionaryEntry de in proc.StartInfo.EnvironmentVariables) + log.WriteLine ($"export {de.Key}={de.Value}"); + Jenkins.MainLog.WriteLine ("Executing {0} ({1})", TestName, Mode); + if (!Harness.DryRun) { + ExecutionResult = TestExecutingResult.Running; + var result = await ProcessManager.RunAsync (proc, log, Timeout); + if (result.TimedOut) { + FailureMessage = $"Execution timed out after {Timeout.TotalMinutes} minutes."; + log.WriteLine (FailureMessage); + ExecutionResult = TestExecutingResult.TimedOut; + } else if (result.Succeeded) { + ExecutionResult = TestExecutingResult.Succeeded; + } else { + ExecutionResult = TestExecutingResult.Failed; + FailureMessage = $"Execution failed with exit code {result.ExitCode}"; + } + } + Jenkins.MainLog.WriteLine ("Executed {0} ({1})", TestName, Mode); + } } } diff --git a/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs b/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs index 6884e2e9a6da..c0a93467ae68 100644 --- a/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs +++ b/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs @@ -7,9 +7,6 @@ namespace Xharness.Jenkins.TestTasks { class RunXtroTask : MacExecuteTask { - - public string WorkingDirectory; - public RunXtroTask (BuildToolTask build_task) : base (build_task) { } diff --git a/tests/xharness/Logging/ILog.cs b/tests/xharness/Logging/ILog.cs index 2f2ad5c24e56..fed96b84e33c 100644 --- a/tests/xharness/Logging/ILog.cs +++ b/tests/xharness/Logging/ILog.cs @@ -14,6 +14,8 @@ public enum LogType { TestLog, ExtensionTestLog, ExecutionLog, + TrxLog, + HtmlLog, } public static class LogTypeExtensions { @@ -37,6 +39,10 @@ public static string ToString (this LogType type) return "Extension test log"; case LogType.ExecutionLog: return "Execution log"; + case LogType.TrxLog: + return "Test log (trx)"; + case LogType.HtmlLog: + return "Test log (html)"; default: throw new ArgumentException ($"Unknown type for {nameof (type)}"); } diff --git a/tests/xharness/xharness.csproj b/tests/xharness/xharness.csproj index ca507b448b29..005acd622f2b 100644 --- a/tests/xharness/xharness.csproj +++ b/tests/xharness/xharness.csproj @@ -10,6 +10,7 @@ Xharness xharness v4.7.2 + 8.0 true @@ -104,6 +105,8 @@ + + diff --git a/tools/common/TargetFramework.cs b/tools/common/TargetFramework.cs index 4a07c1f688de..2037c39532be 100644 --- a/tools/common/TargetFramework.cs +++ b/tools/common/TargetFramework.cs @@ -41,16 +41,26 @@ public struct TargetFramework : IEquatable public static readonly TargetFramework Xamarin_Mac_2_0_Mobile = Parse ("Xamarin.Mac,Version=v2.0,Profile=Mobile"); public static readonly TargetFramework Xamarin_Mac_4_5_Full = Parse ("Xamarin.Mac,Version=v4.5,Profile=Full"); public static readonly TargetFramework Xamarin_Mac_4_5_System = Parse ("Xamarin.Mac,Version=v4.5,Profile=System"); + + public static readonly TargetFramework DotNet_5_0_iOS = Parse (".NETCoreApp,Version=5.0,Profile=ios"); // Short form: net5.0-ios + public static readonly TargetFramework DotNet_5_0_tvOS = Parse (".NETCoreApp,Version=5.0,Profile=tvos"); // Short form: net5.0-tvos + public static readonly TargetFramework DotNet_5_0_watchOS = Parse (".NETCoreApp,Version=5.0,Profile=watchos"); // Short form: net5.0-watchos + public static readonly TargetFramework DotNet_5_0_macOS = Parse (".NETCoreApp,Version=5.0,Profile=macos"); // Short form: net5.0-macos #if MTOUCH public static readonly TargetFramework [] ValidFrameworks = new TargetFramework[] { Xamarin_iOS_1_0, Xamarin_WatchOS_1_0, Xamarin_TVOS_1_0 }; #elif BGENERATOR public static readonly TargetFramework [] ValidFrameworks = new TargetFramework[] { Xamarin_iOS_1_0, Xamarin_TVOS_1_0, Xamarin_WatchOS_1_0, - Xamarin_Mac_2_0_Mobile, Xamarin_Mac_4_5_Full, Xamarin_Mac_4_5_System + Xamarin_Mac_2_0_Mobile, Xamarin_Mac_4_5_Full, Xamarin_Mac_4_5_System, + DotNet_5_0_iOS, DotNet_5_0_macOS, DotNet_5_0_tvOS, DotNet_5_0_watchOS, }; #endif + public bool IsDotNet { + get { return Identifier == ".NETCoreApp" && Version.Major >= 5; } + } + public static TargetFramework Parse (string targetFrameworkString) { TargetFramework targetFramework; @@ -209,6 +219,19 @@ public ApplePlatform Platform { return ApplePlatform.WatchOS; case "Xamarin.TVOS": return ApplePlatform.TVOS; + case ".NETCoreApp": + switch (Profile) { + case "ios": + return ApplePlatform.iOS; + case "tvos": + return ApplePlatform.TVOS; + case "watchos": + return ApplePlatform.WatchOS; + case "macos": + return ApplePlatform.MacOSX; + default: + throw new InvalidOperationException (string.Format ("Invalid .NETCoreApp Profile for Apple platforms: {0}", Profile)); + } default: return ApplePlatform.MacOSX; }