Commit Graph

13 Commits

Author SHA1 Message Date
Mishal Shah bc666e6c1c Revert "[CMake] Consolidate and standardlize the embedded Swift library build" 2026-06-02 08:44:41 -07:00
Doug Gregor 97cd0df479 [CMake] Centralize most of the logic for building embedded libraries
There was a ton of copy-paste in the various embedded swift library
builds. Centralize most of that logic into a new
add_embedded_swift_target_library function that will make it easier to
make additional libraries build as embedded swift.
2026-05-28 07:08:32 -04:00
Doug Gregor d169e97818 [CMake] Eliminate a lot of embedded library building copy-pasta
Sink settings for various Swift library build options that have fixed
values for Embedded Swift down into the AddSwiftStdlib logic, rather
than duplicating them in every embedded library build.
2026-05-28 07:08:32 -04:00
Doug Gregor ac9a69a50f [CMake] Drop the ONLY_SWIFTMODULE option and centralize Embedded Swift build flags
The ONLY_SWIFTMODULE option was used for some of the Embedded Swift
library builds to produce just a .swiftmodule without any
corresponding object files or static archives. This presupposes a
build model where we never emit object code for these libraries;
rather, it all gets inlined into the clients.

To make it possible to add more flexibility to the build model here,
drop this option. Instead, pass along the flags to emit an empty
object file and set the code generation model to "implementation".
This is effectively the same code generation model (since the object
file is empty), but made more explicit and done in a manner that fits
in better with the build system.

Use this as an excuse to centralize setting a number of other Embedded
Swift-specific flags, rather than copy-pasting them for every library
built as Embedded Swift.
2026-05-28 07:08:30 -04:00
Doug Gregor 19c616928f Replace _swift_writeCharToStandardOutput with _swift_writeToStandardOutput 2026-05-22 23:57:41 -07:00
Doug Gregor 5ade284158 [Embedded] Start staging in _swift_writeToStandardOutput
It's far better to write characters in bulk than one at a time,
putchar-style. Start moving the platform abstraction layer over to a
function that does so.
2026-05-22 23:05:55 -07:00
Doug Gregor 7f1344bf92 [Embedded] Add single/counted_by/sized_by annotations for the Platform Abstraction Layer 2026-05-22 23:05:54 -07:00
Doug Gregor 4f1a0b7016 [Embedded] Add _swift_exit() to the Platform Abstraction Layer
The Embedded Swift concurrency library needs a way to exit the program
at the end of async main. The existing implementation calls through a
_swift_exit() function to the POSIX/C exit(). Enshrine _swift_exit()
as part of the Platform Abstraction Layer, with the same signature
(albeit in C), and implement it in the PAL-on-POSIX library as a call
through to exit().
2026-05-05 21:30:59 -07:00
Doug Gregor d677252ee1 [Embedded platform] Disable bridging PCH
The bridging PCH created by the driver uses a temporary directory,
which introduces nondeterminism into the results. We don't need to
precompile this tiny header, so turn off the precompiled bridging
header.

Fixes rdar://172741975
2026-04-02 16:10:20 -07:00
Dario Rexin 5b0da23150 [IRGen] Add typed allocations for embedded Swift
rdar://158239258

This change adds logic in the compiler to compute malloc type ids and emit them together with typed allocation calls. It also adds the new runtime function swift_allocObjectTyped, which calls typed malloc.
2026-03-05 12:41:16 -08:00
Doug Gregor ae1e3d0865 Build a static library that implements the Embedded Swift platform layer on POSIX
The new library, swiftEmbeddedPlatformPOSIX, implements all of the
_swift_XYZ functions needed to support Embedded Swift as shims on top
of a POSIX system that provides posix_memalign, free, putchar, and so
on. This offers an easier way to bridge between the prior ad hoc
requirements of Embedded Swift and the newer platform abstraction
layer.

Part of rdar://164057124
2026-03-03 09:05:30 -08:00
Doug Gregor a7cdd02c6e [Embedded platform] Replace _swift_free with _swiftAlignedFree
Pass size and alignment through to the free function, to account for
allocators that need to know this information.
2026-03-03 09:05:30 -08:00
Doug Gregor 84b653fb73 Provide a C header that describes Embedded Swift's upcoming platform requirements
Embedded Swift depends on a number of functions from the platform,
including posix_memalign, free, and arc4random_buf. While these
dependencies are documented, they aren't documented in a manner that
makes them easy to implement. Additionally, most of these are C
library functions that may or may not be available, and can have
requirements that are more stringent than Embedded Swift actually
requires.

Try to address both problems at once by introducing a new header,
`swift/EmbeddedPlatform.h`, that provides a new set of C declarations
for functions that need to be provided by a platform. For
each function, we provide documentation on what it does, what Embedded
Swift facilities will end up using it (e.g.,
`_swift_generateRandomHashSeed` is needed for seeding the hash
functions used for `Set` and `Dictionary`, among other things), and
some guidance on how to implement it---including those cases where
directly calling an existing C standard library or POSIX function will
suffice.

There is a new CMake option, SWIFT_USE_SWIFT_EMBEDDED_PLATFORM, that
enables the use of these entrypoints in the Embedded Swift runtime. It
is currently disabled, because enabling it would break existing
clients of Embedded Swift. We're looking for a way to stage this in.

Addresses rdar://164057124.
2026-03-03 09:05:29 -08:00