I'm new to swift programming and am working with it on Ubuntu Linux, swift-6.0.2-RELEASE-ubuntu24.04. I want to use the Logger but, I cannot import the os module, I get:
import os
' - error: no such module 'os'
As you can guess, my code runs fine on macOS. what do I need to do to fix my ubuntu swift package?
As a note: Swift doesn’t have a os library. If you want to have some OS functionality you should use Darwin(Apple‘s Kernal Name) on Apple Devices and GLibC on Linux or check if Foundation contains the functionality you want. This can prevent Future confusion. You may have come from python which doesn’t have a discernment between Kernals as it requires some special C-Libraries to make os work on all devices so it is reimplemented per kernal/OS(depending on the variance in OSs among a kernal), this does work for JIT languages but Compiled Languages cannot abstract OS functionality and as such need to properly integrate the OS functionality.
There is a package that some of the core of the Swift ecosystem (things like swift package manager, etc) is leveraging in this regard: GitHub - apple/swift-system: Low-level system calls and types for Swift - it's a collection of platform specific APIs to make interacting with the C API's otherwise exposed through Darwin, MUSL, GLibC, WASM, etc a bit more pleasant. Not everything is in there, and I'm sure quite a lot won't ever be, but it's worth knowing about.
On macOS, you can import System without adding a package dependency. That will provide you with a library that is very similar to the one provided by the swift-system package.