Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild/dotnet] Automatically link with Swift's system libraries if a binding project has the IsSwift=true property. #20546

Merged
merged 9 commits into from
May 20, 2024
34 changes: 34 additions & 0 deletions Make.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1479,16 +1479,23 @@
</_LinkNativeExecutableDependsOn>
</PropertyGroup>

<Target Name="_AddSwiftLinkerFlags" Condition="'$(LinkWithSwiftSystemLibraries)' == 'true'" DependsOnTargets="_DetectSdkLocations">
<Target Name="_AddSwiftLinkerFlags" DependsOnTargets="_DetectSdkLocations">
<PropertyGroup>
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'iOS' And '$(_SdkIsSimulator)' == 'true'">iphonesimulator</_SwiftTargetPlatform>
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'iOS' And '$(_SdkIsSimulator)' != 'true'">iphoneos</_SwiftTargetPlatform>
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'tvOS' And '$(_SdkIsSimulator)' == 'true'">appletvsimulator</_SwiftTargetPlatform>
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'tvOS' And '$(_SdkIsSimulator)' != 'true'">appletvos</_SwiftTargetPlatform>
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'MacCatalyst'">macosx</_SwiftTargetPlatform> <!-- yes, 'macosx' and not 'maccatalyst': even though the resulting maccatalyst directory exists, it doesn't have anything useful in it -->
<_SwiftTargetPlatform Condition="'$(_PlatformName)' == 'macOS'">macosx</_SwiftTargetPlatform>

<_HasBindingLibraryWithSwift Condition="@(_BindingLibraryLinkWith->WithMetadataValue('IsSwift', 'true')->Count()) &gt; 0">true</_HasBindingLibraryWithSwift>
<_HasFrameworkNativeReferenceWithSwift Condition="@(_FrameworkNativeReference->WithMetadataValue('IsSwift', 'true')->Count()) &gt; 0">true</_HasFrameworkNativeReferenceWithSwift>
<_HasFileNativeReferenceWithSwift Condition="@(_FileNativeReference->WithMetadataValue('IsSwift', 'true')->Count()) &gt; 0">true</_HasFileNativeReferenceWithSwift>

<!-- Automatically link with Swift system libraries if any of the native libraries we link with has IsSwift=true -->
<LinkWithSwiftSystemLibraries Condition="'$(LinkWithSwiftSystemLibraries)' == '' And ('$(_HasBindingLibraryWithSwift)' == 'true' Or '$(_HasFrameworkNativeReferenceWithSwift)' == 'true' Or '$(_HasFileNativeReferenceWithSwift)' == 'true')">true</LinkWithSwiftSystemLibraries>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition="'$(LinkWithSwiftSystemLibraries)' == 'true'">
<_MainLinkerFlags Include="-L$(_SdkDevPath)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(_SwiftTargetPlatform)/" />
<_MainLinkerFlags Include="-L$(_SdkRoot)/usr/lib/swift/" />
</ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "IsSwift" };

string CreateManifest (string resourcePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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], "IsSwift");
AppendBooleanProperty (text, NativeReferences [i], "NeedsGccExceptionHandling");
AppendBooleanProperty (text, NativeReferences [i], "SmartLink", true);
AppendBooleanProperty (text, NativeReferences [i], "ForceLoad");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ void ProcessSidecar (ITaskItem r, string resources, List<ITaskItem> native_frame
t.SetMetadata ("ForceLoad", "False");
t.SetMetadata ("NeedsGccExceptionHandling", "False");
t.SetMetadata ("IsCxx", "False");
t.SetMetadata ("IsSwift", "False");
t.SetMetadata ("SmartLink", "True");

// values from manifest, overriding defaults if provided
Expand Down
6 changes: 6 additions & 0 deletions src/ObjCRuntime/LinkWithAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public bool IsCxx {
get; set;
}

/// <summary>Determines whether the library uses Swift.</summary>
/// <remarks>If this is true, the app will automatically link with the Swift system libraries.</remarks>
public bool IsSwift {
get; set;
}

public bool SmartLink {
get; set;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/bindings-test/ApiDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,12 @@ interface ProtocolWithBlockProperties {
SimpleCallback MyOptionalStaticProperty { get; set; }
}
interface IProtocolWithBlockProperties { }

#if NET
[BaseType (typeof (NSObject))]
interface SwiftTestClass {
[Export ("SayHello")]
string SayHello ();
}
#endif
}
10 changes: 10 additions & 0 deletions tests/bindings-test/RuntimeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 5 additions & 0 deletions tests/bindings-test/dotnet/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<Kind>Static</Kind>
<Frameworks>CoreLocation Foundation ModelIO</Frameworks>
</NativeReference>

<NativeReference Include="$(TestLibrariesDirectory)\.libs\SwiftTest.xcframework">
<Kind>Framework</Kind>
<IsSwift>true</IsSwift>
</NativeReference>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void AssertResourceDirectory (string directory, bool symlinks)
<ForceLoad></ForceLoad>
<Frameworks></Frameworks>
<IsCxx></IsCxx>
<IsSwift></IsSwift>
<Kind></Kind>
<LinkerFlags></LinkerFlags>
<NeedsGccExceptionHandling></NeedsGccExceptionHandling>
Expand All @@ -129,6 +130,7 @@ void AssertResourceDirectory (string directory, bool symlinks)
<ForceLoad></ForceLoad>
<Frameworks></Frameworks>
<IsCxx></IsCxx>
<IsSwift></IsSwift>
<Kind></Kind>
<LinkerFlags></LinkerFlags>
<NeedsGccExceptionHandling></NeedsGccExceptionHandling>
Expand All @@ -139,6 +141,7 @@ void AssertResourceDirectory (string directory, bool symlinks)
<ForceLoad></ForceLoad>
<Frameworks></Frameworks>
<IsCxx></IsCxx>
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
<IsSwift></IsSwift>
<Kind></Kind>
<LinkerFlags></LinkerFlags>
<NeedsGccExceptionHandling></NeedsGccExceptionHandling>
Expand Down
Loading
Loading