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

51 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge a33c80d6c7
[net8.0] Change the default RuntimeIdentifier. (#18495)
* When publishing a mobile app, choose a device architecture (as opposed
  to showing an error if none was specified by the developer)
* When building for the simulator, choose the arm64 runtime identifier
  if we're running on an arm64 machine.
* When building a Debug build for desktop, choose the arm64 runtime
  identifier if we're running on an arm64 machine.

Fixes https://github.com/xamarin/xamarin-macios/issues/18455.
Fixes https://github.com/xamarin/xamarin-macios/issues/16152.
Fixes https://github.com/xamarin/xamarin-macios/issues/17841.

Section in the release notes: https://github.com/xamarin/xamarin-macios/wiki/.NET-8-release-notes#default-runtimeidentifiers

---------

Co-authored-by: Alex Soto <alex@alexsoto.me>
2023-08-07 17:51:37 +02:00
Filip Navara 53ff85f67c
[NativeAOT] Remove IlcKeepManagedDebuggerSupport workaround (#18515)
Fixes #18478

Co-authored-by: Alex Soto <alex@alexsoto.me>
2023-08-01 16:05:35 +02:00
Rolf Bjarne Kvinge 42d6121e12 [dotnet] Set a flag to avoid a bug with the NativeAOT compiler 2023-06-22 08:44:47 +02:00
Rolf Bjarne Kvinge 264be7055e [dotnet] Disable SelfContained for the outer build of a universal app build when using NativeAOT. 2023-06-22 08:44:47 +02:00
Rolf Bjarne Kvinge 7d65804e32 [dotnet/tests] Only use NativeAOT when publishing.
This matches how NativeAOT works for other platforms.
2023-06-22 08:44:47 +02:00
Rolf Bjarne Kvinge e3228d04ea [dotnet] Turn off some publishing behavior we don't need 2023-06-21 20:49:56 +02:00
Rolf Bjarne Kvinge d601e51698 [dotnet] Set PublishAotUsingRuntimePack=true when using NativeAOT to get the correct BCL libraries. 2023-06-21 20:49:56 +02:00
Rolf Bjarne Kvinge 13fa76923f [dotnet] Disable our own IL stripping when using NativeAOT, because NativeAOT already does something equivalent 2023-06-21 20:49:54 +02:00
Rolf Bjarne Kvinge e0e4b77a55 [dotnet] Set AutoreleasePoolSupport earlier so that the linker doesn't set it first.
Might not be necessary: https://github.com/dotnet/runtime/pull/86753
2023-06-21 20:49:52 +02:00
Rolf Bjarne Kvinge 5d6a92eaf0 [net8.0] Merge main into net8.0. 2023-06-12 18:56:10 +02:00
Ivan Povazan e3088879a6
Reduce the size of `__LINKEDIT Export Info` section in stripped binaries (#18408)
# Description

This PR reduces the application's SOD (size on disk) by making
`__LINKEDIT Export Info` section smaller in the stripped Mach-O
binaries.

The feature is controlled by `_ExportSymbolsExplicitly` MSBuild property
and can be disabled by specifying: `-p:_ExportSymbolsExplicitly=true`

Fixes #18332 

# Initial problem

It has been noticed that during stripping, the strip tool does not
resize the export info section after it removes the symbols. Instead it
only zeroes out the entries (achieved by calling `prune_trie` function):

- https://github.com/apple-oss-distributions/cctools/blob/cctools-986/misc/strip.c
- https://github.com/apple-oss-distributions/ld64/blob/ld64-711/src/other/PruneTrie.cpp

Thanks @lambdageek for helping to track this down.

# Approach

As Xamarin build process already collects all the [required symbols][1] needed
for the application to run and preserves them during the strip phase, we can
use the same file to instruct clang toolchain to export only those symbols via
the command line options: `-exported_symbols_list <file>` ([source][2]).

This will make the export info section only include what is necessary for the
runtime - and at the same time eliminate the problem of the `strip` tool which
does not resize stripped symbols.

# Investigation setup

The issue is observable by building and inspecting the test application:
https://github.com/xamarin/xamarin-macios/blob/main/tests/dotnet/MySingleView/MySingleView.csproj
and targeting iOS platform in Release mode.

## Results:

| Measure      | MySingleView - main | MySingleView - this PR | Diff (%) | 
| :---         |                ---: |                   ---: |     ---: |
| SOD (bytes)  |            13668940 |               13458476 |    -1.5% |
| .ipa (bytes) |             4829368 |                4827928 |   -0.03% |

Even though zeroes are compressed well, the SOD is still affected and
unused section takes around 1.5% of the most simplistic app size.
Much bigger impact has been noted when trying out a MAUI iOS template
app with NativeAOT where the `__LINKEDIT Export Info` zeroes take up to
20MB of the SOD, but also with the regular macOS applications:
https://github.com/dotnet/runtime/issues/86707

### Repro current state of MySingleView.app with stripped binary

1. Build the app (you can ignore the need to run the sample, I just did it to
   make sure the changes do not break anything)

```bash
make run-device
``` 

2. Print the load commands - [load_cmds_strip.list][3]

```bash
otool -l bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > load_cmds_strip.list
```

- We are interested in the export info section:

```
cmd LC_DYLD_INFO_ONLY
...
export_off 5942960
export_size 207712
```

3. Create a hex dump of the export info section - [hex_dump_strip.list][4]

``` bash
xxd -s 5942960 -l 207712 bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > hex_dump_strip.list
```

- NOTE: Notice around ~200kb of zeroes from ~0x005ab490 to ~0x005dda00
    
4. Verify exported symbols are correct - [dyld_info_strip.list][5]

``` bash
dyld_info -exports bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > dyld_info_strip.list
```

### Repro current state of MySingleView.app with unstripped binary

1. Build the app (the make target preserves the symbols)

```bash
make run-device-no-strip
``` 

2. Print the load commands - [load_cmds_nostrip.list][6]

```bash
otool -l bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > load_cmds_nostrip.list
```

- We are interested in the export info section:

```
cmd LC_DYLD_INFO_ONLY
...
export_off 5942960
export_size 207712
```

3. Create a hex dump of the export info section - [hex_dump_nostrip.list][7]

``` bash
xxd -s 5942960 -l 207712 bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > hex_dump_nostrip.list
```

- Notice that the range: ~ 0x005ab490 to ~ 0x005dda00 now includes exported symbol entries
    
4. Verify exported symbols are correct - [dyld_info_nostrip.list][8]

``` bash
dyld_info -exports bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > dyld_info_nostrip.list
```

### Repro the new approach 

1. Build the app (the make target uses the new approach)

```bash
make run-device-export-syms
``` 

2. Print the load commands - [load_cmds_export.list][9]

```bash
otool -l bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > load_cmds_export.list
```

- We are interested in the export info section ***notice the reduced size of the section***:

```
cmd LC_DYLD_INFO_ONLY
...
export_off 5942432
export_size 1048
```

3. Create a hex dump of the export info section - [hex_dump_export.list][10]

``` bash
xxd -s 5942432 -l 1048 bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > hex_dump_export.list
```
    
4. Verify exported symbols are correct - [dyld_info_export.list][11]

``` bash
dyld_info -exports bin/Release/net7.0-ios/ios-arm64/MySingleView.app/MySingleView > dyld_info_export.list
```

---

## Additional benefits

With this approach we could also switch the way strip tool is invoked to
always strip all debug and local symbols via `strip -S -x` instead of passing
the file with symbols to preserve. This would remove the warning that we are
currently getting (which is being ignored):

```
/Applications/Xcode_14.3.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: warning: removing global symbols from a final linked no longer supported.  Use -exported_symbols_list at link time when building...
```

## Other references:

- https://github.com/qyang-nj/llios/blob/main/exported_symbol/README.md

[1]: 11e7883da0/tools/dotnet-linker/Steps/GenerateReferencesStep.cs (L38-L44)
[2]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
[3]: https://gist.github.com/ivanpovazan/d53f8d10be5e4ea9f39a41ea540aa7fa
[4]: https://gist.github.com/ivanpovazan/60637422f3ff8cb5f437ddd06a21d9c1
[5]: https://gist.github.com/ivanpovazan/352595ad15c2ac02f38dcb3bd4130642
[6]: https://gist.github.com/ivanpovazan/bf700161f2f3691d1d7381c98d4fa0be
[7]: https://gist.github.com/ivanpovazan/44269e4fff5ebd58a4d181451e5c106f
[8]: https://gist.github.com/ivanpovazan/38c5afe076502d514a77420af0e10b01
[9]: https://gist.github.com/ivanpovazan/3f663c3c630005f5a578605d48ba807e
[10]: https://gist.github.com/ivanpovazan/0bb84f64281d05ab20438aeaed64f13c
[11]: https://gist.github.com/ivanpovazan/78b3ba2288f53a2316b9bc46964e7e4f

---------

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2023-06-12 13:45:38 +02:00
Rolf Bjarne Kvinge 6f1c0ea534 [net8.0] Merge main into net8.0. 2023-06-08 13:32:48 +02:00
VS MobileTools Engineering Service 2 1527450920
[dotnet] Set _RequiresILLinkPack=true so that we always restore the ILLink package. (#18412)
This property will be required when building for a net7.0-* target framework
using .NET 8 (preview 6 - preview 5 does not need this fix)

Backport of #18411
2023-06-07 08:48:42 +02:00
dotnet-maestro[bot] 99ffae1f0d
[net8.0] Update dependencies from dotnet/installer (#18271)
This pull request updates the following dependencies

## Coherency Updates

The following updates ensure that dependencies with a *CoherentParentDependency*
attribute were produced in a build used as input to the parent dependency's build.
See [Dependency Description Format](https://github.com/dotnet/arcade/blob/master/Documentation/DependencyDescriptionFormat.md#dependency-description-overview)

- **Coherency Updates**:
  - **Microsoft.NET.ILLink.Tasks**: from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.AspNetCore.App.Ref**: from 8.0.0-preview.5.23252.26 to 8.0.0-preview.5.23262.1 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.NETCore.App.Ref**: from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100.Transport**: from 8.0.0-preview.5.23225.2 to 8.0.0-preview.5.23252.1 (parent: Microsoft.NETCore.App.Ref)
  - **Microsoft.NETCore.App.Ref**: from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3 (parent: Microsoft.Dotnet.Sdk.Internal)

## From https://github.com/dotnet/installer
- **Subscription**: f9b68d84-9c90-4bd0-5499-08db4112d57e
- **Build**: 20230517.7
- **Date Produced**: May 17, 2023 9:29:46 PM UTC
- **Commit**: dda516cbd77ab9dc3c6048a1893b4321cdcda195
- **Branch**: refs/heads/main

- **Updates**:
  - **Microsoft.Dotnet.Sdk.Internal**: [from 8.0.100-preview.5.23258.8 to 8.0.100-preview.5.23267.7][29]
  - **Microsoft.NET.ILLink.Tasks**: [from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3][30]
  - **Microsoft.AspNetCore.App.Ref**: [from 8.0.0-preview.5.23252.26 to 8.0.0-preview.5.23262.1][31]
  - **Microsoft.NETCore.App.Ref**: [from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3][30]
  - **Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100.Transport**: [from 8.0.0-preview.5.23225.2 to 8.0.0-preview.5.23252.1][32]
  - **Microsoft.NETCore.App.Ref**: [from 8.0.0-preview.5.23252.13 to 8.0.0-preview.5.23260.3][30]

[29]: 1ab664ce1c...dda516cbd7
[30]: bc9dad2351...888bac3044
[31]: 730dac21a5...059939bda4
[32]: 81590b9b84...ab09b0b8d6
2023-05-19 07:33:48 +02:00
Haritha Mohan 3dff232920
[dotnet] Enable generation of runtime configuration file (#17840)
Set the GenerateRuntimeConfigurationFiles (GRCF) property to true 
to avoid warnings at build time + add test for change.

Diving deeper into the fix...
- This warning only occurs with .NET apps which is why GRCF
is only updated in the dotnet directory and not msbuild (legacy)
- After examining the binlog (see issue), it was found that the GRCF 
was contingent upon the HasRuntimeOutput property, which is only 
defined for executable projects. And in this case, the user's project
output type is library thus both the RuntimeOutput and consequently 
GRCF properties were not enabled.
- By setting the GRCF to true we can address the original warning of 
concern while ensuring the rest of the projects's behavior is not
altered
in mysterious ways (i.e. by touching the RuntimeOutput property or the 
project output type instead, these changes could have extraneous
effects).

Fixes #17543

---------

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2023-03-23 08:10:04 -07:00
Mauro Agnoletti 7f7942eae0
Imports the .user.env file if exists and the build is from VS (#17466)
This will allow the latest runtime identifier values to be evaluated in time during the MSBuild property evaluation phase.

Related and dependent of this PR: https://github.com/xamarin/XamarinVS/pull/13606
2023-02-08 09:37:39 +01:00
Rolf Bjarne Kvinge 7d02fa6f4f
[dotnet] Ensure any trimmer components are restored properly. (#17227)
.NET 8 will load the ILLink component based on the target framework of the
project file - so if .NET 8 is building a net7.0-ios app, the build will
restore and use the ILLink component from .NET 7.

There is a problem however:

* The inclusion of the ILLink component is dpendent on the PublishTrimmed
  property - if PublishTrimmed is true, then the ILLink component is restored
  (which makes sense, why restore it if it's not going to be used?).
* We always PublishTrimmed, because the linker must always be executed for our
  projects. So far so good - we can just always enable PublishTrimmed, right?
* Nope, when building on Windows, we only enable PublishTrimmed when connected
  to a Mac, because that's where the ILLink target must be executed (and if
  we're not connected to a Mac, we can't run the ILLink target, and things
  fall apart - so just disable PublishTrimmed in that, since it won't work
  anyway).
* Early on in the build we have no idea if we're connected to a Mac or not,
  which means we can only enable PublishTrimmed in a target, and not as an
  early-on default value. This is *way* to late for the ILLink component,
  which needs PublishTrimmed set quite early in the build process.
* Fortunately, the ILLink inclusion is actually gated on a different variable
  (_IsTrimmingEnabled) - which is initialized from PublishTrimmed if it's not
  set. So the way out here is to set _IsTrimmingEnabled early enough, and now
  the ILLink component is included and restored.
* The additional hurdle is that we need to set _IsTrimmingEnabled in our .NET
  6 and .NET 7 workloads as well, it's not enough to set it in our .NET 8
  workload (which isn't even loaded when building an earlier TFM).
2023-01-16 08:21:09 +01:00
Rolf Bjarne Kvinge 18962171b9 Merge main into net7.0. 2022-10-13 13:36:40 +02:00
Rolf Bjarne Kvinge 9e3dbf2c09
[dotnet] Hardcode 'true' as the default value for GenerateSatelliteAssembliesForCore. Fixes #16193. (#16306)
Hardcode 'true' as the default value for GenerateSatelliteAssembliesForCore,
because .NET gets it wrong when building from inside VS (Windows).

When building using either VSMac or the command line (either from Windows or
Mac), the `MSBuildRuntimeType` property is set to `Core`, and as a result, the
default value for `GenerateSatelliteAssembliesForCore` is `true`:

```xml
<GenerateSatelliteAssembliesForCore Condition=" '$(GenerateSatelliteAssembliesForCore)' == '' and '$(MSBuildRuntimeType)' == 'Core' ">true</GenerateSatelliteAssembliesForCore>
```

See: 00100960bf/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets (L41)

This is the correct behavior.

However, when building from inside Visual Studio (for Windows), the
`MSBuildRuntimeType` property is set to `Full`, and thus
`GenerateSatelliteAssembliesForCore` is not set to `true`, and we end up
executing al.exe to generate satellite assemblies, which is wrong (al.exe
complains that 'arm64' is an invalid platform).

Fix this by always defaulting `GenerateSatelliteAssembliesForCore` to `true`,
independent on where we're executing.

Ref: https://github.com/dotnet/sdk/issues/28419.

Fixes https://github.com/xamarin/xamarin-macios/issues/16193.
2022-10-10 21:41:36 +02:00
Rolf Bjarne Kvinge 2ddb7a6d68
[dotnet] Make relase builds for desktop universal by default. Fixes #15620. (#15769) 2022-08-31 16:45:10 +02:00
dotnet-maestro[bot] 62055c56fb
[net7.0] Update dependencies from dotnet/installer (#15657)
* Update dependencies from https://github.com/dotnet/installer build 20220807.1

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22407.1

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220808.5

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22408.5

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220809.23

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22409.23

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220810.15

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22410.15

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220812.1

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22412.1

Dependency coherency updates

Microsoft.NET.ILLink.Tasks,Microsoft.NETCore.App.Ref,Microsoft.AspNetCore.App.Ref
 From Version 7.0.100-1.22377.1 -> To Version 7.0.100-1.22411.2 (parent: Microsoft.Dotnet.Sdk.Internal

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220813.1

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22413.1

Dependency coherency updates

Microsoft.NET.ILLink.Tasks,Microsoft.NETCore.App.Ref,Microsoft.AspNetCore.App.Ref
 From Version 7.0.100-1.22377.1 -> To Version 7.0.100-1.22412.1 (parent: Microsoft.Dotnet.Sdk.Internal

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220814.7

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22414.7

Dependency coherency updates

Microsoft.NET.ILLink.Tasks,Microsoft.NETCore.App.Ref,Microsoft.AspNetCore.App.Ref
 From Version 7.0.100-1.22377.1 -> To Version 7.0.100-1.22412.1 (parent: Microsoft.Dotnet.Sdk.Internal

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220816.2

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.1.22416.2

Dependency coherency updates

Microsoft.NET.ILLink.Tasks,Microsoft.NETCore.App.Ref,Microsoft.AspNetCore.App.Ref
 From Version 7.0.100-1.22377.1 -> To Version 7.0.100-1.22415.1 (parent: Microsoft.Dotnet.Sdk.Internal

* Re-generate global.json

* Update dependencies from https://github.com/dotnet/installer build 20220817.1

Microsoft.Dotnet.Sdk.Internal
 From Version 7.0.100-rc.1.22405.9 -> To Version 7.0.100-rc.2.22417.1

Dependency coherency updates

Microsoft.NET.ILLink.Tasks,Microsoft.NETCore.App.Ref,Microsoft.AspNetCore.App.Ref
 From Version 7.0.100-1.22377.1 -> To Version 7.0.100-1.22415.4 (parent: Microsoft.Dotnet.Sdk.Internal

* Re-generate global.json

* [dotnet] Include the 'marshal-ilgen' component. Fixes #15668.

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

* [dotnet] Enable serialization discovery in the linker. Fixes #15676.

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

* [tests] Make the dont link tests actually not link for macOS.

* [tests] The 'trimmode copy' test needs an adjustment after recent linker changes.

* [dotnet] Don't set a default 'TrimMode' value.

We already compute a TrimMode value depending on other properties
(MtouchLink/LinkMode - or a default value if those aren't set), and the logic
to compute the default value is not executed if we set a TrimMode default (because
TrimMode overrides any MtouchLink/LinkMode values).

* [tests] Workaround a bug in 'dotnet build'.

Workaround a bug in 'dotnet build' where escaping semicolons interferes with
our ability to pass RuntimeIdentifiers to the build on the command line.

* [dotnet] Update expected bundle contents according to updated runtime.

* [tests] Update expected error message texts.

* Bump to RC 2.

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: GitHub Actions <github-actions@xamarin.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-08-19 12:53:56 +02:00
Andy Gocke c558df7524
Merge branch 'main' into set-trimmode-partial 2022-07-10 19:45:16 -07:00
Andy Gocke d67523d437 Set TrimMode to partial if not set
Companion to https://github.com/dotnet/linker/pull/2856
2022-06-28 11:47:44 -07:00
Emanuel Fernandez Dell'Oca 3af92421f9
[dotnet] Adds platform specific RID options (#14643)
This enables Visual Studio to set a specific `RuntimeIdentifier` for each platform when building all target frameworks in a MAUI project.

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-04-06 09:39:33 +02:00
Rolf Bjarne Kvinge bb655a3840
[dotnet] Only validate the RuntimeIdentifier if we need/use it. Fixes #13482. (#14339)
Fixes https://github.com/xamarin/xamarin-macios/issues/13482.
2022-03-09 08:22:52 +01:00
Rolf Bjarne Kvinge 0d0b0bc86b [dotnet] Always set 'UseAppHost' and '_RuntimeIdentifierUsesAppHost' to 'false' in .NET.
Otherwise .NET might want to include an app host in the app, which ends up with a
build warning, because we don't use apphosts.
2021-12-22 10:17:34 +01:00
Rolf Bjarne Kvinge 86a3689b77 [dotnet] Make sure that MSBuild doesn't strip away our PublishFolderType metadata 2021-12-22 10:17:34 +01:00
Rolf Bjarne Kvinge 2aa21751a6
[dotnet] Show an error if an app developer tries to publish a simulator architecture. (#13462)
* [dotnet] Show an error if an app developer tries to publish a simulator architecture.

* We can't publish a simulator build, so show an error in that case.
* We can't change the default runtime identifier when publishing (to a
  publishable runtime identifier), because by the time we know we're
  publishing, it's too late to change the runtime identifier. This means that
  it'll be required for app developers to specify a runtime identifier when
  publishing to a mobile platform, since the current default runtime
  identifier is for a simulator build.

Partial fix for https://github.com/xamarin/xamarin-macios/issues/12997.

* Fix typo and improve naming.

* [dotnet] Don't use '_UsingDefaultRuntimeIdentifier', it's already used elsewhere in .NET
2021-11-29 23:13:48 +01:00
Chris Hamons a6eb528197
[net6][msbuild] Set SelfContained for AppExtensions sooner to fix publishing (#12703)
This PR resolves a crash when running the linker on publishing iOS extensions.

The crash would occur here in failing to resolve corelib.

The reason this would fail was System.Private.CoreLib.dll was not in input_assemblies.

This was because we were passes the set of reference assemblies not the expected 'real' ones, and those do not include CoreLib.

After a bunch of digging, this was because _ComputeManagedRuntimePackAssembliesIfSelfContained target was not being set as a condition of _ComputeAssembliesToPostprocessOnPublish.

_ComputeManagedRuntimePackAssembliesIfSelfContained happened to be the place these were added, and wasn't being set since it has a condition of $(SelfContained) == 'true'

Now confusingly SelfContained WAS being set to true, but only in the targets file, which was too late, as it was checked in a 'global' property group outside of a target.

This means we'd fail to set SelfContained until after the condition, and not run.

This was verified by setting /p:SelfContained=true to true.

I also looked at removing the condition above, since https://github.com/dotnet/runtime/issues/54406 is fixed, however this caused project that didn't set RuntimeIdentifier to fail.
2021-09-20 09:40:41 -05:00
Rolf Bjarne Kvinge c2fda6ebf9
[dotnet] Enable LLVM by default for release builds. Fixes #12147. (#12660)
Fixes https://github.com/xamarin/xamarin-macios/issues/12147.
2021-09-08 18:04:39 +02:00
Rolf Bjarne Kvinge ab88892fd1
[dotnet] Update logic for default global namespaces and fix the templates. Fixes #12457. (#12471)
* Add 'ImplicitUsings=true' to all the templates.
* Make the implicit global namespaces C#-only.
* Add the implicit global namespaces to the 'Using' itemgroup instead of the
  'Import' itemgroup.
* Make sure the global namespaces are set from AutoImport.props, so that the
  user may remove any global namespace they don't want in their project file
  (by doing something like: `<Using Remove="Foundation" />`)

Ref: https://github.com/dotnet/sdk/issues/19521
Ref: https://github.com/dotnet/sdk/issues/19793

Fixes https://github.com/xamarin/xamarin-macios/issues/12457.
2021-08-19 07:47:03 +02:00
Emanuel Fernandez Dell'Oca 7c66aa3829
[net6] Fixes build issues from VS for Preview 7 (#12281)
* [net6] Adds missing custom linker steps when building from Windows

To share the definition of the custom steps we need to specify the right path to the `dotnet-linker.dll`.

When building from macOS `_XamarinSdkRootDirectoryOnMac` will have the same value as `_XamarinSdkRootDirectory` (which is the local Xamarin SDK dir), but from Windows the former will be the path to the Xamarin SDK on the connected Mac. Essentially this new property is agnostic from the platform from which the build is being executed, and will always return the path to the Xamarin SDK on macOS (either local or remote), so it can be used on scenarios like this one where we know the resource we need should always be referenced from macOS.

* [net6] Updates .NET SDK path for remote tasks execution

This path needs to be updated because VS (from Dev17 Preview 3+) will install through XMA the .NET SDK and the iOS SDK on macOS in a custom dir. This should be the preferred path when building from Windows if it does exist.

* Adds missing spaces to TaskRunner.cs
2021-07-29 15:20:20 +02:00
Rolf Bjarne Kvinge a010778b30
[dotnet] Add support for implicit namespace imports. Fixes #12084. (#12173)
* [dotnet] Add support for implicit namespace imports. Fixes #12084.

Also update our templates to remove any using statements for implicitly imported
namespaces.

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

* [monotouch-test] Fix compilation error due to implicit namespace causing type conflict.

Fixes these errors:

    xamarin-macios/tests/monotouch-test/ImageIO/MutableImageMetadataTest.cs(54,54): error CS0104: 'CGImageProperties' is an ambiguous reference between 'CoreGraphics.CGImageProperties' and 'ImageIO.CGImageProperties'
    xamarin-macios/tests/monotouch-test/ImageIO/MutableImageMetadataTest.cs(54,88): error CS0104: 'CGImageProperties' is an ambiguous reference between 'CoreGraphics.CGImageProperties' and 'ImageIO.CGImageProperties'
    xamarin-macios/tests/monotouch-test/ImageIO/ImageMetadataTest.cs(40,54): error CS0104: 'CGImageProperties' is an ambiguous reference between 'CoreGraphics.CGImageProperties' and 'ImageIO.CGImageProperties'
    xamarin-macios/tests/monotouch-test/ImageIO/ImageMetadataTest.cs(40,88): error CS0104: 'CGImageProperties' is an ambiguous reference between 'CoreGraphics.CGImageProperties' and 'ImageIO.CGImageProperties'
2021-07-23 15:07:03 +02:00
Rolf Bjarne Kvinge 423bd571ec Merge remote-tracking branch 'origin/main' into darc-main-2c3dc6cd-c245-4d20-9461-75a98d067b3b 2021-07-13 14:30:18 +02:00
Jonathan Peppers 33f8143b97
[dotnet] no default $(RuntimeIdentifier) for class libraries (#12093)
Context: https://github.com/dotnet/maui/pull/1578

In the latest xamarin-macios bump, the dotnent/maui build started
failing because the `$(OutputPath)` of all the projects changed from:

    bin/Debug/net6.0-ios/
    bin/Debug/net6.0-maccatalyst/

To:

    bin/Debug/net6.0-ios/iossimulator-x64/
    bin/Debug/net6.0-maccatalyst/maccatalyst-x64/

Class library projects appear to have `$(RuntimeIdentifier)` set by
default. I don't think this is needed, because class libraries do not
need to be compiled as `--self-contained` apps.

On the Android side, we only set a default `$(RuntimeIdentifiers)` for
application projects:

7c5fab1332/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets (L49-L61)

I think the correct change here is to check:

    '$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true'

So Apple platforms only put a default `$(RuntimeIdentifier)` for
applications or extensions.

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2021-07-13 13:14:08 +02:00
Rolf Bjarne Kvinge 235a0f4942 [dotnet] Partially remove workaround for problems when setting the default RuntimeIdentifier. 2021-07-12 23:39:20 +02:00
Rolf Bjarne Kvinge 7179cac047 [dotnet] Set the default RuntimeIdentifier earlier. 2021-06-21 13:24:49 +02:00
Rolf Bjarne Kvinge 71a0659207
[dotnet] Tell .NET to not generate files we don't need. Fixes #9687. (#11693)
Tell .NET to not generate files we don't need:

* Dependency file (*.deps.json).
* Reference assemblies for executable projects.

Fixes https://github.com/xamarin/xamarin-macios/issues/9687.
2021-05-31 18:06:42 +02:00
Emanuel Fernandez Dell'Oca d5f1671184
[dotnet] Fix _DetectSdkLocations from Windows (#11451)
This task ends up setting as env variable the Xamarin Sdk root directory on the Mac, but when building from Windows it was setting the Windows path, so instead we need to override it with the proper value on macOS.

This should not change the original behavior when building from macOS.
2021-05-06 07:42:43 +02:00
Rolf Bjarne Kvinge 6225cac669
[msbuild/dotnet] Fix build logic when using .NET to not try to use nor require any version of installed Xamarin.iOS/Xamarin.Mac. Fixes #10827. (#11433)
* [dotnet] Ship the buildinfo file.

* [msbuild/dotnet] Fix build logic when using .NET to not try to use nor require any version of installed Xamarin.iOS/Xamarin.Mac. Fixes #10827.

We do this by setting the _XamarinSdkRoot variable in our .NET logic, which
our existing shared build logic reads, passes to the DetectSdkLocations task,
and then sets our override environment variable
(MD_MTOUCH_SDK_ROOT/XAMMAC_FRAMEWORK_PATH) to the install location, so that
existing code (which honors the override variable) continues to work as-is.

Fixes https://github.com/xamarin/xamarin-macios/issues/10827.
2021-05-04 21:36:48 -04:00
Peter Collins b88c3bb031
[build] Create Microsoft.iOS.Windows.Sdk workload pack (#11251)
Converts the Microsoft.iOS.Windows.Sdk NuGet package into a proper
[workload SDK pack][0].  The entry point for this pack has been changed,
and it is now imported through the `WorkloadManifest.targets` file
included in `Microsoft.NET.Workload.iOS`, rather than being imported
directly from `Microsoft.iOS.Sdk`.

Import ordering has otherwise changed slightly.  The following files are
now imported before the majority of the `Microsoft.iOS.Sdk` (and the 
majority of the .NET SDK targets):

 * Xamarin.iOS.Common.Before.props
 * Xamarin.iOS.Common.Before.targets

After this the majority of the .NET SDK targets will load, followed by
the `Microsoft.iOS.Sdk` targets. Finally, everything declared in the
`<AfterMicrosoftNETSdkTargets/>` hook loads, which consists of:

 * Microsoft.iOS.Windows.Sdk.targets
 * tools/msbuild/*

[0]: https://github.com/dotnet/designs/blob/main/accepted/2020/workloads/workload-manifest.md#sdk-packs

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2021-04-27 07:44:51 +02:00
Peter Collins 7a5c28f6cc
[msbuild] Rename $(_UsingXamarinSdk) to $(UsingAppleNETSdk) (#11270)
The `$(_UsingXamarinSdk)` property has been renamed to help improve
external usability.  This change increases parity with the Android SDK,
which currently defines `$(UsingAndroidNETSdk)` for internal and
external use.
2021-04-21 21:32:33 -04:00
Jonathan Peppers 5e18eae0ca
[dotnet] suppress IL2026 linker warning (#11043)
We started using `$(SuppressTrimAnalysisWarnings)` by default, because
ILLink started emitting warnings by default in .NET 6 Preview 3.

7bf3e8d8 fixed *most* of these warnings except for `IL2026`:

16aedd6e72/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets (L52-L57)

I get around 20 instances of this warning when building dotnet/maui.

`IL2026` occurs because this logic is evaluated much earlier than the
`PrepareForILLink` MSBuild target:

16aedd6e72/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets (L202)

The MSBuild evaluation order right now is:

* Sdk/Sdk.props
* Microsoft.[platform].Sdk.props
* Xamarin.Shared.Sdk.props
* Microsoft.NET.ILLink.targets
* Microsoft.[platform].Sdk.targets
* Xamarin.Shared.Sdk.targets

We need to set `$(SuppressTrimAnalysisWarnings)` earlier in
`Xamarin.Shared.Sdk.props` to solve the issue here.

On the Android side I got lucky, and it worked first try without
thinking too much. We import a `*.DefaultProperties.targets` before
`Microsoft.NET.ILLink.targets`, and that is why it worked.
2021-03-31 09:07:02 -05:00
Rolf Bjarne Kvinge f127e614c9
[dotnet] Templateify some build logic. (#10618)
* [dotnet-linker] Templateify the install logic.

* [builds] Templateify the Versions.plist install logic.

* [dotnet] Create a per-platform Versions.props file with only the values applicable to that platform.

Also move the definition of the default TargetPlatformVersion to Make.versions, where we have other versions.

* [dotnet] Templateify some build code.
2021-02-11 20:17:12 +01:00
Rolf Bjarne Kvinge 8f0ca7508a [dotnet] Reorder imports to account for that our targets are imported earlier in the build process.
In the latest .NET 6, our Workloads.targets is imported earlier in the build. This
requires a few changes, because we still need to run most of our logic later in the
process, which we do by adding targets files we want imported later to the AfterMicrosoftNETSdkTargets
property.

What we're loading as soon as possible:

* Our version information (Xamarin.Shared.Sdk.Versions.targets)
* The supported OS versions (Microsoft.<platform>.Sdk.SupportedTargetPlatforms.targets)
* The default OS version (Xamarin.Shared.Sdk.TargetFrameworkInference.targets).

This is all information that the .NET build require early on.

Changes:

* Rename all files that are loaded early to *.props.
* Updated documentations to reflect these changes.
* Remove Microsoft.<platform>.TargetFrameworkInference.targets, these files aren't
  used and don't contain anything useful.
* Move the logic to calculate _ComputedTargetFrameworkMoniker has been delayed
  to later, because it needs TargetFrameworkMoniker set.
2020-11-10 11:41:30 +01:00
Rolf Bjarne Kvinge e43688a60b [dotnet] Merge Xamarin.Shared.Sdk.props into Xamarin.Shared.Sdk.targets. 2020-10-16 14:27:57 +02:00
Rolf Bjarne Kvinge 613ebb1dce [dotnet] Don't import Microsoft.NET.Sdk's Sdk.props/Sdk.targets.
We're not in control of this anymore.
2020-10-16 14:27:42 +02:00
Rolf Bjarne Kvinge d2788511b6
[dotnet] Use net5.0-[ios|tvos|watchos|macos] TargetFrameworks. (#9532)
* [dotnet] Set TargetPlatformSupported when the right TargetPlatformIdentifier is used.

* [dotnet] Generate a list of valid OS versions for each platform, and add it to the SupportedTargetPlatform item group.

The generated files: https://gist.github.com/rolfbjarne/765c4e4b38b1b017380c9378d9666317

* [dotnet] Define and set the default platform version if it's not set in the TargetFramework variable.

* [dotnet] Switch to using the new-style TargetFramework values.

This includes bumping spouliot/Touch.Unit to get new-style TargetFramework values for Touch.Client.

* spouliot/Touch.Unit@89afaf7 [Touch.Client] Use the right TargetFrameworks for watchOS and macOS as well. (#92)
* spouliot/Touch.Unit@fd0e576 [Touch.Client] Use the right TargetFrameworks. (#91)
* spouliot/Touch.Unit@40f47db [Touch.Client] Add a macOS and watchOS version for .NET. (#90)
* spouliot/Touch.Unit@1d4b8c0 Add .gitignore for NuGet.config and global.json. (#89)
* spouliot/Touch.Unit@49441f3 Call `mlaunch` instead of `mtouch` (#88)
* spouliot/Touch.Unit@b157cf4 Fix a few markdown issues found by markdownlint. (#87)

Diff: d7f55a6167..89afaf7e05

* [dotnet] Document the script that generates the lists of the target platform versions a little bit better.

* [dotnet] Make the [Platform]SupportedTargetPlatform variables public.

This matches how Android and Windows do it:

* https://github.com/xamarin/xamarin-android/pull/5007
* 18ee4eac8b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.WindowsSupportedTargetPlatforms.props

* [xharness] Update the TargetFramework value when creating project variations.
2020-08-31 09:27:19 +02:00
Rolf Bjarne Kvinge cf1f8af55a [msbuild] Don't inject our existing build logic into the *DependsOn variables when building using net5. 2020-05-26 14:49:31 +02:00
Rolf Bjarne Kvinge 0aea29cf0a [dotnet] Import the existing targets files. 2020-05-26 14:49:31 +02:00