The original attempt at a fix for this was too aggressive:
https://github.com/microsoft/cppwinrt/pull/1381/files
This fix is targeted specifically at removing references to stale winmd files that have yet to be copied from referenced projects (e.g., from a runtime component to an app).
* Merged PR 9973274: Auto-generated baselines by 1ES Pipeline Templates
This pull request includes baselines **with an expiration date of 180 days from now** automatically generated for your 1ES PT-based pipelines. Complete this pull request as soon as possible to make sure that your pipeline becomes compliant. Longer delays in completing this PR can trigger additional emails or S360 alerts in the future.
1ES PT Auto-baselining feature helps capture existing violations in your repo and ensures to break your pipeline only for newly introduced SDL violations after baselining. Running SDL tools in break mode is required for your pipeline to be compliant. Go to https://aka.ms/1espt-autobaselining for more details.
* Merged PR 9973274: Auto-generated baselines by 1ES Pipeline Templates
This pull request includes baselines **with an expiration date of 180 days from now** automatically generated for your 1ES PT-based pipelines. Complete this pull request as soon as possible to make sure that your pipeline becomes compliant. Longer delays in completing this PR can trigger additional emails or S360 alerts in the future.
1ES PT Auto-baselining feature helps capture existing violations in your repo and ensures to break your pipeline only for newly introduced SDL violations after baselining. Running SDL tools in break mode is required for your pipeline to be compliant. Go to https://aka.ms/1espt-autobaselining for more details.
---------
Co-authored-by: MerlinBot <MerlinBot>
Incremental builds fail when a referenced project's winmd has been updated. This is because the CppWinRT reference projection is properly using project's referenced winmds as inputs. But the MarkupCompilePass2 target is using XamlReferencesToCompile, which has been set here to use previously copied output files.
We have found that a very common pattern for event handlers is
to capture a weak reference into a lambda, and in the event handler,
try to upgrade the weak reference to a strong one, and if so, do some work:
```cpp
widget.Closed([weak = get_weak(), data](auto&& sender, auto&& args)
{
if (auto strongThis = weak.get())
{
strongThis->do_all_the_things(data);
}
});
```
This commit extends the existing delegate constructors to permit a
`winrt::weak_ref` + lambda (or `std::weak_ptr` + lambda), which
simplifies the above to
```cpp
widget.Closed({ get_weak(), [this, data](auto&& sender, auto&& args)
{
do_all_the_things(data);
} });
```
## Implementation notes
A lambda and pointer to member function are hard to distinguish
in a template parameter list. In theory, we could use SFINAE or
partial specialization, but a simpler solution is to distinguish
the two inside the body of the constructor, via
`std::is_member_function_pointer_v`.
The `com_ptr` and `shared_ptr` variants of the test were
unified, since I found myself editing two nearly identical tests.
Fixes#1371
Co-authored-by: Jon Wiswall <jonwis@microsoft.com>
`resume_agile` exposes the ability to save the `await_adapter`
in a variable. This was not possible without `resume_agile` because
the `await_adapter` had previously been available only via
`operator co_await`, which means that it is created only in
response to an immediate attempt to `co_await` it, so we knew
that it would be consumed before its argument (possibly a temporary)
was destructed.
`resume_agile` returns the `await_adapter`, and we expect people
to await it immediately, but it's possible that they decide to
save it in a variable and await it later. In that case, we have
to record the `Async` as a value instead of a reference. We forward
the `resume_agile` argument into the `Async` so that it moves
if given an rvalue reference, or copies if given an lvalue reference.
This ensure that the common case where somebody does
`co_await resume_agile(DoSomething())`, we do not incur any additional
AddRefs or Releases.
Now that it's possible to `co_await` the `await_adapter` twice,
we have to worry about `await_suspend` being called twice. It had
previously assumed that `suspending` was true (since that's how it
was constructed), but that is no longer valid in the `resume_agile`
case if somebody tries to await the `resume_agile` twice. So we have
to force it to `true`. (Now, the second await will fail with
"illegal delegate assignment", but our failure to set `suspending`
to `true` led to double-resumption, which is super-bad.)
* Enable faster dev cycle in Visual Studio
* Oops, remove one more run
* Fix linux build temporarily - see also #1341
---------
Co-authored-by: Jon Wiswall <jonwis@ntdev.microsoft.com>
* Add SDKReference-sourced WinMDs when building
* Add solution items so they're more easily edited
* Update development guidance slightly
* First attempt at template folding
* Make packages easier to build, remove warning about unreferenced static
* Lift delegate creation out for better folding
* More folding of events
* Another delegate folded
* PR feedback
* Speculative improvement for QueryInterface
* PR feedback
---------
Co-authored-by: Jon Wiswall <jdwiswall@hotmail.com>
Co-authored-by: Kenny Kerr <kekerr@microsoft.com>
Co-authored-by: Jon Wiswall <jonwis@ntdev.microsoft.com>