buildsystem: Move to meson for building the project

Meson will allow us to:
- Verify the used rust compiler is recent enough
- Install ressources such as a .desktop files, icons, etc.
This commit is contained in:
Tom A. Wagner 2021-08-29 17:28:55 +02:00
parent 7ef8677c4c
commit a8bfd8383e
6 changed files with 115 additions and 16 deletions

View file

@ -24,27 +24,32 @@ $ flatpak install org.gnome.{Platform,Sdk}//40 org.freedesktop.Sdk.Extension.rus
To compile and install as a flatpak, run To compile and install as a flatpak, run
```shell ```shell
$ flatpak-builder --install flatpak-build/ org.freedesktop.ryuukyu.Helvum.json $ flatpak-builder --install flatpak-build/ build-aux/org.freedesktop.ryuukyu.Helvum.json
``` ```
You can then run the app via You can then run the app via
```shell ```shell
flatpak run org.freedesktop.ryuukyu.Helvum $ flatpak run org.freedesktop.ryuukyu.Helvum
``` ```
## Manually ## Manually
For compilation, you will need: For compilation, you will need:
- Meson
- An up-to-date rust toolchain - An up-to-date rust toolchain
- `libclang-3.7` or higher - `libclang-3.7` or higher
- `gtk-4.0` and `pipewire-0.3` development headers - `gtk-4.0` and `pipewire-0.3` development headers
To compile, run To compile and install, run
$ cargo build --release ```shell
$ meson setup build && cd build
$ meson compile
$ meson install
```
in the repository root. in the repository root.
The resulting binary will be at `target/release/helvum`. This will install the compiled project files into `/usr/local`.
# License # License
Helvum is distributed under the terms of the GPL3 license. Helvum is distributed under the terms of the GPL3 license.

20
build-aux/cargo.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/sh
export MESON_BUILD_ROOT="$1"
export MESON_SOURCE_ROOT="$2"
export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target
export CARGO_HOME="$MESON_BUILD_ROOT"/cargo-home
if [[ $4 = "development" ]]
then
echo "DEBUG MODE"
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml && \
cp "$CARGO_TARGET_DIR"/debug/$5 $3
else
echo "RELEASE MODE"
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --release && \
cp "$CARGO_TARGET_DIR"/release/$5 $3
fi

View file

@ -3,7 +3,9 @@
"runtime": "org.gnome.Platform", "runtime": "org.gnome.Platform",
"runtime-version": "40", "runtime-version": "40",
"sdk": "org.gnome.Sdk", "sdk": "org.gnome.Sdk",
"sdk-extensions": ["org.freedesktop.Sdk.Extension.rust-stable"], "sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable"
],
"command": "helvum", "command": "helvum",
"finish-args": [ "finish-args": [
"--socket=fallback-x11", "--socket=fallback-x11",
@ -21,15 +23,15 @@
"modules": [ "modules": [
{ {
"name": "Helvum", "name": "Helvum",
"buildsystem": "simple", "buildsystem": "meson",
"build-commands": [
"cargo install --path . --root /app --no-track"
],
"sources": [ "sources": [
{ {
"type": "dir", "type": "dir",
"path": "./" "path": "../"
} }
],
"config-opts": [
"-Dprofile=development"
] ]
} }
] ]

30
meson.build Normal file
View file

@ -0,0 +1,30 @@
project(
'helvum',
'rust',
version: '0.3.0',
license: 'GPL-3.0',
meson_version: '>=0.50.0'
)
dependency('glib-2.0', version: '>= 2.48')
dependency('gtk4', version: '>= 4.0.0')
dependency('libpipewire-0.3')
rust_version = meson.get_compiler('rust').version()
min_rust_version = '1.54.0'
if rust_version < min_rust_version
error('Rust version too old: Required version is ' + min_rust_version + ' but actual version is ' + rust_version)
endif
cargo = find_program('cargo', required: true)
cargo_script = find_program('build-aux/cargo.sh')
prefix = get_option('prefix')
bindir = prefix / get_option('bindir')
cargo_sources = files(
'Cargo.toml',
'Cargo.lock',
)
subdir('src')

11
meson_options.txt Normal file
View file

@ -0,0 +1,11 @@
option(
'profile',
type: 'combo',
choices: [
'default',
'development'
],
value: 'default',
description: 'The build profile for Helvum. One of "default" or "development".'
)

31
src/meson.build Normal file
View file

@ -0,0 +1,31 @@
rust_sources = files(
'application.rs',
'main.rs',
'pipewire_connection.rs',
'pipewire_connection/state.rs',
'view/graph_view.rs',
'view/mod.rs',
'view/node.rs',
'view/port.rs',
)
custom_target(
'cargo-build',
build_by_default: true,
input: [
cargo_sources,
rust_sources
],
output: meson.project_name(),
console: true,
install: true,
install_dir: bindir,
command: [
cargo_script,
meson.build_root(),
meson.source_root(),
'@OUTPUT@',
get_option('profile'),
meson.project_name(),
],
)