Skip to content

Apply toolset's debugger property in swift run #8252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2025
Merged

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Jan 27, 2025

Motivation:

Per SE-0378 toolsets can specify an optional debugger property, which so far had no effect. We should respect this property in swift run invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, QEMU or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a Wasm binary.

Modifications:

Updated SwiftRunCommand to check for the debugger property in toolsets or Swift SDKs when such are specified. Its value is then used to launch a freshly built binary.

Result:

Cross-compiled binaries can be directly launched and debugged with a swift run invocation.

Per [SE-0378 toolsets can specify an optional `debugger` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift run` invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, qemu or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a WASI binary.
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov changed the title Apply toolsets debugger property in swift-run Apply toolset's debugger property in swift-run Jan 27, 2025
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

@@ -40,6 +40,25 @@ final class RunCommandTests: CommandsTestCase {
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout)
}

// echo.sh script from the toolset won't work on Windows
#if !os(Windows)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: can we create an equivalent target that will run on Windows to ensure the functions work on that host platform?

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I don't have experience with Windows and don't have means to test on Windows. IIRC the test suite doesn't even run on the Windows CI job. I'd prefer to do this in a separate PR, when we have established means of running these Windows-specific tests on CI in the first place.

@MaxDesiatov MaxDesiatov requested a review from bkhouri January 28, 2025 09:07
@MaxDesiatov MaxDesiatov changed the title Apply toolset's debugger property in swift-run Apply toolset's debugger property in swift run Jan 28, 2025
@MaxDesiatov MaxDesiatov requested a review from phausler January 28, 2025 16:49
@MaxDesiatov MaxDesiatov merged commit 88e2af7 into main Jan 28, 2025
5 checks passed
@MaxDesiatov MaxDesiatov deleted the maxd/toolset-debugger branch January 28, 2025 16:58
MaxDesiatov added a commit that referenced this pull request Jan 29, 2025
### Motivation:

Per [SE-0378 toolsets can specify an optional `debugger` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift run` invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, QEMU or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a Wasm binary.

### Modifications:

Updated `SwiftRunCommand` to check for the `debugger` property in toolsets or Swift SDKs when such are specified. Its value is then used to launch a freshly built binary.

### Result:

Cross-compiled binaries can be directly launched and debugged with a `swift run` invocation.
MaxDesiatov added a commit that referenced this pull request Feb 3, 2025
Cherry-pick of #8252, merged as
88e2af7.

**Explanation**: Per [SE-0378 toolsets can specify an optional `debugger` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift run` invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, QEMU or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a Wasm binary.
**Scope**: Only impacts `swift-run` when a toolset or a Swift SDK are selected.
**Risk**: Low, due to limited scope and automated testing.
**Testing**: Added a new test cause to the existing XCTest suite.
**Issue**: rdar://143814083
**Reviewer**: @dschaefer2
bripeticca pushed a commit to bripeticca/swift-package-manager that referenced this pull request Feb 28, 2025
### Motivation:

Per [SE-0378 toolsets can specify an optional `debugger` property](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md#toolsetjson-files), which so far had no effect. We should respect this property in `swift run` invocations when any toolsets or Swift SDKs are selected.

This allows running and debugging cross-compiled products in an environment other than the host, e.g. a container runtime when cross-compiled to Linux, QEMU or a firmware flasher and serial port setup script with Swift Embedded for microcontrollers, or in a Wasm runtime for a Wasm binary.

### Modifications:

Updated `SwiftRunCommand` to check for the `debugger` property in toolsets or Swift SDKs when such are specified. Its value is then used to launch a freshly built binary.

### Result:

Cross-compiled binaries can be directly launched and debugged with a `swift run` invocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-compilation swift run Changes impacting `swift run` subcommand
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants