‹ back home

Building and running sway-master

2023-08-04 #alpine #open-source #sway

I wanted to run sway from upstream master branch to tests the yet-unreleased fractional scaling support. This recipe also works for trying to build sway with custom patches.

First, I needed to clone sway itself and wlroots as a subproject. Building wlroots as a subproject is required since I need to use the current master of wlroots. Using the distribution/system provided wlroots is unlikely to work (due to it being the latest stable release).

git clone https://github.com/swaywm/sway.git
cd sway
mkdir subprojects
cd subprojects
git clone https://gitlab.freedesktop.org/wlroots/wlroots
cd ..

Next up, install all the build dependencies for both sway and wlroots. Using -t .sway-dev installs a virtual package called .sway-dev which has all the packages listed below as dependencies. This makes cleaning up very simple later on.

doas apk add -t .sway-dev \
  basu-dev \
  cairo-dev \
  eudev-dev \
  eudev-dev \
  gdk-pixbuf-dev \
  glslang-dev \
  hwdata-dev \
  json-c-dev \
  lcms2-dev \
  libcap-dev \
  libcap-utils \
  libdisplay-info-dev \
  libevdev-dev \
  libinput-dev \
  libliftoff-dev \
  libseat-dev \
  libxcb-dev \
  libxkbcommon-dev \
  linux-pam-dev \
  mesa-dev \
  meson \
  ninja \
  pango-dev \
  pcre2-dev \
  pixman-dev \
  scdoc \
  vulkan-loader-dev \
  wayland-dev \
  wayland-protocols \
  wlroots-dev \
  xcb-util-image-dev \
  xcb-util-renderutil-dev \
  xcb-util-wm-dev \
  xkeyboard-config-dev \

As mentioned in the packaging recommendations, it’s best to statically link wlroots. This results in it being bundled into sway’s binary, instead of sway loading the system wlroots1.

meson -Dwlroots:default_library=static build
meson compile -C build
doas meson install -C build --skip-subprojects wlroots

Using meson install will install sway into /usr/local, and it won’t overwrite the distribution-provided sway or any of its files. Since /usr/local/bin/sway has precedence over /usr/bin/sway, then this version will be used by default when running sway.

Running meson uninstall -C build will remove this version of sway and un-shadow the stable one installed via distribution packages.

Update 2024-04-24: Add --skip-subprojects wlroots to avoid installing wlroots. It is unnecessary in this case due to being statically linked.

  1. Loading the system wlroots is very likely to result in a crash, given that sway is being built with a recent version of wlroots, and sway’s master branch is often not even compatible with the latest stable release of wlroots↩︎

— § —