Stdlib Platform module/symbols not found in Embedded Mode

Hi!

When I import Darwin and try to use a symbol defined in stdlib/public/Platform/Platform.swift, such as DarwinBoolean, Semaphore, or errno, that symbol is not found when compiling in embedded mode on a Mac. Why? Am I holding it wrong? I thought the stdlib had (partial) embedded support, at least that's what I inferred based on the @_unavailableInEmbedded attributes and #if !$Embedded around some of the code in said stdlib/public/Platform/Platform.swift. See CMakeLists in stdlib/public/Platform

Even funnier, when I compile in debug mode instead of release, the entire Darwin module cannot be imported (same goes for Darwin.C).

Is this a bug or do I need to pass in additional flags...?

Same issue, regardless whether SPM or xcode. I am using a current main snapshot with
-enable-experimental-feature Embedded -wmo, or, well, the SPM version of that (.enableExperimentalFeature("Embedded"), .unsafeFlags(["-wmo"]))

$ TOOLCHAINS=org.swift.62202503131a swift build -c release
[1/1] Planning build
Building for production...
path/to/main.swift:8:11: error: cannot find type 'Semaphore' in scope
 6 | import Darwin
 7 |
 8 | extension Semaphore {}
   |           `- error: cannot find type 'Semaphore' in scope
 9 | extension Darwin.Semaphore {}
10 |

path/to/main.swift:9:18: error: no type named 'Semaphore' in module 'Darwin'
 7 |
 8 | extension Semaphore {}
 9 | extension Darwin.Semaphore {}
   |                  `- error: no type named 'Semaphore' in module 'Darwin'
$ TOOLCHAINS=org.swift.62202503131a swift build
[1/1] Planning build
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: module '_errno' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_time' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_signal' cannot be imported in embedded Swift mode
<unknown>:0: error: module 'sys_time' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_stdio' cannot be imported in embedded Swift mode
<unknown>:0: error: module 'unistd' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_math' cannot be imported in embedded Swift mode
path/to/main.swift:6:8: error: module 'Darwin' cannot be imported in embedded Swift mode
 4 | print("Hello, world! \(2) \(a)")
 5 |
 6 | import Darwin
   |        `- error: module 'Darwin' cannot be imported in embedded Swift mode
 7 |
 8 | extension Semaphore {}
<unknown>:0: error: module '_errno' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_time' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_signal' cannot be imported in embedded Swift mode
<unknown>:0: error: module 'sys_time' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_stdio' cannot be imported in embedded Swift mode
<unknown>:0: error: module 'unistd' cannot be imported in embedded Swift mode
<unknown>:0: error: module '_math' cannot be imported in embedded Swift mode
path/to/main.swift:6:8: error: module 'Darwin' cannot be imported in embedded Swift mode
 4 | print("Hello, world! \(2) \(a)")
 5 |
 6 | import Darwin
   |        `- error: module 'Darwin' cannot be imported in embedded Swift mode
 7 |
 8 | extension Semaphore {}

I’m not sure why Darwin specific modules would be available in Embedded Swift which, I believe, is designed to be run on platforms where those modules would not be present. Is this wrong of me to assume?

What Xcode and SDK versions do you have?

Importing Darwin should give you at least the Darwin C module, as that's the only way to call standard C APIs on macOS/iOS. It's currently not possible to get the Darwin Swift overlay -- intentionally, at least for now. The reason is that the overlay is part of the SDK, and thus it's not Embedded Swift compatible. (The macOS/iOS SDK doesn't distribute any Embedded Swift modules.)

I was using Xcode 16.2 (16C5032a) with the bundled MacOSX15.2.sdk and
the 03-13a snapshot:

TOOLCHAINS=org.swift.62202503131a swift --version
Apple Swift version 6.2-dev (LLVM 8181ec46fb75248, Swift 27bac6952744072)
Target: arm64-apple-macosx15.0

Now I tried a current Xcode beta version (Xcode 16.3 beta 2 (16E5121h)) which comes with the MacOSX15.4.sdk (which, in turn, gets passed to swift build, right?), and that works (import Darwin[.C]), except for the overlay.

The overlay is the Platform.swift stuff, like errno, Semaphore, etc, isn't? At least that's my guess based on the error I get with the more recent .sdk when I try to access errno:

 80 | extern int * __error(void);
 81 | #define errno (*__error())
    |         `- note: macro 'errno' unavailable: structure not supported
 82 | __END_DECLS

Normally -- assuming I'm right about the overlay -- I'd expect errno to have a Swift getter:

// stdlib/public/Platform/Platform.swift
public var errno : Int32 {
  get {
    return _swift_stdlib_getErrno()
  }
  set(val) {
    return _swift_stdlib_setErrno(val)
  }
}

Plus, the nice argument labels for certain system calls like open aren't available -- suggesting this is the raw open function being imported, rather than the overlay.