From 196da1dd93183c0e1a1819923979628aac66370f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 7 May 2026 09:59:38 +0200 Subject: [PATCH] [sharpie] Show a helpful error message when installed on x64 When users try to install sharpie on x64 Macs, they previously got a confusing 'DotnetToolSettings.xml was not found' error because the nupkg only contained an arm64 binary. Fix this by including a small x64 native binary in the nupkg that prints a clear error message explaining that sharpie requires Apple Silicon and suggests using an arm64 Mac. Fixes https://github.com/dotnet/macios/issues/25339 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tools/sharpie/Makefile | 7 ++++++- .../Sharpie.Bind.Tool.Unsupported/Program.cs | 13 +++++++++++++ .../Sharpie.Bind.Tool.Unsupported.csproj | 14 ++++++++++++++ .../DotnetToolSettings.osx-x64.xml | 6 ++++++ .../Sharpie.Bind.Tool.csproj | 19 ++++++++++++++++++- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tools/sharpie/Sharpie.Bind.Tool.Unsupported/Program.cs create mode 100644 tools/sharpie/Sharpie.Bind.Tool.Unsupported/Sharpie.Bind.Tool.Unsupported.csproj create mode 100644 tools/sharpie/Sharpie.Bind.Tool/DotnetToolSettings.osx-x64.xml diff --git a/tools/sharpie/Makefile b/tools/sharpie/Makefile index 56e53de56372..869c16063ee0 100644 --- a/tools/sharpie/Makefile +++ b/tools/sharpie/Makefile @@ -20,10 +20,15 @@ SHARPIE_BIND_TOOL_NUGET_VERSION=$(if $(filter 0,$(XCODE_BUMP_COMMIT_DISTANCE)),$ SHARPIE_BIND_TOOL_NUPKG_NAME=Sharpie.Bind.Tool.$(SHARPIE_BIND_TOOL_NUGET_VERSION).nupkg SHARPIE_BIND_TOOL_NUPKG=Sharpie.Bind.Tool/bin/Release/$(SHARPIE_BIND_TOOL_NUPKG_NAME) +SHARPIE_BIND_TOOL_X64_SHIM=Sharpie.Bind.Tool.Unsupported/bin/Release/osx-x64/publish/Sharpie.Bind.Tool + pack: $(SHARPIE_BIND_TOOL_NUPKG) -$(SHARPIE_BIND_TOOL_NUPKG): $(Sharpie.Bind_dependencies) +$(SHARPIE_BIND_TOOL_NUPKG): $(Sharpie.Bind_dependencies) $(SHARPIE_BIND_TOOL_X64_SHIM) $(Q_BUILD) $(DOTNET) pack Sharpie.Bind.Tool/Sharpie.Bind.Tool.csproj "/p:Version=$(SHARPIE_VERSION)" "/p:CurrentBranch=$(CURRENT_BRANCH)" "/p:CurrentHash=$(CURRENT_HASH_LONG)" $(DOTNET_PACK_VERBOSITY) -bl:$@.binlog +$(SHARPIE_BIND_TOOL_X64_SHIM): + $(Q_BUILD) $(DOTNET) publish Sharpie.Bind.Tool.Unsupported/Sharpie.Bind.Tool.Unsupported.csproj -c Release $(DOTNET_BUILD_VERBOSITY) -bl:$@.binlog + all-local:: $(DOTNET_NUPKG_DIR)/$(SHARPIE_BIND_TOOL_NUPKG_NAME) $(DOTNET_NUPKG_DIR)/$(SHARPIE_BIND_TOOL_NUPKG_NAME): $(SHARPIE_BIND_TOOL_NUPKG) $(Q) mkdir -p $(dir $@) diff --git a/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Program.cs b/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Program.cs new file mode 100644 index 000000000000..1e99ec5bbb0f --- /dev/null +++ b/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Program.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +class Program { + static int Main (string [] args) + { + Console.Error.WriteLine ("error: sharpie is not supported on x64. Please use an Apple Silicon (arm64) Mac."); + Console.Error.WriteLine (); + Console.Error.WriteLine ("sharpie requires Apple's libclang, which is only available for arm64."); + Console.Error.WriteLine ("If you're running on an Intel Mac, consider using a Mac with Apple Silicon (M1 or later)."); + return 1; + } +} diff --git a/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Sharpie.Bind.Tool.Unsupported.csproj b/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Sharpie.Bind.Tool.Unsupported.csproj new file mode 100644 index 000000000000..86690605eb66 --- /dev/null +++ b/tools/sharpie/Sharpie.Bind.Tool.Unsupported/Sharpie.Bind.Tool.Unsupported.csproj @@ -0,0 +1,14 @@ + + + + net$(BundledNETCoreAppTargetFrameworkVersion) + latest + enable + Exe + osx-x64 + true + false + Sharpie.Bind.Tool + + + diff --git a/tools/sharpie/Sharpie.Bind.Tool/DotnetToolSettings.osx-x64.xml b/tools/sharpie/Sharpie.Bind.Tool/DotnetToolSettings.osx-x64.xml new file mode 100644 index 000000000000..55a0553bced7 --- /dev/null +++ b/tools/sharpie/Sharpie.Bind.Tool/DotnetToolSettings.osx-x64.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tools/sharpie/Sharpie.Bind.Tool/Sharpie.Bind.Tool.csproj b/tools/sharpie/Sharpie.Bind.Tool/Sharpie.Bind.Tool.csproj index c58024873200..711da04f3993 100644 --- a/tools/sharpie/Sharpie.Bind.Tool/Sharpie.Bind.Tool.csproj +++ b/tools/sharpie/Sharpie.Bind.Tool/Sharpie.Bind.Tool.csproj @@ -9,7 +9,8 @@ false - + + osx-arm64 true sharpie @@ -50,4 +51,20 @@ + + + + <_X64ShimPublishDir>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', '..', 'Sharpie.Bind.Tool.Unsupported', 'bin', 'Release', 'osx-x64', 'publish')) + + + + + + tools/any/osx-x64/ + + + tools/any/osx-x64/DotnetToolSettings.xml + + +