|
| 1 | +# Getting started with Swift on OpenBSD |
| 2 | + |
| 3 | +Swift builds and runs on OpenBSD (tested on 6.8-beta), with some special considerations. |
| 4 | + |
| 5 | +## Preparing |
| 6 | + |
| 7 | +The following packages are required to build Swift. You can install these via `pkg_add`: |
| 8 | + |
| 9 | +```shell |
| 10 | +$ doas pkg_add bash cmake e2fsprogs git icu4c ninja py-six python3 |
| 11 | +``` |
| 12 | + |
| 13 | +Because LLVM is built as part of building Swift and does not include some of the patches to handle the OpenBSD library naming convention, you will need to create some symlinks: |
| 14 | + |
| 15 | +```shell |
| 16 | +$ doas ln -s /usr/lib/libc++abi.so.2.1 /usr/lib/libc++abi.so |
| 17 | +$ doas ln -s /usr/lib/libc++.so.4.0 /usr/lib/libc++.so |
| 18 | +$ doas ln -s /usr/lib/libc.so.96.0 /usr/lib/libc.so |
| 19 | +$ doas ln -s /usr/lib/libm.so.10.1 /usr/lib/libm.so |
| 20 | +$ doas ln -s /usr/local/lib/libicuuc.so.18.0 /usr/local/lib/libicuuc.so |
| 21 | +$ doas ln -s /usr/lib/libpthread.so.26.1 /usr/lib/libpthread.so |
| 22 | +``` |
| 23 | + |
| 24 | +*Note: you may need to update the version numbers if necessary.* |
| 25 | + |
| 26 | +Also link `~/bin/python` to the `python2.7` binary: |
| 27 | + |
| 28 | +```shell |
| 29 | +$ doas ln -s /usr/local/bin/python2.7 ~/bin/python |
| 30 | +``` |
| 31 | + |
| 32 | +Since the build requires significant amounts of memory at certain points, you may need to ensure that the user you are using to build Swift has the appropriate limits set. Using the `staff` group in `login.conf` and ensuring the shell limits are raised is recommended. |
| 33 | + |
| 34 | +## Downloading the source |
| 35 | + |
| 36 | +Download the sources with the [Getting Started](/docs/HowToGuides/GettingStarted.md) guide (see "Cloning the project"). Use the config file below when running `update-checkout` by specifying the file name with the `--config` flag. This config file just prepares cmark, LLVM, and Swift (as this is the minimal set of dependencies which has been tested for OpenBSD). |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "ssh-clone-pattern": "[email protected]:%s.git", |
| 41 | + "https-clone-pattern": "https://github.com/%s.git", |
| 42 | + "default-branch-scheme": "master", |
| 43 | + "repos": { |
| 44 | + "cmark": { "remote": { "id": "apple/swift-cmark" } }, |
| 45 | + "llvm-project": { "remote": { "id": "apple/llvm-project" } }, |
| 46 | + "swift": { "remote": { "id": "apple/swift" } } |
| 47 | + }, |
| 48 | + "branch-schemes": { |
| 49 | + "master": { |
| 50 | + "aliases": [ "master", "swift/master" ], |
| 51 | + "repos": { |
| 52 | + "cmark": "master", |
| 53 | + "llvm-project": "swift/master", |
| 54 | + "swift": "master" |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Building |
| 62 | + |
| 63 | +Once the sources have completed downloading, you can use the standard `build-script` mechanism to start building Swift. However, some options are required to be set to successfully build Swift. |
| 64 | + |
| 65 | +These options are: |
| 66 | +* `--skip-build-clang-tools-extra` and `--skip-build-compiler-rt`: to ensure LLVM builds cleanly, |
| 67 | +* `--extra-cmake-options=` |
| 68 | + * `-DCMAKE_DISABLE_FIND_PACKAGE_Backtrace=TRUE,-DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=TRUE,-DLLVM_VERSION_SUFFIX=''`: to ensure LLVM builds cleanly, |
| 69 | + * `-DSWIFT_BUILD_SOURCEKIT=OFF,-DSWIFT_BUILD_SYNTAXPARSERLIB=OFF`: to ensure Swift does not attempt to build libdispatch, which is not yet supported on OpenBSD, |
| 70 | + * `-DSWIFT_USE_LINKER=lld`: to specify that `lld` should be used over `gold`, |
| 71 | + * `-DCMAKE_INSTALL_DIR=/usr/local"`: to set the correct platform install directory. |
| 72 | + |
| 73 | +In full, the minimal set of flags to supply to `build-script` looks like: |
| 74 | +```shell |
| 75 | +$ ./utils/build-script \ |
| 76 | + --skip-build-clang-tools-extra \ |
| 77 | + --skip-build-compiler-rt \ |
| 78 | + --extra-cmake-options="\ |
| 79 | + -DCMAKE_DISABLE_FIND_PACKAGE_Backtrace=TRUE,\ |
| 80 | + -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=TRUE,\ |
| 81 | + -DLLVM_VERSION_SUFFIX='',\ |
| 82 | + -DSWIFT_BUILD_SOURCEKIT=OFF,\ |
| 83 | + -DSWIFT_BUILD_SYNTAXPARSERLIB=OFF,\ |
| 84 | + -DSWIFT_USE_LINKER=lld,\ |
| 85 | + -DCMAKE_INSTALL_DIR=/usr/local" |
| 86 | +``` |
| 87 | + |
| 88 | +You may wish to also supply the flag `--llvm-targets-to-build=host`, to speed up the LLVM build slightly. |
0 commit comments