Skip to content

Commit 0da72c7

Browse files
committed
Merge remote-tracking branch 'origin/main' into dev/rolf/assembly-preparer
2 parents 2070180 + 97d260a commit 0da72c7

File tree

3,719 files changed

+397601
-284850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,719 files changed

+397601
-284850
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: branch_classification
2+
resource: repository
3+
disabled: false
4+
where:
5+
configuration:
6+
branchClassificationSettings:
7+
defaultClassification: nonproduction
8+
ruleset:
9+
- name: prod-branches
10+
branchNames:
11+
- main
12+
- release-test/*
13+
- release/*
14+
- net7.0
15+
- net8.0
16+
- net9.0
17+
- net10.0
18+
- xcode*
19+
classification: production

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
]
1010
},
1111
"dotnet-ilrepack": {
12-
"version": "1.0.0",
12+
"version": "2.0.43",
1313
"commands": [
1414
"ilrepack"
1515
]

.github/copilot-instructions.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
# Instructions for AIs
2+
3+
This repository contains .NET for iOS, Mac Catalyst, macOS, and tvOS.
4+
5+
This is the main branch targeting .NET 9.
6+
7+
## Comment Handling
8+
9+
Ignore comments from the user 'vs-mobiletools-engineering-service2' when processing issues and pull requests.
10+
11+
## Repository Overview
12+
13+
This repository provides C# bindings and tooling for Apple platforms:
14+
- **.NET for iOS**: iPhone and iPad applications
15+
- **.NET for macOS**: Native Mac applications
16+
- **.NET for tvOS**: Apple TV applications
17+
- **.NET for Mac Catalyst**: iOS apps running on macOS
18+
19+
### Key Directories
20+
21+
- `src/` - Apple API bindings (Foundation, UIKit, AppKit, etc.)
22+
- `tools/` - Development tools (mtouch, mmp, linker, bgen)
23+
- `tests/` - Test suites (unit, introspection, extrospection)
24+
- `msbuild/` - MSBuild tasks and targets
25+
- `docs/` - Documentation and guides
26+
- `runtime/` - Runtime components and native code
27+
28+
## Build System
29+
30+
This project uses a Make-based build system. Key commands:
31+
32+
- `make all` and `make install` - Both required to get a complete build
33+
- `make world` - Reset, build, and install everything
34+
- `make check-system` - Verify system dependencies
35+
- `make show-versions` - Display version information
36+
37+
### Platform-Specific Building
38+
39+
The build system supports multiple platforms simultaneously:
40+
- iOS: iPhone and iPad (device and simulator)
41+
- macOS: Native Mac applications
42+
- tvOS: Apple TV applications
43+
- Mac Catalyst: iOS apps adapted for macOS
44+
45+
The `configure` script is used to select which platforms to build. This script must be run before `make`.
46+
47+
## Binding System
48+
49+
### bgen (Binding Generator)
50+
51+
The `src/bgen/` tool generates C# bindings from Objective-C APIs:
52+
- Processes binding definition files (`*.cs`) with binding attributes
53+
- Generates P/Invoke declarations and managed wrappers
54+
- Handles memory management and type marshaling
55+
56+
### Common Binding Patterns
57+
58+
```csharp
59+
// Platform availability attributes
60+
[NoTV, NoMac, iOS (14, 0)]
61+
[Native]
62+
public enum SomeEnum : long {
63+
Value1 = 0,
64+
Value2,
65+
}
66+
67+
// Basic class binding
68+
[BaseType (typeof (NSObject))]
69+
interface SomeClass {
70+
[Export ("someMethod:")]
71+
void SomeMethod (string parameter);
72+
73+
[Export ("someProperty")]
74+
string SomeProperty { get; set; }
75+
}
76+
```
77+
78+
### Platform Attributes
79+
80+
Use these attributes to specify platform availability:
81+
- `[iOS (version)]` - Available on iOS from specified version
82+
- `[Mac (version)]` - Available on macOS from specified version
83+
- `[TV (version)]` - Available on tvOS from specified version
84+
- `[MacCatalyst (version)]` - Available on Mac Catalyst from specified version
85+
- `[NoiOS]`, `[NoMac]`, `[NoTV]`, `[NoMacCatalyst]` - Not available on specified platforms
86+
87+
## Testing Strategy
88+
89+
### Test Types
90+
91+
1. **Unit Tests**: NUnit-based regression tests for specific functionality
92+
2. **Introspection Tests**: Runtime validation comparing managed and native APIs
93+
3. **Extrospection Tests**: Validation against external sources (headers, rules)
94+
95+
### Test Execution
96+
97+
- Tests run on simulators and physical devices
98+
- Different linking modes: "Don't link", "Link SDK only", "Link all"
99+
- Platform-specific test projects generated by xharness tool
100+
101+
### Running Tests
102+
103+
It's typically `make run-tests` in the directory with the test project.
104+
105+
## Apple Platform Integration
106+
107+
### Xcode Requirements
108+
109+
- Latest Xcode version typically required for latest platform features
110+
- Xcode Command Line Tools must be installed
111+
- Multiple Xcode versions may be needed for different platform support
112+
113+
### Framework Dependencies
114+
115+
Apple frameworks are referenced using:
116+
```csharp
117+
[BaseType (typeof (NSObject))]
118+
interface SomeClass {
119+
// Framework linking handled automatically via binding definitions
120+
}
121+
```
122+
123+
### Memory Management
124+
125+
- Proper `[Export]` declarations for Objective-C methods
126+
- `using` statements for `IDisposable` resources
127+
128+
## MSBuild Integration
129+
130+
### Custom MSBuild Tasks
131+
132+
Located in `msbuild/` directory:
133+
- `Xamarin.MacDev.Tasks` - Shared Apple development tasks
134+
135+
### Project Templates
136+
137+
Common project structure for Apple platform apps:
138+
```xml
139+
<Project Sdk="Microsoft.NET.Sdk">
140+
<PropertyGroup>
141+
<TargetFramework>net9.0-ios</TargetFramework>
142+
<!-- Platform-specific properties -->
143+
</PropertyGroup>
144+
</Project>
145+
```
146+
147+
## Development Workflow
148+
149+
### Making Changes
150+
151+
1. Modify bindings in `src/` directory
152+
2. Run `make` to rebuild affected components
153+
3. Test changes using appropriate test suite
154+
4. Verify on both simulator and device when possible
155+
156+
### Code Style
157+
158+
- Follow existing patterns in binding definitions
159+
- Use consistent naming conventions matching Apple's APIs
160+
- Add appropriate platform availability attributes
161+
- Use the code style as defined in .editorconfig
162+
163+
## Nullable Reference Types
164+
165+
When opting C# code into nullable reference types:
166+
167+
Only make the following changes when asked to do so.
168+
169+
* Add `#nullable enable` at the top of the file.
170+
171+
* Don't *ever* use `!` to handle `null`!
172+
173+
* Declare variables non-nullable, and check for `null` at entry points.
174+
175+
* Use `throw new ArgumentNullException (nameof (parameter))` in `netstandard2.0` projects.
176+
177+
* Use `ArgumentNullException.ThrowIfNull (parameter)` in iOS projects that will be .NET 9+.
178+
179+
* `[Required]` properties in MSBuild task classes should always be non-nullable with a default value.
180+
181+
* Non-`[Required]` properties should be nullable and have null-checks in C# code using them.
182+
183+
* For MSBuild task properties like:
184+
185+
```csharp
186+
public string NonRequiredProperty { get; set; }
187+
public ITaskItem [] NonRequiredItemGroup { get; set; }
188+
189+
[Output]
190+
public string OutputProperty { get; set; }
191+
[Output]
192+
public ITaskItem [] OutputItemGroup { get; set; }
193+
194+
[Required]
195+
public string RequiredProperty { get; set; }
196+
[Required]
197+
public ITaskItem [] RequiredItemGroup { get; set; }
198+
```
199+
200+
Fix them such as:
201+
202+
```csharp
203+
public string? NonRequiredProperty { get; set; }
204+
public ITaskItem []? NonRequiredItemGroup { get; set; }
205+
206+
[Output]
207+
public string? OutputProperty { get; set; }
208+
[Output]
209+
public ITaskItem []? OutputItemGroup { get; set; }
210+
211+
[Required]
212+
public string RequiredProperty { get; set; } = "";
213+
[Required]
214+
public ITaskItem [] RequiredItemGroup { get; set; } = [];
215+
```
216+
217+
If you see a `string.IsNullOrEmpty()` check, don't change it.
218+
219+
## Common Objective-C to C# Patterns
220+
221+
### Method Binding
222+
223+
```csharp
224+
// Objective-C: - (void)setTitle:(NSString *)title forState:(UIControlState)state;
225+
[Export ("setTitle:forState:")]
226+
void SetTitle ([NullAllowed] string title, UIControlState state);
227+
228+
// Objective-C: - (NSString *)titleForState:(UIControlState)state;
229+
[Export ("titleForState:")]
230+
[return: NullAllowed]
231+
string GetTitle (UIControlState state);
232+
```
233+
234+
### Property Binding
235+
236+
```csharp
237+
// Objective-C: @property (nonatomic, copy) NSString *title;
238+
[Export ("title")]
239+
string Title { get; set; }
240+
241+
// Objective-C: @property (nonatomic, readonly) BOOL isEnabled;
242+
[Export ("isEnabled")]
243+
bool IsEnabled { get; }
244+
```
245+
246+
### Delegate/Protocol Binding
247+
248+
```csharp
249+
[BaseType (typeof (NSObject))]
250+
[Model]
251+
[Protocol]
252+
interface SomeDelegate {
253+
[Export ("someMethod:")]
254+
void SomeMethod (SomeClass sender);
255+
}
256+
```
257+
258+
### Error Handling
259+
260+
```csharp
261+
// Methods that take NSError**
262+
[Export ("doSomething:")]
263+
bool DoSomething (out NSError error);
264+
265+
// Async methods
266+
[Export ("doSomethingWithCompletion:")]
267+
[Async]
268+
void DoSomething (Action<bool, NSError> completion);
269+
```
270+
271+
## Release and Versioning
272+
273+
### Branch Strategy
274+
275+
- `main` - .NET 9 development
276+
- `net10.0` - .NET 10 development
277+
- `release/` branches for specific releases
278+
- Platform-specific branches for Xcode updates
279+
280+
### Version Management
281+
282+
- NuGet versions managed in `Make.versions`
283+
- Platform API versions track Apple SDK versions
284+
- Commit distance used for pre-release versioning
285+
286+
## Troubleshooting
287+
288+
### Common Issues
289+
290+
1. **Build Failures**: Check `make check-system` for missing dependencies
291+
2. **Binding Errors**: Review bgen output for binding definition issues
292+
3. **Runtime Errors**: Use introspection tests to validate binding correctness
293+
4. **Linking Issues**: Test with different linker modes
294+
295+
### Debugging
296+
297+
- Use simulator for initial testing
298+
- Physical device testing for platform-specific features
299+
- Enable verbose logging with `V=1 make` for detailed build output
300+
301+
## Formatting
302+
303+
C# code uses tabs (not spaces) and the Mono code-formatting style defined in `.editorconfig`
304+
305+
* Your mission is to make diffs as absolutely as small as possible, preserving existing code formatting.
306+
307+
* If you encounter additional spaces or formatting within existing code blocks, LEAVE THEM AS-IS.
308+
309+
* If you encounter code comments, LEAVE THEM AS-IS.
310+
311+
* Place a space prior to any parentheses `(` or `[`
312+
313+
* Use `""` for empty string and *not* `string.Empty`
314+
315+
* Use `[]` for empty arrays and *not* `Array.Empty<T>()`
316+
317+
Examples of properly formatted code:
318+
319+
```csharp
320+
Foo ();
321+
Bar (1, 2, "test");
322+
myarray [0] = 1;
323+
324+
if (someValue) {
325+
// Code here
326+
}
327+
328+
try {
329+
// Code here
330+
} catch (Exception e) {
331+
// Code here
332+
}
333+
```

.github/workflows/autoformat2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
githubToken: ${{ secrets.GITHUB_TOKEN }}
2525
git_user_email: '[email protected]'
2626
git_user_name: 'GitHub Actions Autoformatter'
27-
commentContents: '# :warning: Your code has been reformatted. :warning:\n\nIf this is not desired, add the `actions-disable-autoformat` label, and revert the reformatting commit.\n\nIf files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).'
27+
commentOnPullRequest: false

.github/workflows/bump-global-json.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
1111
permissions:
1212
contents: write
13-
if: contains(github.event.pull_request.title, 'Update dependencies from dotnet/sdk') && github.actor == 'dotnet-maestro[bot]'
13+
if: contains(github.event.pull_request.title, 'Update dependencies from dotnet/') && github.actor == 'dotnet-maestro[bot]'
1414
steps:
1515
- name: 'Checkout repo'
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717
with:
1818
fetch-depth: 0
1919
repository: ${{ github.event.pull_request.head.repo.full_name }}

.github/workflows/localization-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
name: '[Localization PR to main]'
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919
name: checkout
2020

2121
- uses: repo-sync/pull-request@v2

0 commit comments

Comments
 (0)