Skip to content

Proposal for scarthgap branch (Swift 6.1.2) #12

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 41 commits into from
Jul 1, 2025

Conversation

lhoward
Copy link
Collaborator

@lhoward lhoward commented Jun 22, 2025

Rework of #9 to separate changes into distinct commits.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

cc @xtremekforever @compenguy

I can separate out further if required, hopefully this makes it easier to cherry-pick / learn about Yocto etc

@lhoward lhoward force-pushed the release/6.1_separate_commits branch from b05bc90 to a8457aa Compare June 22, 2025 07:13
@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

I'll reword commits to be a bit more loquacious when I've a moment

@jeremy-prater
Copy link
Owner

@lhoward @colemancda @compenguy I do not like the idea of checking in all these cmake files. Those should be provided by a sysroot package. Not copying them to the workdir. That is not maintainable.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

Sure. But they definitely shouldn't come from an unstable URL either. They should come from the SSOT upstream projects or we should build Swift from source. Isolating the change to this commit should hopefully permit the other changes to be reviewed in parallel.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

We can pull them from Apple's llvm-project fork but likely we'll need to build LLVM to expand the macro substitutions. I had hoped to defer this until we actually build Swift from source entirely.

@xtremekforever
Copy link
Collaborator

xtremekforever commented Jun 22, 2025

We can pull them from Apple's llvm-project fork but likely we'll need to build LLVM to expand the macro substitutions. I had hoped to defer this until we actually build Swift from source entirely.

I've found with the swift-armv7 scripts that it's possible to simply grab llvm-project, configure it with cmake without actually building it, and point Swift to the cmake configure folder and it works. If you like I can have a look at this on this branch for you since I've already done it, and it should be somewhat trivial to do this with Yocto!

llvm-project gets the same tags as Swift libraries, so we can use the same swift-6.1.2-RELEASE tag to have a consistent version of LLVM against Swift ✌🏻

@xtremekforever
Copy link
Collaborator

llvm-project gets the same tags as Swift libraries, so we can use the same swift-6.1.2-RELEASE tag to have a consistent version of LLVM against Swift ✌🏻

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

We can pull them from Apple's llvm-project fork but likely we'll need to build LLVM to expand the macro substitutions. I had hoped to defer this until we actually build Swift from source entirely.

I've found with the swift-armv7 scripts that it's possible to simply grab llvm-project, configure it with cmake without actually building it, and point Swift to the cmake configure folder and it works. If you like I can have a look at this on this branch for you since I've already done it, and it should be somewhat trivial to do this with Yocto!

Great, shall I give you write access to the branch? I actually started doing this last night but ran out of time.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

Or just pop the recipe in here as an attachment and I'll merge and rebase.

@xtremekforever
Copy link
Collaborator

@lhoward I was going to PR to this branch for you so we can review the changes from one to the other. Then you can merge it in.

I will note tho- this branch fails to build correctly for armv7. There is a typo in do_fix_gcc_install_dir, building the embedded stdlib needs to be turned off, CxxInterop doesn't seem to be building, and also Foundation is compiling in a weird way and creating an unknown target triple. Shall we try to fix these as a part of this set of changes, or can this be done separately?

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

I'll take whatever you have, whenever you have it :)

@xtremekforever
Copy link
Collaborator

Here is the PR: PADL#1

I just need your help confirming it does build correctly, if you have a moment

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

Onto it!

@lhoward lhoward force-pushed the release/6.1_separate_commits branch 2 times, most recently from 0f94c31 to 2effd4d Compare June 22, 2025 22:35
@lhoward
Copy link
Collaborator Author

lhoward commented Jun 22, 2025

@lhoward @colemancda @compenguy I do not like the idea of checking in all these cmake files. Those should be provided by a sysroot package. Not copying them to the workdir. That is not maintainable.

Fixed (thanks to @xtremekforever)

@lhoward lhoward mentioned this pull request Jun 23, 2025
@lhoward lhoward force-pushed the release/6.1_separate_commits branch 5 times, most recently from 524483f to 2ac6389 Compare June 24, 2025 03:56
@lhoward
Copy link
Collaborator Author

lhoward commented Jun 24, 2025

I will note tho- this branch fails to build correctly for armv7. There is a typo in do_fix_gcc_install_dir, building the embedded stdlib needs to be turned off, CxxInterop doesn't seem to be building, and also Foundation is compiling in a weird way and creating an unknown target triple. Shall we try to fix these as a part of this set of changes, or can this be done separately?

I didn't notice an issue with C++ interop. With a couple of small changes, this branch is now building for armv7.

I believe the only remaining issues for parity with masters are CI and dunfell support. I suggest we only support scarthgap for Swift 6.x unless someone else wants to put in the work. CI is revised for Scarthgap/GH runner, just need to wait for it to complete.

@lhoward lhoward force-pushed the release/6.1_separate_commits branch 4 times, most recently from 03fc213 to 9075604 Compare June 24, 2025 07:07
@lhoward
Copy link
Collaborator Author

lhoward commented Jun 24, 2025

CI appears to be ok.

Propose this could be the basis of a scarthgap branch (in which case let's remove in-tree CMake).

@xtremekforever
Copy link
Collaborator

@lhoward let me try to build this for beaglebone Yocto on my end and confirm it runs okay. If so then we should be good to go with this branch.

@xtremekforever
Copy link
Collaborator

That'll be the best for now, to remove the time mods here, then resolve the issues separately. I guess it's an issue for all 32-bit platforms! I did see that WASI has some special handling in NIO (and WASI is 32-bit) but idk if they are using 64-bit time there. Maybe worth checking

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 28, 2025

That'll be the best for now, to remove the time mods here, then resolve the issues separately. I guess it's an issue for all 32-bit platforms! I did see that WASI has some special handling in NIO (and WASI is 32-bit) but idk if they are using 64-bit time there. Maybe worth checking

I would prefer the layer consumer to patch SwiftNIO, even if it's a bit annoying, as changing the time_t ABI from the Yocto default may cause difficult to diagnose issues at runtime. For example, if a Swift recipe with 32-bit time_t uses a shared library with a 64-bit time_t API (that doesn't have a distinct symbol for 32-bit time_t clients like glibc does).

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 28, 2025

That's annoying, but it is a bug in SwiftNIO. We can file a PR but for now the local patch would be to remove 64-bit time_t from the arch/tune flags.

So yes, I changed my mind :)

@xtremekforever
Copy link
Collaborator

Not sure why you'd want to make the layer unusable on 32-bit platforms without patching NIO and potentially other libraries as well...I understand that it would be nice and is more correct to do 64-bit time, but the full impact of switching to this in Swift is currently unknown...

Could we reconsider including time_t upgrades here and tackle it separately? I will remind that Swift has been using 32-bit time on 32-bit platforms since this original layer at 5.7.1- so making this change now is an extra thing that now breaks armv7 compatibility until a bunch of things get patched.

@compenguy
Copy link

Skimming through the rust libc thread about dealing with time_t on 32-bit systems, it looks like glibc's C headers can be used with preprocessor defines to direct you to the 32-bit versions or the 64-bit versions of the time types and functions. Alternatively, you can be explicit (e.g. calling __clock_gettime64 directly).

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 29, 2025

IMO it should then be disabled distro wide to avoid unexpected ABI issues. Essentially the implication is that some of your image is built with one ABI, and the rest, another.

But, happy to disable with a loud bbwarn that your program may crash.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 29, 2025

I will set GLIBC_64BIT_TIME_FLAGS to the empty string. Let it be known that I believe this is the wrong approach (compared to a note in README.md to do this in the distribution config).

armv7 isn't an important platform to me (at the moment, at least), so I'm happy to accomodate consensus here ;)

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 29, 2025

Skimming through the rust libc thread about dealing with time_t on 32-bit systems, it looks like glibc's C headers can be used with preprocessor defines to direct you to the 32-bit versions or the 64-bit versions of the time types and functions. Alternatively, you can be explicit (e.g. calling __clock_gettime64 directly).

This is correct. The issue is that Yocto (sensibly, if you ask me), enables 64-bit timestamps on 32-bit systems by default, because typically you're building the entire image so you don't need to worry about ABI compatibility with external packages – it's effectively a closed system.

This overrides the Yocto default and may cause your program to crash if Swift
packages link against other packages that do not have this disabled. Caveat
emptor.
@lhoward lhoward force-pushed the release/6.1_separate_commits branch from 6b7f955 to e968883 Compare June 29, 2025 02:16
@lhoward
Copy link
Collaborator Author

lhoward commented Jun 29, 2025

Not sure why you'd want to make the layer unusable on 32-bit platforms without patching NIO and potentially other libraries as well...I understand that it would be nice and is more correct to do 64-bit time, but the full impact of switching to this in Swift is currently unknown...

@jeremy-prater I'll leave it to you whether you think 64-bit timestamps on 32-bit platforms should be disabled unconditionally when building Swift recipes, or if it should be left to the end-user to do (with a suitable note in README.md). If you decide the latter than I will update before you merge; otherwise, good to go.

lhoward added 2 commits June 30, 2025 13:41
in the interest of DRY, consolidate common variables between CMake and SwiftPM
classes, moving per-architecture tune flags into a new class
(swift-platform-tune.bbclass)
replace swift-${SWIFT_VERSION}-RELEASE with ${SWIFT_TAG}; this should make it
easier to test pre-release versions of Swift
@xtremekforever
Copy link
Collaborator

xtremekforever commented Jun 30, 2025

Okay, this looks good to me! Then, when the 64-bit time is supported in libraries (when compiling on 32-bit platforms) it can be enabled!!

@xtremekforever
Copy link
Collaborator

@lhoward @jeremy-prater looks like this runs just fine on armv7 and doesn't include the time_t change either. So, looks like it'll work!

@jeremy-prater
Copy link
Owner

Looks like we're ready to merge. One final question, would this layer support kirkstone?
I don't think there were any breaking changes between recipe syntax between kirkstone and scarthgap

LAYERSERIES_COMPAT_swift-layer = "kirkstone scarthgap"

@xtremekforever
Copy link
Collaborator

@jeremy-prater I think there's a problem building this on Kirkstone that @compenguy fixed in a tarball he sent earlier. So this layer is currently only compatible with Scarthgap and newer I believe.

@compenguy
Copy link

Looks like we're ready to merge. One final question, would this layer support kirkstone? I don't think there were any breaking changes between recipe syntax between kirkstone and scarthgap

LAYERSERIES_COMPAT_swift-layer = "kirkstone scarthgap"

I don't think the issue here is syntax compatibility, but rather recipe version compatibility, e.g. cmake.

@compenguy
Copy link

@jeremy-prater I think there's a problem building this on Kirkstone that @compenguy fixed in a tarball he sent earlier. So this layer is currently only compatible with Scarthgap and newer I believe.

I think there's value in getting this merged as-is, and if there's some work that can be done to make it simultaneously compatible with kirkstone, that can be a subsequent PR. But I think it's important to merged what we've got already as a milestone or checkpoint for basing all future work on.

@jeremy-prater
Copy link
Owner

Sounds good, now do we want to squash merge, or just merge 38 commits?

@xtremekforever
Copy link
Collaborator

I vote for squash merge since we've had a good look at the commits!!

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 30, 2025

I vote for keeping the commits.

@lhoward
Copy link
Collaborator Author

lhoward commented Jun 30, 2025

The commit messages have valuable context, for example re: 64-bit timestamps. But if you want to squash, it’s your choice.

Squashing will also make it slightly harder to restore CMake for kirkstone.

lhoward added 3 commits July 1, 2025 15:52
Exclusivity checking has high runtime performance cost, which is undesirable
for embedded systems. Specifying both options doesn't make sense; opt for
-enforce-exclusivity=unchecked which retains static analysis but disables
runtime checking. [1]

[1] https://www.swift.org/blog/swift-5-exclusivity/
export the Swift package resolution function as do_package_resolve so it can be
used conditionally from recipes
@jeremy-prater jeremy-prater merged commit 1a4b9bf into jeremy-prater:master Jul 1, 2025
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