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] Add @(XcodeProject) action #21232

Open
wants to merge 23 commits into
base: net9.0
Choose a base branch
from
Open

Conversation

pjcollins
Copy link
Member

@pjcollins pjcollins commented Sep 12, 2024

Context: https://github.com/CommunityToolkit/Maui.NativeLibraryInterop

Introduces a @(XcodeProject) build action which can be used to build and consume the outputs of Xcode framework projects.

The following metadata is supported on this item:

  <XcodeProject Include="path/to/myproject.xcodeproj" >
    <Configuration>Release</Configuration>
    <CreateNativeReference>true</CreateNativeReference>
    <ForceLoad></ForceLoad>
    <Frameworks></Frameworks>
    <Kind>Framework</Kind>
    <OutputPath></OutputPath>
    <SchemeName></SchemeName>
    <SmartLink></SmartLink>
    <Visible></Visible>
  </XcodeProject>
  • %(SchemeName): The name of the build scheme that should be used to build the project.

  • %(Configuration): The name of the configuration to use to build the project. The default value is Release.

  • %(CreateNativeReference): Output XCFRAMEWORK files will be added as a @(NativeReference) to be bound or otherwise used by the project. Metadata supported by @(NativeReference) like %(Kind), %(Frameworks), or %(SmartLink) will be forwarded if set.

  • %(OutputPath): Can be set to override the XCARCHIVE and XCFRAMEWORK output path of the Xcode project. The default value is $(IntermediateOutputPath)xcode/{SchemeName}-{Hash}.

A new _BuildXcodeProjects target will attempt to build XCARCHIVE and XCFRAMEWORK files for each @(XcodeProject) item. These outputs will be created for the platform specified in the target framework. If multiple target frameworks are specified, the project will be built for each platform during each inner build.

The built XCFRAMEWORK files will be added as @(NativeReference) items automatically, unless the %(CreateNativeReference) metadata is set to false.

A new $(MaciOSPrepareForBuildDependsOn) build extension point has been added to allow customer projects to more easily hook into the beginning of the build process.

Introduces a `@(MaciOSXcodeProject)` build action which can be used
to build and consume the outputs of Xcode framework projects.

The following metadata is supported on this item:

    <MaciOSXcodeProject Include="path/to/project.xcodeproj">
      <Configuration>Release</Configuration>
      <Kind>Framework</Kind>
      <OutputPath></OutputPath>
      <ReferenceXcFramework>true</ReferenceXcFramework>
      <SchemeName></SchemeName>
      <SharpieBind>true</SharpieBind>
      <SharpieNamespace></SharpieNamespace>
      <SmartLink>true</SmartLink>
    </MaciOSXcodeProject>

 * `%(Configuration)`: The name of the configuration to use to build
    the project. The default value is `Release`.

 * `%(OutputPath)`: Can be set to override the XCARCHIVE and XCFRAMEWORK
    output path of the Xcode project.

 * `%(ReferenceXcFramework)`: Output XCFRAMEWORK files will be added as
    a `@(NativeReference)` to be bound or otherwise used by the project.
    Metadata supported by `@(NativeReference)` like `%(Kind)` or
	`%(SmartLink)` will be forwarded if set.

 * `%(SchemeName)`: The name of the build scheme that should be used to
    build the project. The default value is
    `$(IntermediateOutputPath)xcode/{SchemeName}-{Hash}`.

 * `%(SharpieBind)`: Output XCFRAMEWORK files will be bound using
    Objective Sharpie. The default value is `true`.

 * `%(SharpieNamespace)`: The namespace to use when binding output
    XCFRAMEWORK files with Objective Sharpie.

A new `_BuildMaciOSXcodeProjectFrameworks` target will attempt to build
XCARCHIVE and XCFRAMEWORK files for each `@(MaciOSXcodeProject)` item.
These outputs will be created for the platform specified in the target
framework. If multiple target frameworks are specified, the project
will be built for each platform during each inner build.

The built XCFRAMEWORK files will be added as `@(NativeReference)` items
automatically, unless the `%(ReferenceXcFramework)` metadata is set to
`false`.

A new `$(MaciOSPrepareForBuildDependsOn)` build extension point has been
added to allow customer projects to more easily hook into the beginning
of the build process.
@pjcollins
Copy link
Member Author

pjcollins commented Sep 12, 2024

Putting this up for some early review while it is still in progress, as I am not sure if I am adding these tasks/targets and tests to the best locations. The Android counterpart for these changes can be found in dotnet/android#9270.

Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

dotnet/targets/Microsoft.MaciOS.Sdk.Xcode.targets Outdated Show resolved Hide resolved
dotnet/targets/Microsoft.MaciOS.Sdk.Xcode.targets Outdated Show resolved Hide resolved
dotnet/targets/Microsoft.MaciOS.Sdk.Xcode.targets Outdated Show resolved Hide resolved
dotnet/targets/Microsoft.MaciOS.Sdk.Xcode.targets Outdated Show resolved Hide resolved
dotnet/targets/Microsoft.MaciOS.Sdk.Xcode.targets Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
@pjcollins pjcollins changed the title [msbuild] Add @(MaciOSXcodeProject) action [msbuild] Add @(XcodeProject) action Sep 13, 2024
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, just a few minor things.

Love all tests!

docs/build-apps/build-properties.md Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Show resolved Hide resolved
[Test]
public void BuildMultiTargeting ()
{
var testDir = Cache.CreateTemporaryDirectory (TestName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want the test to run when all platforms are available, you can do this:

Configuration.IgnoreIfAnyIgnoredPlatforms ();

otherwise you need to assert that at least iOS is available:

Configuration.IgnoreIfIgnoredPlatform (ApplePlatform.iOS);

(although the test seems to need at least another platform, and you'll have to pick one if you don't want to just require all of them).

Copy link
Member Author

@pjcollins pjcollins Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured this would safely run against all enabled platforms, and that it would be pretty rare for a branch to exist that only supports one platform? Even in that case it's probably fine for this to still run and not truly test multitargeting, as there should be a corresponding branch that will have multiple platforms enabled and be testing a multitargeted project?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all branches, we run these tests concurrently in 5 modes (in 5 different bots; this is to speed up the test run):

  1. iOS enabled, all other platforms disabled + excluding tests with the "Multiplatform" category.
  2. tvOS enabled, all other platforms disabled + excluding tests with the "Multiplatform" category.
  3. macOS enabled, all other platforms disabled + excluding tests with the "Multiplatform" category.
  4. Mac Catalyst enabled, all other platforms disabled + excluding tests with the "Multiplatform" category.
  5. All available platforms enabled, only tests with the "Multiplatform" category.

So while it's technically really rare that a branch exists that only supports one platform, we run these tests with only one platform all the time.

It's not as rare to have a branch where iOS is completely disabled (we've done macOS/Mac Catalyst-only release branches in the past), in which case the multi platform variation will fail as it stands, because iOS won't be enabled for creating a a new "iosbinding" project.

This is why you need either of the Configuration.IgnoreIf[...] statements I mentioned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context, I'll make a couple of changes here to check for an enabled platform to create the template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should now work as long as some platform is enabled

tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
tests/dotnet/UnitTests/XcodeProjectTests.cs Outdated Show resolved Hide resolved
@vs-mobiletools-engineering-service2

This comment has been minimized.

pjcollins and others added 2 commits September 20, 2024 14:52
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [CI Build] Artifacts 📚

Artifacts were not provided.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 446d6efbc49e1b01aef21e6fa59a909918fa024e [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 446d6efbc49e1b01aef21e6fa59a909918fa024e [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants