OpenBSD port status and tracking

This post is intended to be some supplemental documentation for getting Swift and its components running on OpenBSD and describe context on the state of the port. This is done here on the forums in order to more dynamically and rapidly augment "more official" in-tree documentation, which requires pull requests and reviews to update.

Getting the compiler and stdlib built

  • Follow the in-tree documentation (docs/
    • Take special care to the symlinks section -- don't just blindly copy and paste these, because you need to make sure these apply to the current OpenBSD version.
    • This is because LLVM doesn't recognize the OpenBSD platform version scheme, and mix up static and dynamic libraries. There is a manual change that can be made to LLVM that alleviates the need for making changes to the base system, which I will link in a future edit, but probably will not be upstreamed because of comments about OpenBSD potentially adopting adding symlinks anyway.
  • Known issues/deficiencies:
    • The REPL doesn't work (i.e., calling swift without arguments) and will give a scary backtrace, however the "inbuilt JIT" mode does (swift foo.swift).
      • AIUI, this needs more comprehensive lldb work on the platform. This is unlikely to happen any time soon.
  • Necessary cherrypicks:
    • As of 2022-03-10, the Swift compiler should build at HEAD.

Foundation and Dispatch

  • Necessary cherrypicks:
    • As of 2022-02-10, you will need to cherrypick pr #559 in Dispatch and #3004 in Foundation.
  • The Foundation pr is primarily to get CFRunLoop implemented
    • Among other things, this pr uses kevent, which the BSDs all implement. So does xnu, for that matter. It would be a fun experiment to cross-check whether the kevent implementation in that pr works on Darwin...
  • The Dispatch pr implements a few gaps in functionality
    • Specifically, it uses pipe2 and packed file descriptors for runloop implementation, which has inherent tradeoffs for portability.
    • This implementation may still require some additional testing but generally works well and the associated runloop Foundation tests pass. The caveat here, however, is that the Foundation and Dispatch testing coverage may not be as thorough.
    • You will notice that existing in-tree documentation carefully counsels disabling Dispatch in the Swift compiler/stdlib. This is because the Dispatch pr has not landed.
    • If you go the route of cherrypicking these prs, you can go back and compile with Dispatch enabled.

The road to SwiftPM

  • llbuild requires some manual changes to the in-tree support library, but they are minimal.
    • More TK.
  • swift-crypto works well enough if you make the obvious changes such as changing all the defined(__linux__) to defined(__linux__) || defined(__OpenBSD__). However, I don't know if this is advisable to upstream: OpenBSD has libressl and may be somewhat opinionated about security primitives, but an explicit goal of swift-crypto is to be bit-compatible across platforms and therefore may require specific implementations. More thinking and research may be required here.
  • yams needs the usual amd64 naming change and substituting of complex macro DBL_DECIMAL_DIG. Not difficult, just have not done this yet.
  • With these changes SPM seems to build OK.
    • This is no guarantee that other packages that use SPM will build OK, however!

Additional context

  • TK.

(Editorial nit) Would you mind turning those references to pending PRs in to links? Makes it easier for people to follow along.

Thanks, and nice work maintaining this port!

Done! More braindumping will follow as I get time.


Thank you! FreeBSD user hope have it.

1 Like