Skip to content

Add CI for example projects#37

Merged
marcprux merged 40 commits into
swiftlang:mainfrom
marcprux:ci
May 8, 2026
Merged

Add CI for example projects#37
marcprux merged 40 commits into
swiftlang:mainfrom
marcprux:ci

Conversation

@marcprux
Copy link
Copy Markdown
Contributor

@marcprux marcprux commented Apr 9, 2026

This PR adds GitHub CI that will install the Swift SDK for Android and build each of the individual projects.

It also lightly modifies the gradle build files to enable overriding the Swift version it uses with SWIFT_VERSION and SWIFT_ANDROID_SDK_VERSION environment variables in order to enable building with versions other than the presumed 6.3 (including nightly toolchains, although those aren't currently enabled in the CI).

Note that we manually install everything in accordance with the Getting Started guide rather than leaning on the Android SDK support in github-workflows (swiftlang/github-workflows#172) because it is closer to the experience that an end-user would have, plus this CI supports building on macOS as well as Linux. Also, the github-workflows is designed to build-and-test a normal Swift package against a given SDK, whereas this workflow only builds the Swift package indirectly via the gradle builds.

A successful run can be seen at https://github.com/marcprux/swift-android-examples/actions/runs/24172716605

Closes #34

@marcprux
Copy link
Copy Markdown
Contributor Author

marcprux commented Apr 9, 2026

Note that this PR would require that actions be enabled for this repository.

Copy link
Copy Markdown

@digitalby digitalby left a comment

Choose a reason for hiding this comment

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

Nice PR, the install flow mirrors Getting Started nicely and the version-override hooks are clean. Dropping a pile of nits below, nothing blocking, feel free to ignore any that feel unhelpful.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml Outdated
Comment thread swift-android.gradle.kts
Comment thread hello-swift-java/hashing-lib/build.gradle
@marcprux
Copy link
Copy Markdown
Contributor Author

@shahmishal Could you turn on actions in the settings for this repo so I can iterate on testing the GitHub workflows?

@marcprux marcprux requested a review from shahmishal April 30, 2026 16:07
@marcprux
Copy link
Copy Markdown
Contributor Author

marcprux commented May 6, 2026

Would anyone from @swiftlang/github-workflows-contributors like to give this a quick review pass? If not, I'll merge in the next couple of days.

A representative successful run can be found at https://github.com/marcprux/swift-android-examples/actions/runs/25459566238

Comment thread .github/workflows/ci.yml Outdated
@marcprux marcprux mentioned this pull request May 7, 2026
Comment thread .github/workflows/ci.yml Outdated
strategy:
fail-fast: false
matrix:
swift_version: ["6.3", "nightly-main"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nightly-6.3?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would expand the matrix from 2⁴ to 2⁵ entries, which is already pushing the limits given that GH actions can only have 5 concurrent macOS runners for public repos (and so it is already taking a very long time to run the CI).

I'm not entirely opposed to adding it if you think that it is valuable, but I personally think that if the projects build with 27 and 30, then we are probably also good for the in-betweens.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your math is off: you currently have 8 jobs running on macOS, this would add 4 more, ie 12.

Adding another NDK version on top of this would get us up to 18 jobs. Considering how rarely we update this repo, this would really only be run once daily, so I think the extra coverage is worth it.

Once the LTS NDK 30 releases, we can drop all the older unsupported NDKs, and the nightly 6.3 snapshots too once they stop around the same time, in a month or two.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I've added nightly-6.3 and ndk29 (since 28 is no longer listed at https://developer.android.com/ndk/downloads/) to the mix.

Comment thread .github/workflows/ci.yml Outdated
fail-fast: false
matrix:
swift_version: ["6.3", "nightly-main"]
ndk_version: ['r27d', 'r30-beta1']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

28c would be good too, until 30 is out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as #37 (comment)

workingDir = layout.projectDirectory
executable(getSwiftlyPath())
args("run", "swift", "build", "+${swiftVersion}", "--swift-sdk", info.triple)
args("run", "swift", "build", "+${swiftVersion}", "--swift-sdk", info.triple, "--build-system", "native")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should work with the default build system now, not working?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, not yet. The build works fine, but the .so files are being output in a new location that we will need to accommodate. We are working it out, the change in the build folder layout is going to require some more logic that I'll tackle in a future PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good 👍

Copy link
Copy Markdown
Member

@finagolfin finagolfin left a comment

Choose a reason for hiding this comment

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

Thanks for setting this up, Marc, just some suggestions for better test coverage.

It's too bad you had to do all this from scratch and couldn't just use the official workflows: what do you think about upstreaming all this back there, at least as an apk build option?

@marcprux
Copy link
Copy Markdown
Contributor Author

marcprux commented May 8, 2026

It's too bad you had to do all this from scratch and couldn't just use the official workflows: what do you think about upstreaming all this back there, at least as an apk build option?

We don't really have a consensus about how Swift code should be tested in the form of a packaged .apk yet. These examples (contributed by various people) all have their own individual packaging setups; they are all app-oriented, and they all bring gradle baggage along with them, which I think we'd like to avoid for lightweight testing of pure swift packages in github-workflows.

I do think that we will eventually want to converge on the right way to test swift on Android, both inside and outside of a packaged .apk (which is especially relevant for swift-java, which cannot function outside of an .apk on Android). @dschaefer2 might take note for future work in this direction.

@marcprux marcprux merged commit a698df1 into swiftlang:main May 8, 2026
@marcprux
Copy link
Copy Markdown
Contributor Author

marcprux commented May 8, 2026

I just merged and I notice that all 18 macOS jobs are running simultaneously and do not seem to be subject to the usual 5 concurrent job limit for free OSS action runners. @shahmishal, is this costing real money? If so, perhaps we can reconsider the matrix and pare them back a bit.

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.

Add CI

4 participants