From 6dc1f4c69b0d99b504726a99e715cca3ba0c35ea Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 20 May 2024 20:17:29 +0200 Subject: [PATCH] [msbuild/dotnet] Automatically link with Swift's system libraries if a binding project has the IsSwift=true property. (#20546) Add support for the LinkWithSwiftSystemLibraries metadata to specify whether a native library is a Swift library, in which case we'll automatically set the `LinkWithSwiftSystemLibraries` MSBuild property to `true`. Also add a test. --- Make.config | 34 +++++++++++ dotnet/targets/Xamarin.Shared.Sdk.targets | 11 +++- mk/rules.mk | 48 +++++++++++++++ .../Tasks/CreateBindingResourcePackage.cs | 2 +- .../Tasks/PrepareNativeReferences.cs | 1 + .../Tasks/ResolveNativeReferences.cs | 1 + src/ObjCRuntime/LinkWithAttribute.cs | 6 ++ tests/bindings-test/ApiDefinition.cs | 8 +++ tests/bindings-test/RuntimeTest.cs | 10 ++++ tests/bindings-test/dotnet/shared.csproj | 5 ++ tests/dotnet/UnitTests/ProjectTest.cs | 2 +- .../CreateBindingResourceTaskTests.cs | 3 + tests/test-libraries/Makefile | 59 +++++++++++++++---- .../SwiftTest-Info-iphoneos.plist | 57 ++++++++++++++++++ .../SwiftTest-Info-iphonesimulator.plist | 57 ++++++++++++++++++ .../SwiftTest-Info-maccatalyst.plist | 48 +++++++++++++++ .../test-libraries/SwiftTest-Info-macos.plist | 48 +++++++++++++++ .../test-libraries/SwiftTest-Info-tvos.plist | 56 ++++++++++++++++++ .../SwiftTest-Info-tvsimulator.plist | 56 ++++++++++++++++++ .../SwiftTest-Info-watchos.plist | 56 ++++++++++++++++++ .../SwiftTest-Info-watchsimulator.plist | 56 ++++++++++++++++++ tests/test-libraries/libSwiftTest.swift | 9 +++ tools/common/Assembly.cs | 10 ++++ .../Steps/ExtractBindingLibrariesStep.cs | 1 + 24 files changed, 628 insertions(+), 16 deletions(-) create mode 100644 tests/test-libraries/SwiftTest-Info-iphoneos.plist create mode 100644 tests/test-libraries/SwiftTest-Info-iphonesimulator.plist create mode 100644 tests/test-libraries/SwiftTest-Info-maccatalyst.plist create mode 100644 tests/test-libraries/SwiftTest-Info-macos.plist create mode 100644 tests/test-libraries/SwiftTest-Info-tvos.plist create mode 100644 tests/test-libraries/SwiftTest-Info-tvsimulator.plist create mode 100644 tests/test-libraries/SwiftTest-Info-watchos.plist create mode 100644 tests/test-libraries/SwiftTest-Info-watchsimulator.plist create mode 100644 tests/test-libraries/libSwiftTest.swift diff --git a/Make.config b/Make.config index 57b4c3dc213a..b7245eed8795 100644 --- a/Make.config +++ b/Make.config @@ -390,6 +390,8 @@ IOS_PACKAGE_UTI=com.xamarin.$(IOS_PACKAGE_NAME_LOWER).pkg IOS_COMMON_DEFINES=-DMONOTOUCH +SWIFTC=$(XCODE_DEVELOPER_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc + IOS_CC=$(XCODE_CC) IOS_CXX=$(XCODE_CXX) SIMULATOR_BIN_PATH=$(XCODE_DEVELOPER_ROOT)/Platforms/iPhoneSimulator.platform/Developer/usr/bin @@ -502,6 +504,38 @@ MAC_OBJC_CFLAGS= -mmacosx-version-min=$(MIN_MACOS_SDK_VERSION) -DMONOMAC -DMIN_X MAC_CFLAGS = -mmacosx-version-min=$(MIN_MACOS_SDK_VERSION) -DMONOMAC -g -DMIN_XM_MONO_VERSION=\"$(MIN_XM_MONO_VERSION)\" $(CFLAGS) MAC_LDFLAGS = -mmacosx-version-min=$(MIN_MACOS_SDK_VERSION) -framework AppKit +# Swift compiler flags + +COMMON_SWIFTFLAGS=-g -emit-library + +IOS_SIMULATOR_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(SIMULATOR_SDK) +IOS_SIMULATOR_ARM64_SWIFTFLAGS=$(IOS_SIMULATOR_COMMON_SWIFTFLAGS) -target arm64-apple-ios$(MIN_IOS_SDK_VERSION)-simulator +IOS_SIMULATOR_X64_SWIFTFLAGS=$(IOS_SIMULATOR_COMMON_SWIFTFLAGS) -target x86_64-apple-ios$(MIN_IOS_SDK_VERSION)-simulator +IOS_DEVICE_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(DEVICE_SDK) +IOS_DEVICE_ARM64_SWIFTFLAGS=$(IOS_DEVICE_COMMON_SWIFTFLAGS) -target arm64-apple-ios$(MIN_IOS_SDK_VERSION) + +TVOS_SIMULATOR_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(SIMULATORTV_SDK) +TVOS_SIMULATOR_ARM64_SWIFTFLAGS=$(TVOS_SIMULATOR_COMMON_SWIFTFLAGS) -target arm64-apple-tvos$(MIN_TVOS_SDK_VERSION)-simulator +TVOS_SIMULATOR_X64_SWIFTFLAGS=$(TVOS_SIMULATOR_COMMON_SWIFTFLAGS) -target x86_64-apple-tvos$(MIN_TVOS_SDK_VERSION)-simulator +TVOS_DEVICE_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(DEVICETV_SDK) +TVOS_DEVICE_ARM64_SWIFTFLAGS=$(TVOS_DEVICE_COMMON_SWIFTFLAGS) -target arm64-apple-tvos$(MIN_TVOS_SDK_VERSION) + +WATCHOS_SIMULATOR_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(SIMULATORWATCH_SDK) +WATCHOS_SIMULATOR_ARM64_SWIFTFLAGS=$(WATCHOS_SIMULATOR_COMMON_SWIFTFLAGS) -target arm64-apple-watchos$(MIN_WATCHOS_SDK_VERSION)-simulator +WATCHOS_SIMULATOR_X64_SWIFTFLAGS=$(WATCHOS_SIMULATOR_COMMON_SWIFTFLAGS) -target x86_64-apple-watchos$(MIN_WATCHOS_SDK_VERSION)-simulator +WATCHOS_SIMULATOR_X86_SWIFTFLAGS=$(WATCHOS_SIMULATOR_COMMON_SWIFTFLAGS) -target x86-apple-watchos$(MIN_WATCHOS_SDK_VERSION)-simulator +WATCHOS_DEVICE_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(DEVICEWATCH_SDK) +WATCHOS_DEVICE_ARM64_32_SWIFTFLAGS=$(WATCHOS_DEVICE_COMMON_SWIFTFLAGS) -target arm64_32-apple-watchos$(MIN_WATCHOS_SDK_VERSION) +WATCHOS_DEVICE_ARMV7K_SWIFTFLAGS=$(WATCHOS_DEVICE_COMMON_SWIFTFLAGS) -target armv7k-apple-watchos$(MIN_WATCHOS_SDK_VERSION) + +MACCATALYST_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(XCODE_MAC_SDKROOT) +MACCATALYST_ARM64_SWIFTFLAGS=$(MACCATALYST_COMMON_SWIFTFLAGS) -target arm64-apple-ios$(MIN_MACCATALYST_SDK_VERSION)-macabi +MACCATALYST_X64_SWIFTFLAGS=$(MACCATALYST_COMMON_SWIFTFLAGS) -target x86_64-apple-ios$(MIN_MACCATALYST_SDK_VERSION)-macabi + +MACOS_COMMON_SWIFTFLAGS=$(COMMON_SWIFTFLAGS) -sdk $(XCODE_MAC_SDKROOT) +MACOS_ARM64_SWIFTFLAGS=$(MACOS_COMMON_SWIFTFLAGS) -target arm64-apple-macos$(MIN_MACOS_SDK_VERSION) +MACOS_X64_SWIFTFLAGS=$(MACOS_COMMON_SWIFTFLAGS) -target x86_64-apple-macos$(MIN_MACOS_SDK_VERSION) + # paths to the modules we depend on, as variables, so people can put # things in other places if they absolutely must. MONO_PATH=$(TOP)/external/mono diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 513f7b2357c7..eb60a1bf595a 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1479,7 +1479,7 @@ - + <_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'iOS' And '$(_SdkIsSimulator)' == 'true'">iphonesimulator <_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'iOS' And '$(_SdkIsSimulator)' != 'true'">iphoneos @@ -1487,8 +1487,15 @@ <_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'tvOS' And '$(_SdkIsSimulator)' != 'true'">appletvos <_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'MacCatalyst'">macosx <_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'macOS'">macosx + + <_HasBindingLibraryWithSwift Condition="@(_BindingLibraryLinkWith->WithMetadataValue('LinkWithSwiftSystemLibraries', 'true')->Count()) > 0">true + <_HasFrameworkNativeReferenceWithSwift Condition="@(_FrameworkNativeReference->WithMetadataValue('LinkWithSwiftSystemLibraries', 'true')->Count()) > 0">true + <_HasFileNativeReferenceWithSwift Condition="@(_FileNativeReference->WithMetadataValue('LinkWithSwiftSystemLibraries', 'true')->Count()) > 0">true + + + true - + <_MainLinkerFlags Include="-L$(_SdkDevPath)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(_SwiftTargetPlatform)/" /> <_MainLinkerFlags Include="-L$(_SdkRoot)/usr/lib/swift/" /> diff --git a/mk/rules.mk b/mk/rules.mk index 5c4e6d4791e7..dc95c7c8809f 100644 --- a/mk/rules.mk +++ b/mk/rules.mk @@ -49,6 +49,9 @@ define NativeCompilationTemplate .libs/iphonesimulator/%$(1).x86_64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/iphonesimulator $$(call Q_2,ASM, [iphonesimulator]) $(SIMULATOR_CC) $(SIMULATOR64_CFLAGS) $(SIM64_I) -g $(2) -c $$< -o $$@ +.libs/iphonesimulator/%$(1).x86_64.dylib: %.swift | .libs/iphonesimulator + $$(call Q_2,SWIFT, [iphonesimulator]) $(SWIFTC) $(IOS_SIMULATOR_X64_SWIFTFLAGS) $$< -o $$@ + .libs/iphonesimulator/%$(1).x86_64.dylib: | .libs/iphonesimulator $$(call Q_2,LD, [iphonesimulator]) $(SIMULATOR_CC) $(SIMULATOR64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_IOSSIMULATOR_SDK)/lib -fapplication-extension @@ -66,6 +69,9 @@ define NativeCompilationTemplate .libs/iphonesimulator/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/iphonesimulator $$(call Q_2,ASM, [iphonesimulator]) $(SIMULATOR_CC) $(SIMULATOR_ARM64_CFLAGS) $(SIM64_I) -g $(2) -c $$< -o $$@ +.libs/iphonesimulator/%$(1).arm64.dylib: %.swift | .libs/iphonesimulator + $$(call Q_2,SWIFT, [iphonesimulator]) $(SWIFTC) $(IOS_SIMULATOR_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/iphonesimulator/%$(1).arm64.dylib: | .libs/iphonesimulator $$(call Q_2,LD, [iphonesimulator]) $(SIMULATOR_CC) $(SIMULATOR_ARM64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_IOSSIMULATOR_SDK)/lib -fapplication-extension @@ -108,6 +114,9 @@ define NativeCompilationTemplate .libs/iphoneos/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/iphoneos $$(call Q_2,ASM, [iphoneos]) $(DEVICE_CC) $(DEVICE64_CFLAGS) $$(EXTRA_DEFINES) $(DEV64_I) -g $(2) -c $$< -o $$@ +.libs/iphoneos/%$(1).arm64.dylib: %.swift | .libs/iphoneos + $$(call Q_2,SWIFT, [iphoneos]) $(SWIFTC) $(IOS_DEVICE_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/iphoneos/%$(1).arm64.dylib: | .libs/iphoneos $$(call Q_2,LD, [iphoneos]) $(DEVICE_CC) $(DEVICE64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_IPHONEOS_SDK)/lib -fapplication-extension @@ -125,6 +134,9 @@ define NativeCompilationTemplate .libs/maccatalyst/%$(1).x86_64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/maccatalyst $$(call Q_2,ASM, [maccatalyst]) $(XCODE_CC) $(MACCATALYST_X86_64_CFLAGS) $(COMMON_I) -g $(2) -c $$< -o $$@ +.libs/maccatalyst/%$(1).x86_64.dylib: %.swift | .libs/maccatalyst + $$(call Q_2,SWIFT, [maccatalyst]) $(SWIFTC) $(MACCATALYST_X64_SWIFTFLAGS) $$< -o $$@ + .libs/maccatalyst/%$(1).x86_64.dylib: | .libs/maccatalyst $$(call Q_2,LD, [maccatalyst]) $(XCODE_CC) $(MACCATALYST_X86_64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_MACCATALYST_SDK)/lib -fapplication-extension @@ -140,6 +152,9 @@ define NativeCompilationTemplate .libs/maccatalyst/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/maccatalyst $$(call Q_2,ASM, [maccatalyst]) $(XCODE_CC) $(MACCATALYST_ARM64_CFLAGS) $(COMMON_I) -g $(2) -c $$< -o $$@ +.libs/maccatalyst/%$(1).arm64.dylib: %.swift | .libs/maccatalyst + $$(call Q_2,SWIFT, [maccatalyst]) $(SWIFTC) $(MACCATALYST_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/maccatalyst/%$(1).arm64.dylib: | .libs/maccatalyst $$(call Q_2,LD, [maccatalyst]) $(XCODE_CC) $(MACCATALYST_ARM64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_MACCATALYST_SDK)/lib -fapplication-extension @@ -157,6 +172,9 @@ define NativeCompilationTemplate .libs/watchsimulator/%$(1).x86.o: %.s $(EXTRA_DEPENDENCIES) | .libs/watchsimulator $$(call Q_2,ASM, [watchsimulator]) $(SIMULATOR_CC) $(SIMULATORWATCH_CFLAGS) $$(EXTRA_DEFINES) $(SIMW_I) -g $(2) -c $$< -o $$@ +.libs/watchsimulator/%$(1).x86.dylib: %.swift | .libs/watchsimulator + $$(call Q_2,SWIFT, [watchsimulator]) $(SWIFTC) $(WATCHOS_SIMULATOR_X86_SWIFTFLAGS) $$< -o $$@ + .libs/watchsimulator/%$(1).x86.dylib: | .libs/watchsimulator $$(call Q_2,LD, [watchsimulator]) $(SIMULATOR_CC) $(SIMULATORWATCH_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_WATCHSIMULATOR_SDK)/lib -fapplication-extension @@ -172,6 +190,9 @@ define NativeCompilationTemplate .libs/watchsimulator/%$(1).x86_64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/watchsimulator $$(call Q_2,ASM, [watchsimulator]) $(SIMULATOR_CC) $(SIMULATORWATCH64_CFLAGS) $$(EXTRA_DEFINES) $(SIMW64_I) -g $(2) -c $$< -o $$@ +.libs/watchsimulator/%$(1).x86_64.dylib: %.swift | .libs/watchsimulator + $$(call Q_2,SWIFT, [watchsimulator]) $(SWIFTC) $(WATCHOS_SIMULATOR_X64_SWIFTFLAGS) $$< -o $$@ + .libs/watchsimulator/%$(1).x86_64.dylib: | .libs/watchsimulator $$(call Q_2,LD, [watchsimulator]) $(SIMULATOR_CC) $(SIMULATORWATCH64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_WATCHSIMULATOR_SDK)/lib -fapplication-extension @@ -186,6 +207,9 @@ define NativeCompilationTemplate .libs/watchos/%$(1).armv7k.o: %.c $(EXTRA_DEPENDENCIES) | .libs/watchos $$(call Q_2,CC, [watchos]) $(DEVICE_CC) $(DEVICEWATCH_CFLAGS) $$(EXTRA_DEFINES) $(DEVW_I) -g $(2) -c $$< -o $$@ +.libs/watchos/%$(1).armv7k.dylib: %.swift | .libs/watchsimulator + $$(call Q_2,SWIFT, [watchos]) $(SWIFTC) $(WATCHOS_DEVICE_ARMV7K_SWIFTFLAGS) $$< -o $$@ + .libs/watchos/%$(1).armv7k.dylib: | .libs/watchos $$(call Q_2,LD, [watchos]) $(DEVICE_CC) $(DEVICEWATCH_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_WATCHOS_SDK)/lib -fapplication-extension @@ -198,6 +222,9 @@ define NativeCompilationTemplate .libs/watchos/%$(1).arm64_32.o: %.c $(EXTRA_DEPENDENCIES) | .libs/watchos $$(call Q_2,CC, [watchos]) $(DEVICE_CC) $(DEVICEWATCH64_32_CFLAGS) $$(EXTRA_DEFINES) $(DEVW64_32_I) -g $(2) -c $$< -o $$@ +.libs/watchos/%$(1).arm64_32.dylib: %.swift | .libs/watchsimulator + $$(call Q_2,SWIFT, [watchos]) $(SWIFTC) $(WATCHOS_DEVICE_ARM64_32_SWIFTFLAGS) $$< -o $$@ + .libs/watchos/%$(1).arm64_32.dylib: | .libs/watchos $$(call Q_2,LD, [watchos]) $(DEVICE_CC) $(DEVICEWATCH64_32_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_WATCHOS_SDK)/lib -fapplication-extension @@ -217,6 +244,9 @@ define NativeCompilationTemplate .libs/tvsimulator/%$(1).x86_64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/tvsimulator $$(call Q_2,ASM, [tvsimulator]) $(SIMULATOR_CC) $(SIMULATORTV_CFLAGS) $$(EXTRA_DEFINES) $(SIM_TV_I) -g $(2) -c $$< -o $$@ +.libs/tvsimulator/%$(1).x86_64.dylib: %.swift | .libs/tvsimulator + $$(call Q_2,SWIFT, [tvsimulator]) $(SWIFTC) $(TVOS_SIMULATOR_X64_SWIFTFLAGS) $$< -o $$@ + .libs/tvsimulator/%$(1).x86_64.dylib: | .libs/tvsimulator $$(call Q_2,LD, [tvsimulator]) $(SIMULATOR_CC) $(SIMULATORTV_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_TVSIMULATOR_SDK)/lib -fapplication-extension @@ -234,6 +264,9 @@ define NativeCompilationTemplate .libs/tvsimulator/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/tvsimulator $$(call Q_2,ASM, [tvsimulator]) $(SIMULATOR_CC) $(SIMULATORTV_ARM64_CFLAGS) $$(EXTRA_DEFINES) $(SIM_ARM64_TV_I) -g $(2) -c $$< -o $$@ +.libs/tvsimulator/%$(1).arm64.dylib: %.swift | .libs/tvsimulator + $$(call Q_2,SWIFT, [tvsimulator]) $(SWIFTC) $(TVOS_SIMULATOR_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/tvsimulator/%$(1).arm64.dylib: | .libs/tvsimulator $$(call Q_2,LD, [tvsimulator]) $(SIMULATOR_CC) $(SIMULATORTV_ARM64_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_TVSIMULATOR_SDK)/lib -fapplication-extension @@ -251,6 +284,9 @@ define NativeCompilationTemplate .libs/tvos/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/tvos $$(call Q_2,ASM, [tvos]) $(DEVICE_CC) $(DEVICETV_CFLAGS) $$(EXTRA_DEFINES) $(DEV_TV_I) -g $(2) -c $$< -o $$@ +.libs/tvos/%$(1).arm64.dylib: %.swift | .libs/tvos + $$(call Q_2,SWIFT, [tvos]) $(SWIFTC) $(TVOS_DEVICE_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/tvos/%$(1).arm64.dylib: | .libs/tvos $$(call Q_2,LD, [tvos]) $(DEVICE_CC) $(DEVICETV_CFLAGS) $$(EXTRA_FLAGS) -dynamiclib -o $$@ $$^ -L$(IOS_DESTDIR)$(XAMARIN_TVOS_SDK)/lib -fapplication-extension @@ -268,6 +304,12 @@ define NativeCompilationTemplate .libs/mac/%$(1).x86_64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/mac $$(call Q_2,ASM, [mac]) $(MAC_CC) $(MAC_CFLAGS) -arch x86_64 $(COMMON_I) -g $(2) -c $$< -o $$@ +.libs/mac/%$(1).x86_64.dylib: %.swift | .libs/mac + $$(call Q_2,SWIFT, [mac]) $(SWIFTC) $(MACOS_X64_SWIFTFLAGS) $$< -o $$@ + +.libs/macos/%$(1).x86_64.dylib: %.swift | .libs/mac + $$(call Q_2,SWIFT, [macos]) $(SWIFTC) $(MACOS_X64_SWIFTFLAGS) $$< -o $$@ + .libs/mac/%$(1).x86_64.dylib: | .libs/mac $$(call Q_2,LD, [mac]) $(MAC_CC) $(MAC_CFLAGS) $$(EXTRA_FLAGS) -arch x86_64 -dynamiclib -o $$@ $$^ -L$(MAC_DESTDIR)$(XAMARIN_MACOS_SDK)/lib -fapplication-extension @@ -283,6 +325,12 @@ define NativeCompilationTemplate .libs/mac/%$(1).arm64.o: %.s $(EXTRA_DEPENDENCIES) | .libs/mac $$(call Q_2,ASM, [mac]) $(MAC_CC) $(MAC_CFLAGS) -arch arm64 $(COMMON_I) -g $(2) -c $$< -o $$@ +.libs/mac/%$(1).arm64.dylib: %.swift | .libs/mac + $$(call Q_2,SWIFT, [mac]) $(SWIFTC) $(MACOS_ARM64_SWIFTFLAGS) $$< -o $$@ + +.libs/macos/%$(1).arm64.dylib: %.swift | .libs/mac + $$(call Q_2,SWIFT, [macos]) $(SWIFTC) $(MACOS_ARM64_SWIFTFLAGS) $$< -o $$@ + .libs/mac/%$(1).arm64.dylib: | .libs/mac $$(call Q_2,LD, [mac]) $(MAC_CC) $(MAC_CFLAGS) $$(EXTRA_FLAGS) -arch arm64 -dynamiclib -o $$@ $$^ -L$(MAC_DESTDIR)$(XAMARIN_MACOS_SDK)/lib -fapplication-extension diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateBindingResourcePackage.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateBindingResourcePackage.cs index 2fd27f28372b..41b74c9d6553 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateBindingResourcePackage.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateBindingResourcePackage.cs @@ -137,7 +137,7 @@ static bool ContainsSymlinks (ITaskItem [] items) return false; } - string [] NativeReferenceAttributeNames = new string [] { "Kind", "ForceLoad", "SmartLink", "Frameworks", "WeakFrameworks", "LinkerFlags", "NeedsGccExceptionHandling", "IsCxx" }; + string [] NativeReferenceAttributeNames = new string [] { "Kind", "ForceLoad", "SmartLink", "Frameworks", "WeakFrameworks", "LinkerFlags", "NeedsGccExceptionHandling", "IsCxx", "LinkWithSwiftSystemLibraries" }; string CreateManifest (string resourcePath) { diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareNativeReferences.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareNativeReferences.cs index 98eac47ef89b..fd9395ebd807 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareNativeReferences.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareNativeReferences.cs @@ -148,6 +148,7 @@ public override bool Execute () text.AppendFormat ("[assembly: ObjCRuntime.LinkWith (\"{0}\"", logicalName); AppendLinkTargetProperty (text, NativeReferences [i]); AppendBooleanProperty (text, NativeReferences [i], "IsCxx"); + AppendBooleanProperty (text, NativeReferences [i], "LinkWithSwiftSystemLibraries"); AppendBooleanProperty (text, NativeReferences [i], "NeedsGccExceptionHandling"); AppendBooleanProperty (text, NativeReferences [i], "SmartLink", true); AppendBooleanProperty (text, NativeReferences [i], "ForceLoad"); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ResolveNativeReferences.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ResolveNativeReferences.cs index ab7ab1df3a13..0d39e8e91a00 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ResolveNativeReferences.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ResolveNativeReferences.cs @@ -352,6 +352,7 @@ void ProcessSidecar (ITaskItem r, string resources, List native_frame t.SetMetadata ("ForceLoad", "False"); t.SetMetadata ("NeedsGccExceptionHandling", "False"); t.SetMetadata ("IsCxx", "False"); + t.SetMetadata ("LinkWithSwiftSystemLibraries", "False"); t.SetMetadata ("SmartLink", "True"); // values from manifest, overriding defaults if provided diff --git a/src/ObjCRuntime/LinkWithAttribute.cs b/src/ObjCRuntime/LinkWithAttribute.cs index 4a3ca2b0aabd..918b66b56dc3 100644 --- a/src/ObjCRuntime/LinkWithAttribute.cs +++ b/src/ObjCRuntime/LinkWithAttribute.cs @@ -104,6 +104,12 @@ public LinkWithAttribute () get; set; } + /// Determines whether the library uses Swift. + /// If this is true, the app will automatically link with the Swift system libraries. + public bool LinkWithSwiftSystemLibraries { + get; set; + } + public bool SmartLink { get; set; } diff --git a/tests/bindings-test/ApiDefinition.cs b/tests/bindings-test/ApiDefinition.cs index 1a9e9f643f5e..9b844e3a59a4 100644 --- a/tests/bindings-test/ApiDefinition.cs +++ b/tests/bindings-test/ApiDefinition.cs @@ -456,4 +456,12 @@ interface ProtocolWithBlockProperties { SimpleCallback MyOptionalStaticProperty { get; set; } } interface IProtocolWithBlockProperties { } + +#if NET + [BaseType (typeof (NSObject))] + interface SwiftTestClass { + [Export ("SayHello")] + string SayHello (); + } +#endif } diff --git a/tests/bindings-test/RuntimeTest.cs b/tests/bindings-test/RuntimeTest.cs index ac0ffa9ff929..e494836a323e 100644 --- a/tests/bindings-test/RuntimeTest.cs +++ b/tests/bindings-test/RuntimeTest.cs @@ -95,5 +95,15 @@ public override void AssertMainThreadBlockReleaseCallback (InnerBlock completion completionHandler (42); } } + +#if NET + [Test] + public void SwiftTest () + { + TestRuntime.AssertXcodeVersion (13, 0); + using var obj = new SwiftTestClass (); + Assert.AreEqual ("Hello from Swift", obj.SayHello (), "Hello"); + } +#endif } } diff --git a/tests/bindings-test/dotnet/shared.csproj b/tests/bindings-test/dotnet/shared.csproj index 39c095f93fe1..66b587944a7a 100644 --- a/tests/bindings-test/dotnet/shared.csproj +++ b/tests/bindings-test/dotnet/shared.csproj @@ -38,6 +38,11 @@ Static CoreLocation Foundation ModelIO + + + Framework + true + diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 803c8e95c8c3..d734b6852ff8 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -190,7 +190,7 @@ public void BuildBindingsTest (ApplePlatform platform) // Verify that there's one resource in the binding assembly, and its name var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred }); Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (0), "no embedded resources"); - var resourceBundle = Path.Combine (project_dir, "bin", "Debug", platform.ToFramework (), assemblyName + ".resources"); + var resourceBundle = Path.Combine (project_dir, "bin", "Debug", platform.ToFramework (), assemblyName + ".resources.zip"); Assert.That (resourceBundle, Does.Exist, "Bundle existence"); } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs index b2d3d245a0e1..03f2d33afea5 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs @@ -121,6 +121,7 @@ void AssertResourceDirectory (string directory, bool symlinks) + @@ -131,6 +132,7 @@ void AssertResourceDirectory (string directory, bool symlinks) + @@ -141,6 +143,7 @@ void AssertResourceDirectory (string directory, bool symlinks) + diff --git a/tests/test-libraries/Makefile b/tests/test-libraries/Makefile index bd2695501433..cb753d8088a6 100644 --- a/tests/test-libraries/Makefile +++ b/tests/test-libraries/Makefile @@ -47,22 +47,22 @@ MACCATALYST_BINARY_INFIX=/Versions/A define SymlinksTemplate -$(1)_XTEST_TARGETS += \ - .libs/$(1)/XTest.framework/XTest \ - .libs/$(1)/XTest.framework/Resources \ - .libs/$(1)/XTest.framework/Versions/Current \ - .libs/$(1)/XTest.framework/Versions/A/Resources/Info.plist \ +$(1)_$(4)_TARGETS += \ + .libs/$(1)/$(3).framework/$(3) \ + .libs/$(1)/$(3).framework/Resources \ + .libs/$(1)/$(3).framework/Versions/Current \ + .libs/$(1)/$(3).framework/Versions/A/Resources/Info.plist \ -.libs/$(1)/XTest.framework$($(2)_BINARY_INFIX) .libs/$(1)/XTest.framework$($(2)_INFO_PLIST_INFIX): +.libs/$(1)/$(3).framework$($(2)_BINARY_INFIX) .libs/$(1)/$(3).framework$($(2)_INFO_PLIST_INFIX): $$(Q) mkdir -p $$@ -.libs/$(1)/XTest.framework/XTest: | .libs/$(1)/XTest.framework - $$(Q) ln -fs Versions/A/XTest $$@ +.libs/$(1)/$(3).framework/$(3): | .libs/$(1)/$(3).framework + $$(Q) ln -fs Versions/A/$(3) $$@ -.libs/$(1)/XTest.framework/Resources: | .libs/$(1)/XTest.framework +.libs/$(1)/$(3).framework/Resources: | .libs/$(1)/$(3).framework $$(Q) ln -fs Versions/Current/Resources $$@ -.libs/$(1)/XTest.framework/Versions/Current: | .libs/$(1)/XTest.framework/Versions +.libs/$(1)/$(3).framework/Versions/Current: | .libs/$(1)/$(3).framework/Versions $$(Q) ln -fs A $$@ x:: @@ -70,10 +70,12 @@ x:: endef ifdef INCLUDE_MAC -$(eval $(call SymlinksTemplate,macos,MACOS)) +$(eval $(call SymlinksTemplate,macos,MACOS,XTest,XTEST)) +$(eval $(call SymlinksTemplate,macos,MACOS,SwiftTest,SWIFTTEST)) endif ifdef INCLUDE_MACCATALYST -$(eval $(call SymlinksTemplate,maccatalyst,MACCATALYST)) +$(eval $(call SymlinksTemplate,maccatalyst,MACCATALYST,XTest,XTEST)) +$(eval $(call SymlinksTemplate,maccatalyst,MACCATALYST,SwiftTest,SWIFTTEST)) endif define Template @@ -82,8 +84,13 @@ $(1)_XTEST_TARGETS += \ .libs/$(1)/XTest.framework$($(2)_BINARY_INFIX)/XTest \ .libs/$(1)/XTest.framework$($(2)_INFO_PLIST_INFIX)/Info.plist \ +$(1)_SWIFTTEST_TARGETS += \ + .libs/$(1)/SwiftTest.framework$($(2)_BINARY_INFIX)/SwiftTest \ + .libs/$(1)/SwiftTest.framework$($(2)_INFO_PLIST_INFIX)/Info.plist \ + $(2)_TARGETS = \ $$($(1)_XTEST_TARGETS) \ + $$($(1)_SWIFTTEST_TARGETS) \ .libs/$(1)/XStaticObjectTest.framework/XStaticObjectTest \ .libs/$(1)/XStaticArTest.framework/XStaticArTest \ .libs/$(1)/libtest.dylib \ @@ -96,12 +103,17 @@ $(2)_TARGETS = \ $$(foreach arch,$(3),.libs/$(1)/libtest-ar.$$(arch).a) \ .libs/$(1)/XTest.framework \ .libs/$(1)/XTest.framework.stamp \ + .libs/$(1)/SwiftTest.framework \ + .libs/$(1)/SwiftTest.framework.stamp \ all-local:: $$($(2)_TARGETS) $(GENERATED_FILES) .libs/$(1)/XTest.framework.stamp: $$($(1)_XTEST_TARGETS) $$(Q) touch $$@ +.libs/$(1)/SwiftTest.framework.stamp: $$($(1)_SWIFTTEST_TARGETS) + $$(Q) touch $$@ + clean-$(1): rm -Rf .libs/$(1) @@ -147,6 +159,17 @@ COMMON_DYLIB_ARGS=-g -dynamiclib -gdwarf-2 -fms-extensions libframework.m -o $$@ .libs/$(1)/libtest.dylib: $$(foreach arch,$(3),.libs/$(1)/libtest.$$(arch).dylib) $$(call Q_2,LIPO [$(1)]) $(XCODE_DEVELOPER_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo $$^ -create -output $$@ +.libs/$(1)/libSwiftTest.dylib: $$(foreach arch,$(3),.libs/$(1)/libSwiftTest.$$(arch).dylib) + $$(call Q_2,LIPO [$(1)]) $(XCODE_DEVELOPER_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo $$^ -create -output $$@ + +# SwiftTest is a framework where the binary code is a (fat) dynamic library +.libs/$(1)/SwiftTest.framework$($(2)_BINARY_INFIX)/SwiftTest: .libs/$(1)/libSwiftTest.dylib | .libs/$(1)/SwiftTest.framework$($(2)_BINARY_INFIX) + $$(Q) $(CP) $$^ $$@ + $$(Q) $(XCODE_DEVELOPER_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool -id @rpath/SwiftTest.framework/SwiftTest $$@ + +.libs/$(1)/SwiftTest.framework$($(2)_INFO_PLIST_INFIX)/Info.plist: SwiftTest-Info-$(1).plist | .libs/$(1)/SwiftTest.framework$($(2)_INFO_PLIST_INFIX) + $$(Q) $(CP) $$^ $$@ + # XTest is a framework where the binary code is a (fat) dynamic library .libs/$(1)/XTest.framework$($(2)_BINARY_INFIX)/XTest: .libs/$(1)/libtest.dylib | .libs/$(1)/XTest.framework$($(2)_BINARY_INFIX) $$(Q) $(CP) $$^ $$@ @@ -168,8 +191,10 @@ COMMON_DYLIB_ARGS=-g -dynamiclib -gdwarf-2 -fms-extensions libframework.m -o $$@ $(1)_DIRECTORIES = \ .libs/$(1)/XTest.framework \ .libs/$(1)/XTest.framework/Versions \ + .libs/$(1)/SwiftTest.framework/Versions \ .libs/$(1)/XStaticObjectTest.framework \ .libs/$(1)/XStaticArTest.framework \ + .libs/$(1)/SwiftTest.framework \ $$($(1)_DIRECTORIES): $$(Q) mkdir -p $$@ @@ -405,6 +430,16 @@ LIBTEST2_XCFRAMEWORKS += $(foreach platform,$(XCPLATFORMS),.libs/$(platform)/lib all-local:: .libs/libtest2.xcframework +SWIFTTEST_XCFRAMEWORKS += $(foreach platform,$(XCPLATFORMS),.libs/$(platform)/SwiftTest.framework) +SWIFTTEST_XCTARGETS += \ + $(foreach platform,$(XCPLATFORMS),.libs/$(platform)/SwiftTest.framework.stamp) \ + +.libs/SwiftTest.xcframework: $(SWIFTTEST_XCTARGETS) Makefile + $(Q) rm -rf $@ + $(Q_GEN) $(XCODE_DEVELOPER_ROOT)/usr/bin/xcodebuild -quiet -create-xcframework $(foreach fw,$(SWIFTTEST_XCFRAMEWORKS),-framework $(fw)) -output $@ + +all-local:: .libs/SwiftTest.xcframework + .libs/XTest.xcframework.zip: .libs/XTest.xcframework $(Q_ZIP) cd .libs && $(ZIP) -r "$(notdir $@)" "$(notdir $<)" diff --git a/tests/test-libraries/SwiftTest-Info-iphoneos.plist b/tests/test-libraries/SwiftTest-Info-iphoneos.plist new file mode 100644 index 000000000000..d6ec76f0fe21 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-iphoneos.plist @@ -0,0 +1,57 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + iPhoneOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + iphoneos + DTPlatformVersion + 8.2 + DTSDKBuild + 12D508 + DTSDKName + iphoneos8.2 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 12.2 + UIDeviceFamily + + 1 + 2 + + + diff --git a/tests/test-libraries/SwiftTest-Info-iphonesimulator.plist b/tests/test-libraries/SwiftTest-Info-iphonesimulator.plist new file mode 100644 index 000000000000..d6ec76f0fe21 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-iphonesimulator.plist @@ -0,0 +1,57 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + iPhoneOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + iphoneos + DTPlatformVersion + 8.2 + DTSDKBuild + 12D508 + DTSDKName + iphoneos8.2 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 12.2 + UIDeviceFamily + + 1 + 2 + + + diff --git a/tests/test-libraries/SwiftTest-Info-maccatalyst.plist b/tests/test-libraries/SwiftTest-Info-maccatalyst.plist new file mode 100644 index 000000000000..eaa51a731d7b --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-maccatalyst.plist @@ -0,0 +1,48 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + macosx + DTPlatformVersion + 10.15 + DTSDKBuild + 12D508 + DTSDKName + macosx10.15 + DTXcode + 0620 + DTXcodeBuild + 6C131e + LSMinimumSystemVersion + 12.0 + + diff --git a/tests/test-libraries/SwiftTest-Info-macos.plist b/tests/test-libraries/SwiftTest-Info-macos.plist new file mode 100644 index 000000000000..ac20a955698e --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-macos.plist @@ -0,0 +1,48 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + macosx + DTPlatformVersion + 10.9 + DTSDKBuild + 12D508 + DTSDKName + macosx10.9 + DTXcode + 0620 + DTXcodeBuild + 6C131e + LSMinimumSystemVersion + 12.0 + + diff --git a/tests/test-libraries/SwiftTest-Info-tvos.plist b/tests/test-libraries/SwiftTest-Info-tvos.plist new file mode 100644 index 000000000000..e464510682d4 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-tvos.plist @@ -0,0 +1,56 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + AppleTVOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + appletvos + DTPlatformVersion + 9.0 + DTSDKBuild + 12D508 + DTSDKName + appletvos9.0 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 11.0 + UIDeviceFamily + + 3 + + + diff --git a/tests/test-libraries/SwiftTest-Info-tvsimulator.plist b/tests/test-libraries/SwiftTest-Info-tvsimulator.plist new file mode 100644 index 000000000000..77d161031238 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-tvsimulator.plist @@ -0,0 +1,56 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + AppleTVOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + appletvos + DTPlatformVersion + 9.0 + DTSDKBuild + 12D508 + DTSDKName + appletvos9.0 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 12.2 + UIDeviceFamily + + 3 + + + diff --git a/tests/test-libraries/SwiftTest-Info-watchos.plist b/tests/test-libraries/SwiftTest-Info-watchos.plist new file mode 100644 index 000000000000..98092178ebd2 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-watchos.plist @@ -0,0 +1,56 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + WatchOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + watchos + DTPlatformVersion + 2.0 + DTSDKBuild + 12D508 + DTSDKName + watchos2.0 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 4.0 + UIDeviceFamily + + 4 + + + diff --git a/tests/test-libraries/SwiftTest-Info-watchsimulator.plist b/tests/test-libraries/SwiftTest-Info-watchsimulator.plist new file mode 100644 index 000000000000..98092178ebd2 --- /dev/null +++ b/tests/test-libraries/SwiftTest-Info-watchsimulator.plist @@ -0,0 +1,56 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + xamarin.ios.swifttest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SwiftTest + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 3.12 + NSPrincipalClass + + CFBundleExecutable + SwiftTest + BuildMachineOSBuild + 13F34 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + WatchOS + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 12D508 + DTPlatformName + watchos + DTPlatformVersion + 2.0 + DTSDKBuild + 12D508 + DTSDKName + watchos2.0 + DTXcode + 0620 + DTXcodeBuild + 6C131e + MinimumOSVersion + 4.0 + UIDeviceFamily + + 4 + + + diff --git a/tests/test-libraries/libSwiftTest.swift b/tests/test-libraries/libSwiftTest.swift new file mode 100644 index 000000000000..48aa58dab9f3 --- /dev/null +++ b/tests/test-libraries/libSwiftTest.swift @@ -0,0 +1,9 @@ +import Foundation + +@objc(SwiftTestClass) +public class SwiftTestClass : NSObject { + @objc + public func SayHello() -> String { + return "Hello from Swift" + } +} diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index 50367e7dca16..c10924904059 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -23,6 +23,7 @@ struct NativeReferenceMetadata { public LinkTarget LinkTarget; public bool NeedsGccExceptionHandling; public bool IsCxx; + public bool LinkWithSwiftSystemLibraries; public bool SmartLink; public DlsymOption Dlsym; @@ -39,6 +40,7 @@ public NativeReferenceMetadata (LinkWithAttribute attribute) LinkTarget = attribute.LinkTarget; NeedsGccExceptionHandling = attribute.NeedsGccExceptionHandling; IsCxx = attribute.IsCxx; + LinkWithSwiftSystemLibraries = attribute.LinkWithSwiftSystemLibraries; SmartLink = attribute.SmartLink; Dlsym = attribute.Dlsym; Attribute = attribute; @@ -90,6 +92,7 @@ public static string GetIdentity (string path) } public bool EnableCxx; + public bool LinkWithSwiftSystemLibraries; public bool NeedsGccExceptionHandling; public bool ForceLoad; public HashSet Frameworks = new HashSet (); @@ -203,6 +206,7 @@ IEnumerable ReadManifest (string manifestPath) metadata.LinkerFlags = attributes ["LinkerFlags"]; metadata.NeedsGccExceptionHandling = ParseAttributeWithDefault (attributes ["NeedsGccExceptionHandling"], false); metadata.IsCxx = ParseAttributeWithDefault (attributes ["IsCxx"], false); + metadata.LinkWithSwiftSystemLibraries = ParseAttributeWithDefault (attributes ["LinkWithSwiftSystemLibraries"], false); metadata.SmartLink = ParseAttributeWithDefault (attributes ["SmartLink"], true); // TODO - The project attributes do not contain these bits, is that OK? @@ -325,6 +329,8 @@ void ProcessNativeReferenceOptions (NativeReferenceMetadata metadata) if (metadata.IsCxx) EnableCxx = true; + if (metadata.LinkWithSwiftSystemLibraries) + LinkWithSwiftSystemLibraries = true; #if MONOTOUCH if (metadata.Dlsym != DlsymOption.Default) App.SetDlsymOption (FullPath, metadata.Dlsym == DlsymOption.Required); @@ -404,6 +410,7 @@ static void LogNativeReference (NativeReferenceMetadata metadata) Driver.Log (3, " ForceLoad: {0}", metadata.ForceLoad); Driver.Log (3, " Frameworks: {0}", metadata.Frameworks); Driver.Log (3, " IsCxx: {0}", metadata.IsCxx); + Driver.Log (3, " LinkWithSwiftSystemLibraries: {0}", metadata.LinkWithSwiftSystemLibraries); Driver.Log (3, " LinkerFlags: {0}", metadata.LinkerFlags); Driver.Log (3, " LinkTarget: {0}", metadata.LinkTarget); Driver.Log (3, " NeedsGccExceptionHandling: {0}", metadata.NeedsGccExceptionHandling); @@ -455,6 +462,9 @@ public static LinkWithAttribute GetLinkWithAttribute (CustomAttribute attr) case "IsCxx": linkWith.IsCxx = (bool) property.Argument.Value; break; + case "LinkWithSwiftSystemLibraries": + linkWith.LinkWithSwiftSystemLibraries = (bool) property.Argument.Value; + break; case "SmartLink": linkWith.SmartLink = (bool) property.Argument.Value; break; diff --git a/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs index b0da3c72a22e..8648cf7801f0 100644 --- a/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs +++ b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs @@ -28,6 +28,7 @@ protected override void TryEndProcess () arg, new Dictionary { { "ForceLoad", asm.ForceLoad ? "true" : "false" }, + { "LinkWithSwiftSystemLibraries", asm.LinkWithSwiftSystemLibraries ? "true" : "false" }, { "Assembly", asm.Identity }, } );