diff --git a/tests/common/BundlerTool.cs b/tests/common/BundlerTool.cs index 6239f59d1b29..1d426a391872 100644 --- a/tests/common/BundlerTool.cs +++ b/tests/common/BundlerTool.cs @@ -326,7 +326,7 @@ public virtual void AssertExecute (string message = null) if (rv == 0) return; var errors = Messages.Where ((v) => v.IsError).ToList (); - Assert.Fail ($"Expected execution to succeed, but exit code was {rv}, and there were {errors.Count} error(s): {message}\n\t" + + Assert.Fail ($"Expected execution to succeed, but exit code was {rv}, and there were {errors.Count} error(s).\nCommand: {ToolPath} {StringUtils.FormatArguments (ToolArguments)}\nMessage: {message}\n\t" + string.Join ("\n\t", errors.Select ((v) => v.ToString ()))); } diff --git a/tests/mtouch/MTouch.cs b/tests/mtouch/MTouch.cs index 658eb2d64f69..12701d990f20 100644 --- a/tests/mtouch/MTouch.cs +++ b/tests/mtouch/MTouch.cs @@ -1114,6 +1114,31 @@ public void MT0180 (Profile profile, string name) } } + [Test] + [TestCase (Profile.tvOS, MTouchBitcode.ASMOnly, "arm64+llvm")] + [TestCase (Profile.tvOS, MTouchBitcode.Full, "arm64+llvm")] + [TestCase (Profile.tvOS, MTouchBitcode.Marker, "arm64+llvm")] + public void MT0186 (Profile profile, MTouchBitcode mode, string abi) + { + using (var mtouch = new MTouchTool ()) { + mtouch.Profile = profile; + if (profile == Profile.watchOS) { + mtouch.CreateTemporaryWatchKitExtension (); + } else { + mtouch.CreateTemporaryApp (); + } + mtouch.Abi = abi; + mtouch.Bitcode = mode; + mtouch.WarnAsError = new int[] { 186 }; + if (Configuration.XcodeVersion.Major >= 14) { + Assert.AreEqual (1, mtouch.Execute (MTouchAction.BuildDev)); + mtouch.AssertError (186, "Bitcode is enabled, but bitcode is not supported in Xcode 14+ and has been disabled. Please disable bitcode by removing the 'MtouchEnableBitcode' property from the project file."); + } else { + Assert.AreEqual (0, mtouch.Execute (MTouchAction.BuildDev)); + } + } + } + [Test] public void MT0095_SharedCode () { diff --git a/tools/common/Application.cs b/tools/common/Application.cs index 6aaa58576390..9671477dfb2a 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -874,6 +874,12 @@ public void InitializeCommon () ErrorHelper.Warning (3007, Errors.MX3007); } + if (Driver.XcodeVersion.Major >= 14 && BitCodeMode != BitCodeMode.None && Platform == ApplePlatform.TVOS) { + // We currently have to leave watchOS alone, because the process is to first build bitcode, then compile bitcode into native code, and finally remove the bitcode from the executable (this is likely fixable, but looks like it's a larger effort involving the runtime team). + ErrorHelper.Warning (186, Errors.MX0186 /* Bitcode is enabled, but bitcode is not supported in Xcode 14+ and has been disabled. Please disable bitcode by removing the 'MtouchEnableBitcode' property from the project file. */); + BitCodeMode = BitCodeMode.None; + } + Optimizations.Initialize (this, out var messages); ErrorHelper.Show (messages); if (Driver.Verbosity > 3) diff --git a/tools/mtouch/Application.mtouch.cs b/tools/mtouch/Application.mtouch.cs index 196c91bb5ad9..7a38b9f915a4 100644 --- a/tools/mtouch/Application.mtouch.cs +++ b/tools/mtouch/Application.mtouch.cs @@ -853,6 +853,8 @@ void Initialize () break; case BitCodeMode.None: // If neither llvmonly nor asmonly is enabled, enable markeronly. + if (Driver.XcodeVersion.Major >= 14) + break; if (Platform == ApplePlatform.TVOS || Platform == ApplePlatform.WatchOS) BitCodeMode = BitCodeMode.MarkerOnly; break; @@ -1236,7 +1238,12 @@ public void StripBitcode (string macho_file) { var sb = new List (); sb.Add (macho_file); - switch (BitCodeMode) { + + var mode = BitCodeMode; + if (Driver.XcodeVersion.Major >= 14) + mode = BitCodeMode.None; + + switch (mode) { case BitCodeMode.ASMOnly: case BitCodeMode.LLVMOnly: // do nothing, since we don't know neither if bitcode is needed (if we're publishing) or if native code is needed (not publishing). diff --git a/tools/mtouch/BuildTasks.mtouch.cs b/tools/mtouch/BuildTasks.mtouch.cs index 0181a54d9a00..67be80667db1 100644 --- a/tools/mtouch/BuildTasks.mtouch.cs +++ b/tools/mtouch/BuildTasks.mtouch.cs @@ -315,6 +315,9 @@ protected override async Task ExecuteAsync () } } } + + if (code == 0 && Driver.XcodeVersion.Major >= 14 && Target.App.BitCodeMode != BitCodeMode.None) + Target.App.StripBitcode (OutputFile); } catch (System.ComponentModel.Win32Exception wex) { /* This means we failed to execute the linker, not that the linker itself returned with a failure */ if (wex.NativeErrorCode == 7 /* E2BIG = Too many arguments */ ) { @@ -350,6 +353,9 @@ protected override async Task ExecuteAsync () // we can't trust the native linker to pick the right (non private) framework when an older TargetVersion is used if (CompilerFlags.WeakFrameworks.Count > 0) Target.AdjustDylibs (OutputFile); + // Remove bitcode from the binary + if (Driver.XcodeVersion.Major >= 14 && App.BitCodeMode != BitCodeMode.None) + App.StripBitcode (OutputFile); } protected override void CompilationFailed (int exitCode) diff --git a/tools/mtouch/Errors.designer.cs b/tools/mtouch/Errors.designer.cs index 295403782aed..011310e59666 100644 --- a/tools/mtouch/Errors.designer.cs +++ b/tools/mtouch/Errors.designer.cs @@ -3793,6 +3793,15 @@ public static string MX0185 { } } + /// + /// Looks up a localized string similar to Bitcode is enabled, but bitcode is not supported in Xcode 14+ and has been disabled. Please disable bitcode by removing the 'MtouchEnableBitcode' property from the project file.. + /// + public static string MX0186 { + get { + return ResourceManager.GetString("MX0186", resourceCulture); + } + } + /// /// Looks up a localized string similar to Could not copy the assembly '{0}' to '{1}': {2} /// . diff --git a/tools/mtouch/Errors.resx b/tools/mtouch/Errors.resx index 73fee0747009..66e68cc6c6ba 100644 --- a/tools/mtouch/Errors.resx +++ b/tools/mtouch/Errors.resx @@ -935,6 +935,10 @@ The option '{0}' cannot take the value '{1}' when using CoreCLR. + + Bitcode is enabled, but bitcode is not supported in Xcode 14+ and has been disabled. Please disable bitcode by removing the 'MtouchEnableBitcode' property from the project file. + + Could not copy the assembly '{0}' to '{1}': {2} diff --git a/tools/mtouch/Target.mtouch.cs b/tools/mtouch/Target.mtouch.cs index 15910daaaf66..7556594926dd 100644 --- a/tools/mtouch/Target.mtouch.cs +++ b/tools/mtouch/Target.mtouch.cs @@ -1420,7 +1420,7 @@ public NativeLinkTask NativeLink (BuildTasks build_tasks, Abi abi, string output } var bitcode = App.EnableBitCode; - if (bitcode) + if (bitcode && Driver.XcodeVersion.Major < 14) linker_flags.AddOtherFlag (App.EnableMarkerOnlyBitCode ? "-fembed-bitcode-marker" : "-fembed-bitcode"); if (!App.EnablePie.HasValue) diff --git a/tools/mtouch/mtouch.cs b/tools/mtouch/mtouch.cs index a31d90a2165c..f8b12048f5f0 100644 --- a/tools/mtouch/mtouch.cs +++ b/tools/mtouch/mtouch.cs @@ -787,6 +787,14 @@ public static void CalculateCompilerPath (Application app) // we try again with clang. // + switch (app.Platform) { + case ApplePlatform.TVOS: + case ApplePlatform.WatchOS: + if (Driver.XcodeVersion.Major >= 14) + app.EnableCxx = true; + break; + } + if (string.IsNullOrEmpty (app.Compiler)) { // by default we use `gcc` before iOS7 SDK, falling back to `clang`. Otherwise we go directly to `clang` // so we don't get bite by the fact that Xcode5 has a gcc compiler (which calls `clang`, even if not 100%