Граф коммитов

225 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge d9e3206125
Merge branch 'main' into dotnet-dsyms 2022-03-23 22:24:51 +01:00
Rolf Bjarne Kvinge 6e74f875d9
Apply suggestions from code review
Co-authored-by: Chris Hamons <chris.hamons@xamarin.com>
2022-03-23 22:24:35 +01:00
Rolf Bjarne Kvinge 18fa252f1d
[msbuild] Show a better error when a bundle identifier isn't provided. Fixes #14283. (#14402)
Fixes https://github.com/xamarin/xamarin-macios/issues/14283.
2022-03-23 16:49:06 +01:00
Rolf Bjarne Kvinge 5e8bc0e7ee [msbuild] Remove the CollectFrameworks task, it's no longer used. 2022-03-22 16:14:26 +01:00
Rolf Bjarne Kvinge e5c81564e2 [msbuild/dotnet] Rework how we handle app bundle post processing. Fixes #14067.
Change dSYM generation and native stripping to occur immediately before code signing,
in a newly minted post processing target.

Challenges:

* Both calling 'strip' and 'codesign' on an executable modifies that executable,
  which means that we must make sure to not call 'dsymutil' on the same binary at
  a later point unless it's been rebuilt.
* Thus we must make sure to update 'dsymutil's stamp file whenever we call 'strip'
  and/or 'codesign' on an executable.
* Just like for code signing, we must store the libraries (either static or dynamic)
  we post process in extension/watch/rid-specific projects, so that these libraries
  can be loaded in containing projects and processed there.
* In universal .NET builds, debug symbols are created for the universal app bundle,
  not for each rid-specific version of the app bundle. So I had to add logic to create
  the native symbol lists (MtouchSymbolsList) for each rid-specific build, but then
  collect them and merge those lists for the universal app bundle.

The existing SymbolStrip call we did right after linking the native executable has
been removed, because we have to do that after creating the dSYM (which the GenerateDebugSymbols
target does).

Also add tests.

Fixes https://github.com/xamarin/xamarin-macios/issues/14067.
2022-03-22 16:14:26 +01:00
Rolf Bjarne Kvinge 3550aa4837 [msbuild] Move spotlight indexing out to its own task.
Also establish when we should do post processing: only in the outermost build. This
is a slight change from previous behavior, where we'd run strip/dsymutil separately
for app extensions and watch apps.
2022-03-22 16:14:26 +01:00
Rolf Bjarne Kvinge d0a45d1a75 [msbuild] Create a single target for post-processing (dsymutil/strip) an app bundle 2022-03-22 16:14:26 +01:00
Rolf Bjarne Kvinge 7d500da2bf
[msbuild] Rework code signing. (#14387)
The main theme here is that code signing will be done in the outermost
executable project, not in any app extension projects or watch projects, nor
during the RID-specific build of a .NET universal app. This makes codesigning
easier to reason about and other affected logic (such as strip/dsymutil)
easier to handle, in particular for .NET universal apps. Another benefit is
that the differences between the iOS and macOS code bases have been
eliminated.

The first step is to collect all the information we need from the targets
files. Every app bundle (be it app extension, watch app or main app) will add
its own output app bundle (.app/.appex) to the _CodesignBundle item group.
Then every app bundle will load this informarion from referenced app bundles,
and finally store this information on disk (in the 'codesign-bundle.items'
file). This means that in the end the main app bundle will have a list of all
contained app bundles in the app (recursively), in the _CodesignBundle item
group.

Separately we keep a list of other items that need signing, in the
_CodesignItems item group, and we do the same store/load logic for every
contained/contained app bundle (in the 'codesign.items' file, so a the end the
main app bundle will have a list of all the _CodesignItems for all contained
app bundles (recursively).

The previous steps occur in the _CollectCodesigningData and
_StoreCodesigningData targets.

The next step is to use the new ComputeCodesignItems task to compute
everything we need to know for code signing. This task takes over the
responsibility for listing all the *.dylib and *.metallib files, and the
*.framework directories in the app bundles, that need signing (which was
previously done in the targets file). This logic is significantly easier to
write, debug and test in C# than MSBuild.

In addition the ComputeCodesignItems also figures out a stamp file path we use
to determine if something needs (re-)signing. Previously .framework
directories did not have a stamp location, so they'd always end up resigned in
a rebuild, while now we'll automatically skip signing *.framework directories
unless something changed in them.

I've also tried to comment everything thorougly, for the next poor soul having
to deal with any bugs.

Behavioral differences:

* We were always signing *.dylib files for macOS. We're now doing the same
  thing for all platforms.
* We're now always signing *.framework directories for all platforms (like we
  do for *.dylib files), since frameworks are pretty much like dylibs anyways.

I've verified that this works both by running the submission tests and running
and launching a sample project on device from Windows.
2022-03-22 12:53:58 +01:00
Rolf Bjarne Kvinge 31e883899f
[msbuild] Add support for 'EnableCodeSigning' for mobile projects. (#14379)
Mac Catalyst and macOS projects support an 'EnableCodeSigning' property to determine
whether an app is signed or not. In order to bring parity on mobile platforms, add
support for this property for iOS, tvOS and watchOS projects as well - if not set,
we'll still have the old behavior of signing device builds and not signing simulator builds.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-03-17 14:27:31 +01:00
Rolf Bjarne Kvinge 2057fa3041 [msbuild] Remove code that got duplicated in a rebase. 2022-03-17 07:57:55 +01:00
Rolf Bjarne Kvinge 71482a9754 [msbuild] Resolve the path to the entitlements to a full path.
This way the property works when exposed to containing projects as well.
2022-03-16 21:00:15 +01:00
Rolf Bjarne Kvinge 5ec43ff963 [msbuild] Execute _CompileEntitlements target on macOS under same conditions as for other platforms.
The CompileEntitlements task already handles each platform as it should.

This way we have fewer differences in the code between platforms.
2022-03-16 21:00:15 +01:00
Rolf Bjarne Kvinge 3d05542677 [msbuild] Rework code signing.
The main theme here is that code signing will be done in the outermost executable
project, not in any app extension projects or watch projects, nor during the RID-specific
build of a .NET universal app. This makes codesigning easier to reason about and
other affected logic (such as strip/dsymutil) easier to handle, in particular for
.NET universal apps. Another benefit is that the differences between the iOS and
macOS code bases have been eliminated.

The first step is to collect all the information we need from the targets files.
Every app bundle (be it app extension, watch app or main app) will add its own output
app bundle (.app/.appex) to the _CodesignBundle item group. Then every app bundle
will load this informarion from referenced app bundles, and finally store this information
on disk (in the 'codesign-bundle.items' file). This means that in the end the main
app bundle will have a list of all contained app bundles in the app (recursively),
in the _CodesignBundle item group.

Separately we keep a list of other items that need signing, in the _CodesignItems
item group, and we do the same store/load logic for every contained/contained app
bundle (in the 'codesign.items' file, so a the end the main app bundle will have
a list of all the _CodesignItems for all contained app bundles (recursively).

The previous steps occur in the _CollectCodesigningData and _StoreCodesigningData
targets.

The next step is to use the new ComputeCodesignItems task to compute everything we
need to know for code signing. This task takes over the responsibility for listing
all the *.dylib and *.metallib files, and the *.framework directories in the app
bundles, that need signing (which was previously done in the targets file). This
logic is significantly easier to write, debug and test in C# than MSBuild.

In addition the ComputeCodesignItems also figures out a stamp file path we use to
determine if something needs (re-)signing. Previously .framework directories did
not have a stamp location, so they'd always end up resigned in a rebuild, while now
we'll automatically skip signing *.framework directories unless something changed
in them.

I've also tried to comment everything thorougly, for the next poor soul having to
deal with any bugs, as well has adding a comprehensive test for the new task.

Behavioral differences:

* We were always signing *.dylib files for macOS. We're now doing the same thing
  for all platforms.
* We're now always signing *.framework directories for all platforms (like we do
  for *.dylib files), since frameworks are pretty much like dylibs anyways.
2022-03-16 21:00:15 +01:00
Rolf Bjarne Kvinge 5934522ba8 [msbuild] Begone old code signing logic.
I'm removing the old logic first, because the new logic is so different that a diff
just complicates understanding what's happening (there's not much value in comparing
textually what's changed when it's pretty much a complete rewrite).
2022-03-16 21:00:15 +01:00
Rolf Bjarne Kvinge 1bcc85318a
[msbuild] Disable native strip + dsymutil for simulator builds by default. (#14380)
There's no reason to spend time running 'strip' or 'dsymutil' for simulator builds,
so default to not doing it.
2022-03-14 07:59:45 +01:00
Rolf Bjarne Kvinge 56829a2616
[msbuild] Improve the DSymUtil task. (#14344)
* Enable nullability and fix code accordingly.
* Augment it to be able to take multiple files to run dsymutil on at the same time.
* Execute using xcrun (ref: #3931)
* Pass the full path to the executable file to dsymutil, to make command lines
  easier to copy-paste.
2022-03-11 07:28:25 +01:00
Rolf Bjarne Kvinge 1a21e1ee5c
[msbuild] Make the CollectBundleResourcesDependsOn property public. Fixes #11984. (#14330)
Make the CollectBundleResourcesDependsOn property public, so that custom
targets can inject themselves into the build early enough to add additional
BundleResource or Content items (by adding their custom target's name to the
CollectBundleResourcesDependsOn property).

Fixes https://github.com/xamarin/xamarin-macios/issues/11984.
2022-03-09 18:19:48 +01:00
Rolf Bjarne Kvinge 22d7ccb8ee
[msbuild] Make the default value for NoDSymUtil the same for Mac Catalyst as it is for macOS. (#14337)
I think this is what makes most sense, since they're both desktop platforms.
2022-03-09 08:21:15 +01:00
Rolf Bjarne Kvinge 3da0665ff5
[msbuild] Make the _NoSymbolStrip and _NoDSymUtil properties public by removing the leading underscore. (#14248)
These are useful properties that were exposed in legacy Xamarin as Mtouch*
properties.
2022-02-28 11:27:44 +01:00
Rolf Bjarne Kvinge 429dc7b15e
[msbuild] Remove the AppBundleDir and Architectures properties from the DSymUtil task. (#14246)
These properties aren't used.

This also allows us to remove the CompiledArchitectures output property from
the MTouch task, because it's not longer used anymore either.
2022-02-26 02:08:34 +01:00
Rolf Bjarne Kvinge bd97933b60
[runtime] Remove ObjCRuntime.nfloat in favor of System.Runtime.InteropServices.NFloat. (#14197)
* Remove ObjCRuntime.nfloat (in favor of   System.Runtime.InteropServices.NFloat).
* Automatically add a reference to the System.Runtime.InteropServices.Internal
  package, so that developers get the new NFloat API (with operators) we've
  added post .NET 6 (but don't do this for .NET 7).
* Automatically add a global using alias for
  System.Runtime.InteropServices.NFloat -> nfloat. This is not behind the
  usual `ImplicitUsings` condition our other implicit usings are, because
  they're off by default for existing projects, and the main target for the
  global using alias for nfloat is upgraded projects.
* Automatically generate a global using alias (like above) in the generator
  for all code the generator compiles.
* Update xtro entries to reference System.Runtime.InteropServices.NFloat
  instead of ObjCRuntime.nfloat.
* Add a workaround for a hopefully temporary issue with .NET/CoreCLR where the
  wrong runtime pack is selected otherwise (without the new NFloat API, so
  nothing works at runtime).

Ref: https://github.com/xamarin/xamarin-macios/issues/13087
2022-02-24 16:51:12 +01:00
Rolf Bjarne Kvinge 4fd770c3c4
[msbuild/generator] Pass .NET's C# compiler to bgen to use. Fixes #12922. (#14192)
We can't execute mono's C# compiler when using .NET, so we need to tell bgen
where csc is in that case.

Fixes https://github.com/xamarin/xamarin-macios/issues/12922.
2022-02-23 09:36:43 +01:00
Rolf Bjarne Kvinge 21d7dd8de3
[msbuild] Move debug-related targets to shared code. (#14180) 2022-02-18 16:35:28 +01:00
Rolf Bjarne Kvinge e25163f573
[.NET] Rename our product assemblies. Fixes #13748. (#13847)
Rename our product assemblies to:

* Microsoft.iOS.dll
* Microsoft.tvOS.dll
* Microsoft.macOS.dll
* Microsoft.MacCatalyst.dll

This makes it easy to distinguish between legacy Xamarin and .NET whenever the
product assembly is mentioned, and I've also chosen the platform part of the
name to match how the platforms are named elsewhere (this also makes it
possible to simplify our build logic, since we can remove a lot of special
casing).

Fixes https://github.com/xamarin/xamarin-macios/issues/13748.
2022-02-16 21:30:32 +01:00
Rolf Bjarne Kvinge a404081365
[dotnet] Add support for the PublishFolderType metadata on Content and BundleResource items. (#14162)
Add support for the PublishFolderType metadata on Content and BundleResource
items, which makes it possible to change the location in the app bundle for
these items (this was possible to do before with the Link metadata), but most
importantly it also makes it possible to choose to *not* bundle these items in
the app bundle (which was not possible before with the Link metadata, nor any
other means).

At first I thought setting CopyToPublishDirectory /
CopyToOutputDirectory=Never would accomplish that, but it turns out we don't
honor those, and since we already have this behavior of ignoring
CopyToPublishDirectory / CopyToOutputDirectory in legacy Xamarin, I didn't
want to change it in .NET.

So I added support for honoring the PublishFolderType metadata instead, which
is new and we already support for other item groups. This is accomplished by
adding all Content and BundleResource items with PublishFolderType set to the
ResolvedFileToPublish item group (where we already handle any
PublishFolderType values), and then we ignore such Content and BundleResource
items in our CollectBundleResources task.

Also update the documentation and add tests.
2022-02-16 20:54:14 +01:00
Rolf Bjarne Kvinge 404b6e9af5
[msbuild/dotnet] Set NoBindingEmbedding to 'true' by default in .NET. Fixes #12530. (#12694)
Not embedding third-party libraries in the binding assembly is the future, and
let's try to enable it by default starting with .NET.

Fixes https://github.com/xamarin/xamarin-macios/issues/12530.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-02-16 10:30:41 +01:00
Rolf Bjarne Kvinge d8e7d2c854
[dotnet] Sign the 'createdump' executable. Fixes #13417. (#14111)
Fixes https://github.com/xamarin/xamarin-macios/issues/13417.
2022-02-15 08:28:29 +01:00
Rolf Bjarne Kvinge 5e462b1c21
[dotnet] Fix non-bundling of debug files for release builds. Fixes #14085. (#14103)
Fixes https://github.com/xamarin/xamarin-macios/issues/14085.
2022-02-09 16:46:04 +01:00
Rolf Bjarne Kvinge b48958be8e
[msbuild] Rework code signing to sign everything at the end of the build. (#13956)
* Add support for specifying metadata on items that are to be codesigned to
  override any general codesign setting.

* Make the Codesign task able to sign files and directories that may depend on
  eachother.

  Implement support for ordering signing so that directories containing files
  that also must be signed are signed after those files.

  This is implemented by:

  1. Normalize all input (resolve symlinks, create full path, etc.)

  2. Sort by path length (longest to shortest paths). This way we're certain
     that if we find a directory, we'll know that we won't find any files
     later in the list from inside that directory.

  3. Group into an ordered list of buckets, where each bucket contains files
     and directories that don't depend on eachother (i.e. they can all be
     signed in parallel).

  This makes it possible to call Codesign once, listing both the app bundle
  itself, and all the individual files or directories inside that need
  signing, and the Codesign task will sign the items in an order that ensures
  parent directories are always signed after any files or directories inside.

* Finally rework code signing to sign everything with a single call to the
  Codesign task in the _CodesignAppBundle target for the executable project,
  instead of having multiple calls to the Codesign task from multiple targets
  (and projects). This makes it easier to reason about what's being signed,
  and it also makes it easier to add files to the signing process.

* Also make the Codesign task able to figure out if something needs to be
  signed, and change the _CodesignAppBundle target to not keep track of
  inputs/outputs, because it becomes quite complex (for directories, it needs
  to keep track of all the files inside that directory, and also if there's
  anything in the directory that's also being signed).
2022-02-08 10:41:51 +01:00
Rolf Bjarne Kvinge 0d27c71a48
[msbuild] Unify the _CodesignAppBundle targets between iOS and Mac. (#13870)
The targets were somewhat different, where the Mac version seemed much less
evolved than the iOS version, so this meant mostly update the iOS version to
be Mac-compatible as well (and use it for macOS).
2022-01-28 09:20:58 +01:00
Rolf Bjarne Kvinge 82207afc70
[msbuild] Share the logic to CalculateCodesignAppBundleInputs between iOS and Mac. (#13844) 2022-01-25 11:34:42 +01:00
Rolf Bjarne Kvinge b3a9b07244
[msbuild] Share the logic to sign app extensions between iOS and Mac. (#13807) 2022-01-21 21:12:47 +01:00
Rolf Bjarne Kvinge bc1368cae0
[msbuild] Move the GetFiles task to shared msbuild code (Xamarin.MacDev.Tasks). (#13800) 2022-01-20 16:22:01 +01:00
Rolf Bjarne Kvinge c6ee74377a
[msbuild] Unify some of the codesign dependency properties. (#13725) 2022-01-19 18:54:08 +01:00
Rolf Bjarne Kvinge 1d9a02cbef
[dotnet] Figure out where to publish files in the app bundle. Fixes #12572. (#13591)
In .NET, all files that should be published (put into the final .app bundle) are put into the @(ResolvedFileToPublish) item group, and at the end of the build process, .NET will publish all the files in that item group. Which files are in this item group, and how they're put in there, is out of our control (it's just how the build process works in .NET), so we'll have to cope.

Additionally, publishing an app for Apple platforms is different than publishing other .NET apps, because we can't just put all the files in the a directory like .NET usually does, we have a fairly strict directory structure we need to follow, and it also differs between platforms (the structure is different between macOS and iOS for instance).

This means that for every file in the `ResolvedFileToPublish` item group, we have to figure out:

* Should it be put into the app bundle in the first place?
* If so, in which subdirectory (if any)?

This PR implements these changes. The exact details are explained in a document in the PR, but the general logic is:

* We make an educated guess for some types of files we know about (assemblies, unmanaged libraries, images, etc).
* We provide a way to set metadata on each item specifying which type of item it is (assembly, unmanaged library, image, etc), and we'll treat the item as such. This method can also be used to override the guess we made (for files that shouldn't be published for instance).
* We warn if we run into files we're not educated enough to be able to guess about, and for which there's no custom metadata set.

Fixes https://github.com/xamarin/xamarin-macios/issues/12572.
2022-01-17 09:50:06 +01:00
Rolf Bjarne Kvinge 2992e3be1b
[msbuild] Touch all files when copying an app extension into the app. (#13721)
Touch all files when copying an app extension into the app.

This fixes an issue where we'd in some cases run into this scenario:

* Build once (successfully), and sign the app (and app extension), including all dylibs.
* We build again, copy the (unsigned) app extension into the app again, but
  not sign dylibs because the timestamp went back into the past.
2022-01-17 09:05:08 +01:00
Rolf Bjarne Kvinge a2e4438536 Merge remote-tracking branch 'origin/main' into dotnet-resolvedfiletopublish 2022-01-13 22:13:00 +01:00
Rolf Bjarne Kvinge 38cf423936
[msbuild] Share the _CleanAppBundleRootDirectory target between iOS and Mac logic. (#13680) 2022-01-12 19:21:45 +01:00
Rolf Bjarne Kvinge 394c8fa4c7 [msbuild] The CollectBundleResources and DetectAppManifest targets need to know the target framework moniker. 2021-12-22 10:17:35 +01:00
Rolf Bjarne Kvinge 22220b149c [dotnet] Start using the new ComputeBundleLocation task 2021-12-22 10:17:35 +01:00
Rolf Bjarne Kvinge 19dc9ce0aa [msbuild] Add a ComputeBundleLocation task 2021-12-22 10:17:35 +01:00
Rolf Bjarne Kvinge 342b312a73
Our current behavior is to detect any None, BundleResource or Content item that's (#13550)
named 'Info.plist', and assume that's the app manifest.

That doesn't quite work when we end up with multiple 'Info.plist' entries in any
of those item groups (one example being a framework as a BundleResource - all frameworks
have an Info.plist, and there's no good way to distinguish what the developer's intention
was).

So:

1. Implement a 'AppManifestDetectionEnabled' property to disable automatic app manifest
   detection.

2. Add a public 'AppBundleManifest' property that specifies the app manifest
   (this is just a renamed version of our previously private '_AppManifest' property).

This makes it possible for app developers to:

* Disable automatic app manifest detection.
* Still have an app manifest by specifying it manually.
* Disable automatic app manifest detection, but also not specify an app manifest
  manually (so no custom app manifest at all).

Also:

* Rename '_AppBundleManifest' to '_AppBundleManifestPath' to make it less confusing
  with the new 'AppBundleManifest' property.
2021-12-14 20:56:52 +01:00
Rolf Bjarne Kvinge b8e9c61409
[dotnet] Parse the -gcc_flags and -link_flags mtouch/mmp arguments and pass them to the native linker. (#13521) 2021-12-13 08:33:26 +01:00
Rolf Bjarne Kvinge f8b6699ab2 Merge remote-tracking branch 'origin/main' into arm64-sim 2021-12-02 09:38:36 +01:00
Rolf Bjarne Kvinge 7dc5851520
[msbuild] Hardcode values for the nuget short folder name for legacy builds. Fixes #13469. (#13478)
The GetNuGetShortFolderName task only exists in .NET builds, which means we
have to find another way to compute the path to resources in nugets for legacy
builds. Do it the simple way by hardcoding the possible values.

Fixes https://github.com/xamarin/xamarin-macios/issues/13469.
2021-12-02 07:43:23 +01:00
Rolf Bjarne Kvinge ac441c1106 [msbuild] Detect SdkIsSimulator better for .NET by using the RuntimeIdentifier instead of only the architecture.
This way we're able to detect that "iossimulator-arm64" is actually a RID for the simulator.
2021-11-30 18:20:43 +01:00
Rolf Bjarne Kvinge 78f52e2fc2
[msbuild/tests] Add support for xcframeworks with static libraries in them. (#13459)
* [tests] Create a libtest.xcframework and libtest2.xcframework

* [tests] Make bindings-test and bindings-test2 use an xcframework instead of plain static library

* [msbuild] Add support for xcframeworks with static libraries in them.

* List the frameworks libtest needs.

* [tests] Update .NET unit tests according to test project changes.

* [tests] Add new test to verify that packing an old-style binding project doesn't work.
2021-11-30 18:19:22 +01:00
Rolf Bjarne Kvinge e2cacb8931
[msbuild] Don't use custom logic to handle facades in .NET. (#13461)
It's not needed, and may in some cases do the wrong thing: for instance, this
logic will automatically reference any *.dll files in the project directory,
which breaks the build if those *.dll files aren't actually assemblies.
2021-11-29 07:54:47 +01:00
Rolf Bjarne Kvinge 4afc8f7e3f
[dotnet] Put packages (.ipa/.pkg) in the publish directory by default. (#13436)
Partial fix for #12997.
2021-11-24 16:00:16 +01:00
Rolf Bjarne Kvinge fd126c8261
[msbuild] Use the correct logic to determine the PlugIns directory for all platforms. Fixes #13415. (#13418)
The '_AppExtensionRoot' contains the correct parent directory of the 'PlugIns'
directory for all platforms, so use that instead of appending 'PlugIns' to
'_AppBundlePath' - which is incorrect on macOS and Mac Catalyst, because the
'PlugIns' parent directory is '$(_AppBundlePath)/Contents' on those platforms.

Fixes https://github.com/xamarin/xamarin-macios/issues/13415.
2021-11-23 18:34:11 +01:00