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

[dotnet] Build macOS/.NET for ARM64 as well. #10959

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Make.config
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ endif

DOTNET_PLATFORMS+=macOS
DOTNET_CORECLR_PLATFORMS+=macOS
DOTNET_MACOS_RUNTIME_IDENTIFIERS=osx-x64
DOTNET_MACOS_RUNTIME_IDENTIFIERS=osx-x64 osx-arm64

DOTNET_WINDOWS_PLATFORMS = iOS

Expand Down
3 changes: 2 additions & 1 deletion builds/package-download/download-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<PackageRuntimeIdentifiers Include="$(PackageRuntimeIdentifiers.Split(' '))" />

<!-- Download the mono osx pack as well -->
<!-- I wasn't able to figure out how to only do this if 'osx-x64' is already included -->
<!-- I wasn't able to figure out how to only do this if 'osx-x64'/'osx-arm64' is already included -->
<PackageRuntimeIdentifiers Include="Mono.osx-x64" />
<PackageRuntimeIdentifiers Include="Mono.osx-arm64" />

<!-- download the runtime packs -->
<PackageDownload Include="@(PackageRuntimeIdentifiers -> 'Microsoft.NETCore.App.Runtime.%(Identity)')" Version="[$(BundledNETCorePlatformsPackageVersion)]" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<_PlatformName>macOS</_PlatformName>
<_RuntimeIdentifier>osx-arm64</_RuntimeIdentifier>
</PropertyGroup>

<Import Project="../microsoft.runtime.csproj" />
</Project>
5 changes: 3 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetArchitectures)' == '' And '$(_PlatformName)' == 'macOS' ">
<TargetArchitectures Condition=" '$(RuntimeIdentifier)' == 'osx-x64' ">x86_64</TargetArchitectures>
<TargetArchitectures Condition=" '$(RuntimeIdentifier)' == 'osx-arm64' ">arm64</TargetArchitectures>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetArchitectures)' == '' And '$(_PlatformName)' == 'MacCatalyst' ">
<TargetArchitectures Condition=" '$(RuntimeIdentifier)' == 'maccatalyst-x64' ">x86_64</TargetArchitectures>
Expand All @@ -62,7 +63,7 @@
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'iOS' ">ios-x64;ios-arm64;ios-arm;ios-x86</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'tvOS' ">tvos-x64;tvos-arm64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'watchOS' ">watchos-x86;watchos-x64;watchos-arm</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'macOS' ">osx-x64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'macOS' ">osx-x64;osx-arm64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'MacCatalyst' ">maccatalyst-x64;maccatalyst-arm64</_RuntimePackRuntimeIdentifiers>
</PropertyGroup>

Expand Down Expand Up @@ -98,7 +99,7 @@
TargetingPackName="Microsoft.NETCore.App.Ref"
TargetingPackVersion="$(BundledNETCorePlatformsPackageVersion)"
RuntimePackNamePatterns="Microsoft.NETCore.App.Runtime.Mono.**RID**"
RuntimePackRuntimeIdentifiers="osx-x64"
RuntimePackRuntimeIdentifiers="osx-x64;osx-arm64"
IsTrimmable="true"
/>
<FrameworkReference Remove="Microsoft.NETCore.App" />
Expand Down
15 changes: 15 additions & 0 deletions mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ define NativeCompilationTemplate
.libs/mac/%$(1).x86_64.framework: | .libs/mac
$$(call Q_2,LD, [mac]) $(MAC_CC) $(MAC_CFLAGS) $$(EXTRA_FLAGS) -arch x86_64 -dynamiclib -o $$@ $$^ -F$(MAC_DESTDIR)$(XAMARIN_MACOS_SDK)/Frameworks -fapplication-extension

.libs/mac/%$(1).arm64.o: %.m $(EXTRA_DEPENDENCIES) | .libs/mac
$$(call Q_2,OBJC, [mac]) $(MAC_CC) $(MAC_OBJC_CFLAGS) $$(EXTRA_DEFINES) -arch arm64 $(COMMON_I) -g $(2) -c $$< -o $$@

.libs/mac/%$(1).arm64.o: %.c $(EXTRA_DEPENDENCIES) | .libs/mac
$$(call Q_2,CC, [mac]) $(MAC_CC) $(MAC_CFLAGS) $$(EXTRA_DEFINES) -arch arm64 $(COMMON_I) -g $(2) -c $$< -o $$@

.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: | .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

.libs/mac/%$(1).arm64.framework: | .libs/mac
$$(call Q_2,LD, [mac]) $(MAC_CC) $(MAC_CFLAGS) $$(EXTRA_FLAGS) -arch arm64 -dynamiclib -o $$@ $$^ -F$(MAC_DESTDIR)$(XAMARIN_MACOS_SDK)/Frameworks -fapplication-extension

endef

$(eval $(call NativeCompilationTemplate,,-O2))
Expand Down
4 changes: 4 additions & 0 deletions runtime/monotouch-main.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ inline void debug_launch_time_print (const char *msg)
*/

#if defined (__arm__) || defined(__aarch64__)
#if !defined (CORECLR_RUNTIME)
extern void mono_gc_init_finalizer_thread (void);
#endif
#endif

@interface XamarinGCSupport : NSObject {
}
Expand Down Expand Up @@ -214,10 +216,12 @@ - (void) start
{
// COOP: ?
#if defined (__arm__) || defined(__aarch64__)
#if !defined (CORECLR_RUNTIME)
MONO_ENTER_GC_UNSAFE;
mono_gc_init_finalizer_thread ();
MONO_EXIT_GC_UNSAFE;
#endif
#endif
}

- (void) memoryWarning: (NSNotification *) sender
Expand Down
2 changes: 1 addition & 1 deletion runtime/xamarin-support.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
return (name != nil) ? strdup ([name UTF8String]) : strdup ("Local");
}

#if !TARGET_OS_WATCH && !TARGET_OS_TV && !(TARGET_OS_MACCATALYST && defined (DOTNET))
#if !TARGET_OS_WATCH && !TARGET_OS_TV && !(TARGET_OS_MACCATALYST && defined (DOTNET)) && !TARGET_OS_OSX
void
xamarin_start_wwan (const char *uri)
{
Expand Down
9 changes: 9 additions & 0 deletions tools/mmp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $(MMP_DIR)/mmp.exe: $(mmp_dependencies)

MMP_TARGETS_DOTNET = \
$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-x64/runtimes/osx-x64/native/Microsoft.macOS.registrar.a \
$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-arm64/runtimes/osx-arm64/native/Microsoft.macOS.registrar.a \

MMP_TARGETS = \
$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/mmp \
Expand All @@ -29,6 +30,7 @@ MMP_TARGETS = \

MMP_DIRECTORIES_DOTNET = \
$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-x64/runtimes/osx-x64/native \
$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-arm64/runtimes/osx-arm64/native \

MMP_DIRECTORIES = \
$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin \
Expand All @@ -49,6 +51,9 @@ $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/lib/mmp/Xamarin.Mac.registrar.%.a: Xa
$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-x64/runtimes/osx-x64/native/Microsoft.macOS.registrar.a: Microsoft.macOS.registrar.x86_64.a | $(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-x64/runtimes/osx-x64/native
$(Q) $(CP) $< $@

$(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-arm64/runtimes/osx-arm64/native/Microsoft.macOS.registrar.a: Microsoft.macOS.registrar.arm64.a | $(DOTNET_DESTDIR)/Microsoft.macOS.Runtime.osx-arm64/runtimes/osx-arm64/native
$(Q) $(CP) $< $@

$(MMP_DIRECTORIES):
$(Q) mkdir -p $@

Expand All @@ -74,6 +79,10 @@ Xamarin.Mac.registrar.full.x86_64.m: $(TOP)/src/build/mac/full-64/Xamarin.Mac.
$(GENERATE_PART_REGISTRAR) --arch=x86_64 --target-framework Xamarin.Mac,Version=v4.5,Profile=Full -a:$(FULL_BCL_DIR)/mscorlib.dll
$(Q) touch Xamarin.Mac.registrar.full.x86_64.m Xamarin.Mac.registrar.full.x86_64.h

Microsoft.macOS.registrar.arm64.m: $(TOP)/src/build/dotnet/macos/64/Xamarin.Mac.dll $(LOCAL_MMP)
$(GENERATE_PART_REGISTRAR) --arch=arm64 --target-framework .NETCoreApp,Version=6.0,Profile=macos -a:$(DOTNET6_BCL_DIR)/System.Runtime.dll
$(Q) touch $@ $(basename $@).h

Xamarin.Mac.registrar.full.arm64.m: $(TOP)/src/build/mac/full-64/Xamarin.Mac.dll $(LOCAL_MMP)
$(GENERATE_PART_REGISTRAR) --arch=arm64 --target-framework Xamarin.Mac,Version=v4.5,Profile=Full -a:$(FULL_BCL_DIR)/mscorlib.dll
$(Q) touch Xamarin.Mac.registrar.full.arm64.m Xamarin.Mac.registrar.full.arm64.h
Expand Down