Skip to content

Commit

Permalink
Merge pull request #10 from vilfa/feature/2-add-vagrantfile
Browse files Browse the repository at this point in the history
#9 Add a development environment setup using Vagrant.
  • Loading branch information
vilfa authored Oct 3, 2022
2 parents 53b835a + 70a0a1e commit ff9e6fc
Show file tree
Hide file tree
Showing 21 changed files with 388 additions and 402 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ dkms.conf
# # # ArchPkgbuild # # #
package/arch/*
!package/arch/PKGBUILD

# # # Vagrant # # #
**/.vagrant
70 changes: 66 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,86 @@
"version": "2.0.0",
"tasks": [
{
"label": "Remote: Setup",
"label": "Devenv: Connect to Display",
"type": "shell",
"command": "${workspaceFolder}/remote/setup.sh",
"command": "virt-viewer -ac qemu:///system --uuid 60fa5b18-e4d6-47a4-af7a-023d3d34bfaa",
"group": "none",
"presentation": {
"reveal": "never",
"panel": "shared"
},
"isBackground": true,
"problemMatcher": []
},
{
"label": "Devenv: Prepare Project (Git)",
"type": "shell",
"command": "vagrant provision --provision-with prepare_git",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Devenv: Prepare Project (Local)",
"type": "shell",
"command": "vagrant provision --provision-with prepare_local",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Devenv: Build Project",
"type": "shell",
"command": "vagrant provision --provision-with build",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Devenv: Update Project",
"type": "shell",
"command": "vagrant provision --provision-with update",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Devenv: Run Bonsai",
"type": "shell",
"command": "vagrant provision --provision-with run",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Remote: Build all machines",
"label": "Devenv: Kill Bonsai",
"type": "shell",
"command": "${workspaceFolder}/remote/build.sh",
"command": "vagrant provision --provision-with kill",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
},
{
"label": "Devenv: Clean Project",
"type": "shell",
"command": "vagrant provision --provision-with clean",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
}
}
]
}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,71 @@ library, meaning a rock-solid foundation to build on.
* `wl-clipboard` (screenshot & clipboard)
* `brightnessctl` (brightness control via waybar)

### Using the Vagrant development environment
For the optimal developer experience, it is recommended you use the provided
Vagrant development environment. Currently this environment is only configured
with the `libvirt` provider, however, multiple Vagrant providers could quite easily
be added in the future.

To use this environment, make sure, you have the latest versions of the following
packages:
* `vagrant` (manages virtual machines)
* `vagrant-libvirt` (the `libvirt` plugin for Vagrant)
* `libvirt` + `qemu` (should be installed automatically with `vagrant`)
* `virt-manager` (graphical frontend to `libvirt`)
* `virt-viewer` (connect to virtual machine display)

After installing the necessary dependencies (a restart may be required), move to
the project root and simply run
```bash
vagrant up
```

This should automatically create a new virtual machine that is set up with all
necessary compile- and run-time dependencies. As far as using this setup goes,
there are several commands/provisioners that are available to you, to make working
with the development virtual machine easier. These should be run in the project
root, in the following form
```bash
vagrant provision --provision-with <command/provisioner>
```

The available commands/provisioners are
* `connect` -> connect to the dev env display using `virt-manager`
* `prepare_git` -> clone the git upstream & prepare meson build env
* `prepare_local` -> copy local sources from your project root & prepare meson build env
* `build` -> build the project in the build env
* `update` -> update build env with sources from your project root
* `run` -> run bonsai in the graphical session on the dev env (currently not working)
* `kill` -> kill the bonsai process on the dev env
* `clean` -> clean the meson build artefacts from the project folder on the dev env

Thus, the steps for the first build could be
```bash
git clone https://github.com/vilfa/bonsai.git && cd bonsai
vagrant up
vagrant provision --provision-with prepare_local
vagrant provision --provision-with build
```

Then, in the dev env graphical session, login as vagrant:vagrant, and run the built
project with
```bash
cd home/vagrant/bonsai && ./builddir/bonsai/bonsai
```

Then, when you make some changes, you might want to update your source on the dev env
and rerun the compositor. That could also be done by running
```bash
vagrant provision --provision-with kill
vagrant provision --provision-with update
vagrant provision --provision-with build
```

...and repeating the above step for running.

To make this even easier, VS Code tasks are also provided. Search for 'devenv'.

### Building and installing

* Clone the repo
Expand Down
106 changes: 106 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

module LocalCommand
class Config < Vagrant.plugin("2", :config)
attr_accessor :command
end

class Plugin < Vagrant.plugin("2")
name "local_shell"

config(:local_shell, :provisioner) do
Config
end

provisioner(:local_shell) do
Provisioner
end
end

class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
result = system "#{config.command}"
end
end
end

Vagrant.configure("2") do |config|
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development devenvment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.define "devenv"
config.vm.box = "generic/arch"
config.vm.hostname = "bonsai-devenv"

# Configure libvirt for 3d accelerated graphical session.
config.vm.provider :libvirt do |libvirt|
libvirt.graphics_type = "spice"
libvirt.video_accel3d = true
libvirt.video_type = "virtio"
libvirt.graphics_ip = nil
libvirt.graphics_port = nil
libvirt.uuid = "60fa5b18-e4d6-47a4-af7a-023d3d34bfaa"
libvirt.uri = "qemu:///system"
end

# Share working directory with devenv.
config.vm.synced_folder ".", "/vagrant_data"

# Various provisioners for working with the devenv.
config.vm.provision "connect", type: "local_shell", run: "always" do |p|
p.command = "virt-viewer -ac qemu:///system --uuid 60fa5b18-e4d6-47a4-af7a-023d3d34bfaa &"
end

config.vm.provision "prepare_box", type: "shell", run: "once" do |p|
p.path = "devenv/prepare_box.sh"
p.privileged = true
end

config.vm.provision "install_compile_deps", type: "shell", run: "once" do |p|
p.path = "devenv/install_compile_deps.sh"
p.privileged = true
end

config.vm.provision "install_runtime_deps", type: "shell", run: "once" do |p|
p.path = "devenv/install_runtime_deps.sh"
p.privileged = true
end

config.vm.provision "prepare_git", type: "shell", run: "never" do |p|
p.path = "devenv/project_prepare_git.sh"
p.privileged = false
end

config.vm.provision "prepare_local", type: "shell", run: "never" do |p|
p.path = "devenv/project_prepare_local.sh"
p.privileged = false
end

config.vm.provision "build", type: "shell", run: "never" do |p|
p.path = "devenv/project_build.sh"
p.privileged = false
end

config.vm.provision "update", type: "shell", run: "never" do |p|
p.path = "devenv/project_update.sh"
p.privileged = false
end

config.vm.provision "run", type: "shell", run: "never" do |p|
p.path = "devenv/project_run.sh"
p.privileged = false
end

config.vm.provision "kill", type: "shell", run: "never" do |p|
p.path = "devenv/project_kill.sh"
p.privileged = false
end

config.vm.provision "clean", type: "shell", run: "never" do |p|
p.path = "devenv/project_clean.sh"
p.privileged = false
end
end
55 changes: 55 additions & 0 deletions devenv/install_compile_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

install() {
pacman -S --noconfirm $@
}

concat() {
local -n in=$1
for dep in ${in[@]}; do
deps="$deps $dep"
done
echo $deps
}

dependencies=(
base-devel
gdb
git
meson
libinput
libevdev
systemd-libs
libxkbcommon
mesa
vulkan-headers
libdrm
wayland
wayland-utils
wayland-protocols
xdg-desktop-portal
xdg-desktop-portal-wlr
pixman
cairo
seatd
xcb-util
xcb-util-renderutil
xcb-util-wm
xcb-util-errors
xorg-xwayland
glslang
ffmpeg
rsync
)

install $(concat dependencies)

install_wlroots_latest() {
git clone https://gitlab.freedesktop.org/wlroots/wlroots.git /root/wlroots
cd /root/wlroots
meson builddir
meson compile -C builddir
meson install -C builddir
}

install_wlroots_latest
26 changes: 26 additions & 0 deletions devenv/install_runtime_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

install() {
pacman -S --noconfirm $@
}

concat() {
local -n in=$1
for dep in ${in[@]}; do
deps="$deps $dep"
done
echo $deps
}

dependencies=(
swaybg
swaylock
bemenu-wayland
waybar
slurp
grim
wl-clipboard
brightnessctl
)

install $(concat dependencies)
7 changes: 7 additions & 0 deletions devenv/prepare_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

update () {
pacman -Syu --noconfirm
}

update
6 changes: 6 additions & 0 deletions devenv/project_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Run prepare_* first." && exit 1

cd /home/vagrant/bonsai
meson compile -C builddir/
9 changes: 9 additions & 0 deletions devenv/project_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Nothing to clean." && exit 0

cd /home/vagrant/bonsai

[ ! -d builddir ] && echo "Nothing to clean." && exit 0

rm -rf builddir
3 changes: 3 additions & 0 deletions devenv/project_kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

killall bonsai
5 changes: 5 additions & 0 deletions devenv/project_prepare_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && git clone https://github.com/vilfa/bonsai.git /home/vagrant/bonsai
cd /home/vagrant/bonsai
[ ! -d builddir ] && PKG_CONFIG_PATH=/usr/local/lib/pkgconfig meson builddir/
Loading

0 comments on commit ff9e6fc

Please sign in to comment.