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

[xcode16] Use [Experimental] instead of [RequiresPreviewFeatures]. #21178

Merged
merged 6 commits into from
Sep 10, 2024
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 @@ -691,7 +691,7 @@ $(TOP)/Build.props: Make.config
ifeq ($(XCODE_IS_STABLE),true)
# do nothing
else ifeq ($(XCODE_IS_STABLE),false)
$(Q) printf "\t\t<EnablePreviewFeatures>true</EnablePreviewFeatures>\n" >> $@.tmp
$(Q) printf '\t\t<NoWarn>$$(NoWarn);XCODE_$(subst .,_,$(XCODE_VERSION))_PREVIEW</NoWarn>\n' >> $@.tmp
else
$(error "The variable XCODE_IS_STABLE is not set!")
endif
Expand Down
2 changes: 1 addition & 1 deletion Make.versions
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ MACCATALYST_NUGET_OS_VERSION=18.0
# would add support for trying the preview release by doing:
#
# <TargetFramework>net9.0-18.0</TargetFramework>
# <EnablePreviewFeatures>true</EnablePreviewFeatures>
# <NoWarn>XCODE_16_0_PREVIEW;$(NoWarn)</NoWarn>
#
# Note that any SUPPORTED_API_VERSIONS entry below for older OS versions need a corresponding entry in
# the eng/Version.Details.xml and eng/Versions.props files.
Expand Down
13 changes: 3 additions & 10 deletions docs/multi-target-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ following property in their project file to make their intention clear:

```xml
<PropertyGroup>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<NoWarn>XCODE_16_0;$(NoWarn)</NoWarn>
</PropertyGroup>
```

Expand All @@ -89,7 +89,7 @@ We'll release a single workload (per platform), with bindings for every OS
version we currently support or plan to support. This means our stable
releases may point to preview packages (but these preview packages have to be
opted in by doing two things: appending the OS version to their target
framework + setting EnablePreviewFeatures=true)
framework + adding the specific experimental warning to NoWarn)

We'll rename our packages. Currently we ship these packages:

Expand Down Expand Up @@ -162,14 +162,7 @@ Note 2: One complication here is that TargetPlatformVersion might not be set
condition that accepts an empty TargetPlatformVersion. This corresponds with
the default target platform version.

Note 3: we load the preview sdk (Microsoft.iOS.Sdk.net8.0_18.0) even if
`EnablePreviewFeatures!=true` - we show the error requesting
`EnablePreviewFeatures` to be set from the preview sdk instead (this is to get
an actionable error message). Without this, the user would get this rather
unhelpful error message: `error NETSDK1139: The target platform identifier ios
was not recognized.`

Note 4: we load a special error-handling version of the sdk if we don't
Note 3: we load a special error-handling version of the sdk if we don't
support a TargetPlatformVersion for given TargetFrameworkVersion, and show an
error about unsupported TargetPlatformVersion. Without this, the user would
get this rather unhelpful error message: `error NETSDK1139: The target
Expand Down
11 changes: 10 additions & 1 deletion docs/preview-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ References:
* https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.experimentalattribute?view=net-8.0
* https://learn.microsoft.com/en-us/dotnet/fundamentals/apicompat/preview-apis#experimentalattribute

## Previws of new API bindings (XCODE_x_y_PREVIEW)

We sometimes release previews of new API bindings, and until these are deemed
stable (by both Apple and us), we mark all our API bindings as preview of the
new Xcode version.

The diagnostic id is `XCODE_x_y_PREVIEW`, where `x` and `y` are Xcode's major and
minor versions.

## CryptoTokenKit (APL0001)

CryptoTokenKit requires special hardware to test, so it's not trivial for us to do so.
Expand All @@ -85,6 +94,6 @@ framework as preview API for a while.

We've tentatively set .NET 11 as the release when we'll stop marking FSKit as preview API.

The diagnostic id for CryptoTokenKit is APL0001.
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
The diagnostic id for FSKit is APL0002.

[1]: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.experimentalattribute?view=net-8.0
8 changes: 0 additions & 8 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,6 @@
<Error Text="Only CoreCLR is supported on macOS. Set 'UseMonoRuntime=false' to use CoreCLR." Condition="'$(_PlatformName)' == 'macOS' And '$(UseMonoRuntime)' != 'false'" />
</Target>

<Target Name="_VerifyPreviewFeaturesIfUnstableXcode">
<Error
Text="These are preview bindings for an unstable version of Xcode. Opt into preview features by adding &lt;EnablePreviewFeatures&gt;True&lt;/EnablePreviewFeatures&gt; to your project file."
Condition="'$(_XamarinIsPreviewRelease)' == 'true' And '$(EnablePreviewFeatures)' != 'true'"
/>
</Target>

<Target Name="_VerifyValidProperties">
<Error
Text="The property 'MtouchArch' is deprecated, please remove it from the project file. Use 'RuntimeIdentifier' or 'RuntimeIdentifiers' instead to specify the target architecture."
Expand All @@ -1049,7 +1042,6 @@

<PropertyGroup>
<_ComputeVariablesDependsOn>
_VerifyPreviewFeaturesIfUnstableXcode;
_VerifyValidRuntime;
_GenerateBundleName;
_ComputeFrameworkVariables;
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.

<PropertyGroup>
<_CompiledApiDefinitionAssembly>$(DeviceSpecificIntermediateOutputPath)compiled-api-definitions.dll</_CompiledApiDefinitionAssembly>
<_CompiledApiDefinitionNoWarn>$(_CompiledApiDefinitionNoWarn);$(NoWarn)</_CompiledApiDefinitionNoWarn>
<_CompiledApiDefinitionNoWarn>$(_CompiledApiDefinitionNoWarn);436</_CompiledApiDefinitionNoWarn>
<_CompiledApiDefinitionDocumentationFile>$(DeviceSpecificIntermediateOutputPath)compiled-api-definitions.xml</_CompiledApiDefinitionDocumentationFile>
<_CompiledApiDefinitionNoWarn>$(_CompiledApiDefinitionNoWarn);1591</_CompiledApiDefinitionNoWarn> <!-- Don't expect every public API to have documentation -->
Expand Down
3 changes: 2 additions & 1 deletion src/AssemblyInfo.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// Copyright 2014 Xamarin, Inc.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -40,5 +41,5 @@ using System.Runtime.CompilerServices;
#endif

#if NET && !XCODE_IS_STABLE && !COREBUILD
[assembly: RequiresPreviewFeatures("These are preview bindings for an unstable version of Xcode. Opt into preview features by adding <EnablePreviewFeatures>True</EnablePreviewFeatures> to your project file.")]
[assembly: Experimental("XCODE_@XCODE_VERSION@_PREVIEW", UrlFormat = "https://github.com/xamarin/xamarin-macios/blob/main/docs/preview-apis.md")]
#endif
5 changes: 5 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ $(IOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in | $(IOS_BUILD_DI
-e 's|@NUGET_VERSION_REV@|$(IOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(IOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|iOS|g' \
-e 's|@XCODE_VERSION@|$(subst .,_,$(XCODE_VERSION))|g' \
< $< > $@.tmp
$(Q) diff $@ $@.tmp >/dev/null 2>&1 || mv -f $@.tmp $@
$(Q) rm -f $@.tmp
Expand Down Expand Up @@ -510,6 +511,7 @@ $(MACOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in | $(MACOS_BUIL
-e 's|@NUGET_VERSION_REV@|$(MACOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(MACOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|macOS|g' \
-e 's|@XCODE_VERSION@|$(subst .,_,$(XCODE_VERSION))|g' \
< $< > $@.tmp
$(Q) diff $@ $@.tmp >/dev/null 2>&1 || mv -f $@.tmp $@
$(Q) rm -f $@.tmp
Expand Down Expand Up @@ -735,6 +737,7 @@ $(WATCH_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.co
-e 's|@PACKAGE_VERSION_MINOR@|$(IOS_PACKAGE_VERSION_MINOR)|g' \
-e 's|@PACKAGE_VERSION_REV@|$(IOS_PACKAGE_VERSION_REV)|g' \
-e 's|@PACKAGE_VERSION_BUILD@|$(IOS_PACKAGE_VERSION_BUILD)|g' \
-e 's|@XCODE_VERSION@|$(subst .,_,$(XCODE_VERSION))|g' \
$< > $@.tmp
$(Q) diff $@ $@.tmp >/dev/null 2>&1 || mv -f $@.tmp $@
$(Q) rm -f $@.tmp
Expand Down Expand Up @@ -945,6 +948,7 @@ $(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.con
-e 's|@NUGET_VERSION_REV@|$(TVOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(TVOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|tvOS|g' \
-e 's|@XCODE_VERSION@|$(subst .,_,$(XCODE_VERSION))|g' \
$< > $@.tmp
$(Q) diff $@ $@.tmp >/dev/null 2>&1 || mv -f $@.tmp $@
$(Q) rm -f $@.tmp
Expand Down Expand Up @@ -1111,6 +1115,7 @@ $(MACCATALYST_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/M
-e 's|@NUGET_VERSION_REV@|$(MACCATALYST_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(MACCATALYST_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|MacCatalyst|g' \
-e 's|@XCODE_VERSION@|$(subst .,_,$(XCODE_VERSION))|g' \
$< > $@.tmp
$(Q) diff $@ $@.tmp >/dev/null 2>&1 || mv -f $@.tmp $@
$(Q) rm -f $@.tmp
Expand Down
15 changes: 11 additions & 4 deletions src/bgen/BindingTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class BindingTouch : IDisposable {
TypeCache? typeCache;
public TypeCache TypeCache => typeCache!;
public LibraryManager LibraryManager = new ();
public List<string> NoWarn = new ();

bool disposedValue;

Expand Down Expand Up @@ -220,13 +221,16 @@ public bool TryCreateOptionSet (BindingTouchConfig config, string [] args)
{ "nowarn:", "An optional comma-separated list of warning codes to ignore (if no warnings are specified all warnings are ignored).", v => {
try {
if (!string.IsNullOrEmpty (v)) {
foreach (var code in v.Split (new char [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
ErrorHelper.SetWarningLevel (ErrorHelper.WarningLevel.Disable, int.Parse (code));
foreach (var code in v.Split (new char [] { ',' }, StringSplitOptions.RemoveEmptyEntries)) {
if (int.TryParse (code, out var nowarnCode))
ErrorHelper.SetWarningLevel (ErrorHelper.WarningLevel.Disable, nowarnCode);
NoWarn.Add (code);
}
} else {
ErrorHelper.SetWarningLevel (ErrorHelper.WarningLevel.Disable);
}
} catch (Exception ex) {
throw ErrorHelper.CreateError (26, ex.Message);
throw ErrorHelper.CreateError (27, "--nowarn", ex.Message);
}
}
},
Expand Down Expand Up @@ -414,6 +418,8 @@ bool TryGenerate (BindingTouchConfig config, Api api)
// Ignore it, because we don't expect code to have everything documented.
cargs.Add ("-nowarn:1591");
}
foreach (var nw in NoWarn)
cargs.Add ($"-nowarn:{nw}");

AddNFloatUsing (cargs, config.TemporaryFileDirectory);

Expand Down Expand Up @@ -487,7 +493,8 @@ string GetCompiledApiBindingsAssembly (LibraryInfo libraryInfo, BindingTouchConf
// Ignore it, because we don't expect code to have everything documented.
cargs.Add ("-nowarn:1591");
}

foreach (var nw in NoWarn)
cargs.Add ($"-nowarn:{nw}");
AddNFloatUsing (cargs, tmpdir);

Compile (cargs, 2, tmpdir);
Expand Down
4 changes: 4 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ test.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Version.De
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(rid)_NUGET_RUNTIME_NAME=$($(rid)_NUGET_RUNTIME_NAME)\\n))" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),SUPPORTED_API_VERSIONS_$(platform)='$(SUPPORTED_API_VERSIONS_$(platform))'\\n)" | sed 's/^ //' >> $@
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)" >> $@
@printf "XCODE_VERSION=$(XCODE_VERSION)" >> $@

test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Version.Details.xml
@rm -f $@
Expand Down Expand Up @@ -120,6 +122,8 @@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Ver
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(rid)_NUGET_RUNTIME_NAME=$($(rid)_NUGET_RUNTIME_NAME)\\n))" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),SUPPORTED_API_VERSIONS_$(platform)='$(SUPPORTED_API_VERSIONS_$(platform))'\\n)" | sed 's/^ //' >> $@
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)" >> $@
@printf "XCODE_VERSION=$(XCODE_VERSION)" >> $@

clean-local::
$(Q) $(SYSTEM_XBUILD) /t:Clean /p:Platform=iPhoneSimulator /p:Configuration=$(CONFIG) $(XBUILD_VERBOSITY) tests.sln
Expand Down
4 changes: 3 additions & 1 deletion tests/common/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static partial class Configuration {
public static bool include_legacy_xamarin;
public static bool iOSSupports32BitArchitectures;
public static bool EnableXamarin;
public static bool XcodeIsStable;

static Version xcode_version;
public static Version XcodeVersion {
Expand Down Expand Up @@ -310,8 +311,9 @@ static Configuration ()
DotNetTfm = GetVariable ("DOTNET_TFM", null);
iOSSupports32BitArchitectures = !string.IsNullOrEmpty (GetVariable ("IOS_SUPPORTS_32BIT_ARCHITECTURES", ""));
EnableXamarin = !string.IsNullOrEmpty (GetVariable ("ENABLE_XAMARIN", ""));
XcodeIsStable = string.Equals (GetVariable ("XCODE_IS_STABLE", ""), "true", StringComparison.OrdinalIgnoreCase);

XcodeVersionString = GetXcodeVersion (xcode_root);
XcodeVersionString = GetVariable ("XCODE_VERSION", GetXcodeVersion (xcode_root));
#if MONOMAC
mac_xcode_root = xcode_root;
#endif
Expand Down
1 change: 1 addition & 0 deletions tests/generator/BGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ public void Issue19612 ()
var tf = TargetFramework.Parse (BGenTool.GetTargetFramework (profile));
cscArguments.Add ($"/r:{Configuration.GetBindingAttributePath (tf)}");
cscArguments.Add ($"/r:{Configuration.GetBaseLibrary (tf)}");
BGenTool.AddPreviewNoWarn (cscArguments);
var rv = ExecutionHelper.Execute (cscExecutable, cscArguments);
Assert.AreEqual (0, rv, "CSC exit code");

Expand Down
26 changes: 26 additions & 0 deletions tests/generator/BGenTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -206,6 +207,8 @@ string [] BuildArgumentArray ()
sb.Add (arg);
}

NoWarn = GetPreviewNoWarn (NoWarn);

if (NoWarn is not null) {
var arg = "--nowarn";
if (NoWarn.Length > 0)
Expand All @@ -217,6 +220,29 @@ string [] BuildArgumentArray ()
return sb.ToArray ();
}

public static void AddPreviewNoWarn (IList<string> argumentList)
{
var nw = GetPreviewNoWarn (null);
if (!string.IsNullOrEmpty (nw))
argumentList.Add ($"-nowarn:{nw}");
}

#if NET
[return: NotNullIfNotNull (nameof (existingNowarn))]
#endif
public static string? GetPreviewNoWarn (string? existingNowarn)
{
if (Configuration.XcodeIsStable)
return null;

var previewNoWarn = $"XCODE_{Configuration.XcodeVersion.Major}_{Configuration.XcodeVersion.Minor}_PREVIEW";
if (string.IsNullOrEmpty (existingNowarn)) {
return previewNoWarn;
} else {
return $"{existingNowarn},{previewNoWarn}";
}
}

public void AssertExecute (string message)
{
Assert.AreEqual (0, Execute (), message);
Expand Down
3 changes: 3 additions & 0 deletions tests/generator/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@ public void WarnAsError (Profile profile)
public void NoWarn (Profile profile)
{
Configuration.IgnoreIfIgnoredPlatform (profile.AsPlatform ());
if (!Configuration.XcodeIsStable)
Assert.Ignore ("This test doesn't work when using a preview Xcode, because we have to pass -nowarn to enable preview builds, which interferes with the test.");

const string message = "The member 'SomeMethod' is decorated with [Static] and its container class nowarnTests.FooObject_Extensions is decorated with [Category] this leads to hard to use code. Please inline SomeMethod into nowarnTests.FooObject class.";
{
// Enabled
Expand Down
Loading