Implement WinRT / C# projection for the WSLC SDK API surface#40360
Draft
florelis wants to merge 12 commits into
Draft
Implement WinRT / C# projection for the WSLC SDK API surface#40360florelis wants to merge 12 commits into
florelis wants to merge 12 commits into
Conversation
Member
|
The |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
6 tasks
Comment on lines
+165
to
+169
| auto context = ProgressCallbackHelper<winrt::Microsoft::WSL::Containers::ImageProgress>{co_await winrt::get_progress_token()}; | ||
|
|
||
| auto pushStruct = GetStructPointer(options); | ||
| pushStruct->progressCallback = ImageProgressCallback; | ||
| pushStruct->progressCallbackContext = &context; |
Comment on lines
+132
to
+135
| m_settings = nullptr; | ||
|
|
||
| return *this; | ||
| } |
| // This takes ownership without increasing the ref count to account for the AddRef in ApplyCallbacksToSettings(). | ||
| process.attach(static_cast<Process*>(context)); | ||
|
|
||
| process->m_exitedEvent(*process, exitCode); |
Comment on lines
+29
to
+32
| if (options != InputStreamOptions::None) | ||
| { | ||
| winrt::throw_hresult(ERROR_NOT_SUPPORTED); | ||
| } |
Comment on lines
+99
to
+103
| if (m_cmdLine.Size() > 0) | ||
| { | ||
| auto argc = m_cmdLine.Size(); | ||
| m_cmdLineStrings = StringArray{argc}; | ||
| for (auto const& arg : m_cmdLine) |
Comment on lines
+347
to
+351
| // Positive: load a saved image tar and verify the image can be run | ||
| { | ||
| // Remote the image if it already exists | ||
| IGNORE_ERRORS(m_defaultSession.DeleteImage(L"hello-world:latest")); | ||
|
|
Comment on lines
+282
to
+287
|
|
||
| // Negative: Must throw if used used before Start() | ||
| { | ||
| auto session = WSLCSDK::Session::Create(settings); | ||
| VERIFY_THROWS_HR(std::ignore = session.Images(), E_ILLEGAL_METHOD_CALL); | ||
| } |
Comment on lines
+1496
to
+1503
| auto container = m_defaultSession.CreateContainer(containerSettings); | ||
| container.Start(WSLCSDK::ContainerStartFlags::Attach); | ||
|
|
||
| // The init process has now exited. Attempting to exec on a stopped container must fail. | ||
| auto execSettings = WSLCSDK::ProcessSettings(); | ||
| execSettings.CmdLine(winrt::single_threaded_vector<winrt::hstring>({L"/bin/echo", L"should-fail"})); | ||
|
|
||
| VERIFY_THROWS_HR(container.CreateProcess(execSettings).Start(), static_cast<HRESULT>(WSLC_E_CONTAINER_NOT_RUNNING)); |
Comment on lines
+1488
to
+1492
| WSLC_TEST_METHOD(StopContainerWithInvalidSignal) | ||
| { | ||
| auto procSettings = WSLCSDK::ProcessSettings(); | ||
| procSettings.CmdLine(winrt::single_threaded_vector<winrt::hstring>({L"/bin/sleep", L"10"})); | ||
|
|
| bool callbacksApplied = false; | ||
| if (m_initProcess) | ||
| { | ||
| callbacksApplied = m_initProcess->ApplyCallbacksToSettings(GetStructPointer(GetImplementation(m_settings)->InitProcess())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
This PR the C++/WinRT wrapper for the WSLC SDK, which is then projected to C#.
PR Checklist
Detailed Description of the Pull Request / Additional comments
This builds on top of #40121 and #40212. The relevant changes for this are only the
.hand.cppfiles.The implementation for all types follows a similar pattern, but there are some differences between types that are meant to be constructed by the consumer (e.g.,
SessionSettings) and types that can only be obtained by a function call (e.g.,Session).For types constructed by the consumer:
implementationtypes that don't have one in the public APIhstringbut as a nativestd::(w)stringto directly back any string pointers passed to the C API.IReference<>(projected to C# as a nullable type) andnullptrto represent the default.ToStruct()orToStructPointer()(depending on usage) to get and retrieve the equivalentstructfor the C API. This nativestructis cached so that we only create it once. To avoid dealing with updating the native object if a property is changed, I blocked all setters if the nativestructwas already created.For the types that are only constructed by the API:
For the few properties that are lists (e.g.,
ContainerPortMapping), I created two backing vectors. One is for the WinRT objects that are used when interacting with the consumer, and the other is for backing the pointers passed to the C API.For callbacks, we use events that are configured before calling
Start()on the object, and we pass the C API a callback that invokes the event handler.The tests are more or less a direct translation of the tests for the C API. The tests show some issues that I have not resolved yet.
Validation Steps Performed