Skip to content

Conversation

@madsodgaard
Copy link

@madsodgaard madsodgaard commented Dec 6, 2025

Adds shims for the posix_spawnattr added in #2928 for Android 27 and below.

@ktoso
Copy link

ktoso commented Dec 7, 2025

@swift-ci please smoke test

Copy link
Contributor

@parkera parkera left a comment

Choose a reason for hiding this comment

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

This is probably fine, but should we be looking at improving swift-subprocess instead, or in addition to this?

@madsodgaard
Copy link
Author

@parkera This PR is mostly motivated by being able to lower the recent Android SDK to API 24 instead of 28, which would currently fail to compile, because of these missing symbols on API 27 and below.

I don't think people are going to use Process or subprocess a lot on Android, but at least this is better than removing it by "!os(Android)"

You can read more about this discussion here: https://forums.swift.org/t/android-api-minimum-for-the-swift-sdk-for-android/82874

@ktoso
Copy link

ktoso commented Dec 22, 2025

@swift-ci please smoke test

1 similar comment
@ktoso
Copy link

ktoso commented Dec 22, 2025

@swift-ci please smoke test

@madsodgaard madsodgaard marked this pull request as draft December 22, 2025 09:54
@madsodgaard
Copy link
Author

@ktoso I am just trying to get building in my fork with Github Actions and the Android SDK, so no need to run the smoke tests. But thanks!

@ktoso
Copy link

ktoso commented Dec 22, 2025

I see lol, I'll stop then :-)

@madsodgaard
Copy link
Author

So after a lot of debugging, I also found that the existing polyfills did not work on API 27 devices and below.

After fixing those, I built a API 24 SDK with this PR, and the below code now correctly runs with no errors on both a API 24 device and API 28

@main
struct MyExecutable {
    static func main() {
        let executablePath = "/system/bin/ls"
        let arguments = ["-l"]

        let process = Process()
        process.executableURL = URL(fileURLWithPath: executablePath)
        process.arguments = arguments

        let pipe = Pipe()
        process.standardOutput = pipe
        process.standardError = pipe

        do {
            try process.run()

            let data = pipe.fileHandleForReading.readDataToEndOfFile()

            if let output = String(data: data, encoding: .utf8) {
                print("--- Subprocess Output ---")
                print(output)
                print("-------------------------")
            }

            process.waitUntilExit()
            print("Process exited with status: \(process.terminationStatus)")
        } catch {
            print("Failed to spawn process: \(error)")
        }
    }
}

@madsodgaard madsodgaard marked this pull request as ready for review December 23, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants