Compiling and install using meson

This commit is contained in:
Daniel García Moreno 2017-11-08 12:44:55 +01:00
parent 148d6c387b
commit 73895f22e7
9 changed files with 272 additions and 5 deletions

3
.gitignore vendored
View file

@ -2,3 +2,6 @@ target
*~
*.swp
*.swo
Makefile
_build
Cargo.lock

View file

@ -8,6 +8,17 @@ Fractal is a Gtk+ Matrix.org client written in Rust.
![screenshot](https://gitlab.gnome.org/danigm/fractal/raw/master/screenshots/fractal.png)
## How to Build
You need meson and jinja to build this project. Rust and cargo are also
needed.
```
./configure --prefix=/usr/local
make
sudo make install
```
## Supported m.room.message (msgtypes)
msgtypes | Recv | Send
@ -33,4 +44,4 @@ REST API.
The first version of this project was called guillotine, based on french revolution,
in relation with the Riot client name, but it's a negative name so we decide
to change for a math one.
to change for a math one.

23
build.rs Normal file
View file

@ -0,0 +1,23 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let fractal_res = env::var("FRACTAL_RES").unwrap_or(String::from("res"));
let dest_path = Path::new(&out_dir).join("config.rs");
let mut f = File::create(&dest_path).unwrap();
let code = format!("
mod config {{
pub fn datadir(res: &str) -> String {{
let out = String::from(\"{}/\");
out + res
}}
}}
", fractal_res);
f.write_all(code.as_bytes()).unwrap();
}

183
configure vendored Executable file
View file

@ -0,0 +1,183 @@
#!/bin/bash
# configure script adapter for Meson
# Based on build-api: https://github.com/cgwalters/build-api
# Copyright 2010, 2011, 2013 Colin Walters <walters@verbum.org>
# Copyright 2016, 2017 Emmanuele Bassi
# Copyright 2017 Iñigo Martínez <inigomartinez@gmail.com>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# Build API variables:
# Little helper function for reading args from the commandline.
# it automatically handles -a b and -a=b variants, and returns 1 if
# we need to shift $3.
read_arg() {
# $1 = arg name
# $2 = arg value
# $3 = arg parameter
local rematch='^[^=]*=(.*)$'
if [[ $2 =~ $rematch ]]; then
read "$1" <<< "${BASH_REMATCH[1]}"
else
read "$1" <<< "$3"
# There is no way to shift our callers args, so
# return 1 to indicate they should do it instead.
return 1
fi
}
sanitycheck() {
# $1 = arg name
# $1 = arg command
# $2 = arg alternates
local cmd=$( which $2 2>/dev/null )
if [ -x "$cmd" ]; then
read "$1" <<< "$cmd"
return 0
fi
test -z $3 || {
for alt in $3; do
cmd=$( which $alt 2>/dev/null )
if [ -x "$cmd" ]; then
read "$1" <<< "$cmd"
return 0
fi
done
}
echo -e "\e[1;31mERROR\e[0m: Command '$2' not found"
exit 1
}
checkoption() {
# $1 = arg
option="${1#*--}"
action="${option%%-*}"
name="${option#*-}"
if [ ${default_options[$name]+_} ]; then
case "$action" in
enable) meson_options[$name]=true;;
disable) meson_options[$name]=false;;
*) echo -e "\e[1;33mINFO\e[0m: Ignoring unknown action '$action'";;
esac
else
echo -e "\e[1;33mINFO\e[0m: Ignoring unknown option '$option'"
fi
}
echooption() {
# $1 = option
if [ ${meson_options[$1]+_} ]; then
echo ${meson_options[$1]}
elif [ ${default_options[$1]+_} ]; then
echo ${default_options[$1]}
fi
}
sanitycheck MESON 'meson'
sanitycheck MESONTEST 'mesontest'
sanitycheck NINJA 'ninja' 'ninja-build'
declare -A default_options=(
['introspection']=true
)
declare -A meson_options
while (($# > 0)); do
case "${1%%=*}" in
--prefix) read_arg prefix "$@" || shift;;
--bindir) read_arg bindir "$@" || shift;;
--sbindir) read_arg sbindir "$@" || shift;;
--libexecdir) read_arg libexecdir "$@" || shift;;
--datarootdir) read_arg datarootdir "$@" || shift;;
--datadir) read_arg datadir "$@" || shift;;
--sysconfdir) read_arg sysconfdir "$@" || shift;;
--libdir) read_arg libdir "$@" || shift;;
--mandir) read_arg mandir "$@" || shift;;
--includedir) read_arg includedir "$@" || shift;;
*) checkoption $1;;
esac
shift
done
# Defaults
test -z ${prefix} && prefix="/usr/local"
test -z ${bindir} && bindir=${prefix}/bin
test -z ${sbindir} && sbindir=${prefix}/sbin
test -z ${libexecdir} && libexecdir=${prefix}/bin
test -z ${datarootdir} && datarootdir=${prefix}/share
test -z ${datadir} && datadir=${datarootdir}
test -z ${sysconfdir} && sysconfdir=${prefix}/etc
test -z ${libdir} && libdir=${prefix}/lib
test -z ${mandir} && mandir=${prefix}/share/man
test -z ${includedir} && includedir=${prefix}/include
# The source directory is the location of this file
srcdir=$(dirname $0)
# The build directory is the current location
builddir=`pwd`
# If we're calling this file from the source directory then
# we automatically create a build directory and ensure that
# both Meson and Ninja invocations are relative to that
# location
if [[ -f "${builddir}/meson.build" ]]; then
mkdir -p _build
builddir="${builddir}/_build"
NINJA_OPT="-C ${builddir}"
fi
# Wrapper Makefile for Ninja
cat > Makefile <<END
# Generated by configure; do not edit
all:
${NINJA} ${NINJA_OPT} cargo
install:
DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
uninstall:
${NINJA} ${NINJA_OPT} uninstall
check:
${MESONTEST} ${NINJA_OPT}
END
echo "
fractal
=======
meson: ${MESON}
ninja: ${NINJA}
prefix: ${prefix}
compiler: ${CC}
global flags: ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
introspection: $(echooption introspection)
Now type 'make' to build
"
cmd_options=""
for key in "${!meson_options[@]}"; do
cmd_options="$cmd_options -Denable-$key=${meson_options[$key]}"
done
exec ${MESON} \
--prefix=${prefix} \
--libdir=${libdir} \
--libexecdir=${libexecdir} \
--datadir=${datadir} \
--sysconfdir=${sysconfdir} \
--bindir=${bindir} \
--includedir=${includedir} \
--mandir=${mandir} \
${cmd_options} \
${builddir} \
${srcdir}

30
meson.build Normal file
View file

@ -0,0 +1,30 @@
project(
'fractal', 'rust',
version: '0.1.0',
license: 'GPLv3',
)
fractal_version = meson.project_version()
version_array = fractal_version.split('.')
fractal_major_version = version_array[0].to_int()
fractal_minor_version = version_array[1].to_int()
fractal_version_micro = version_array[2].to_int()
fractal_prefix = get_option('prefix')
fractal_datadir = join_paths(fractal_prefix, get_option('datadir'), 'fractal')
fractal_bindir = join_paths(fractal_prefix, get_option('bindir'))
install_data('res/app.css', install_dir : fractal_datadir)
install_data('res/fractal.svg', install_dir : fractal_datadir)
install_data('res/main_window.glade', install_dir : fractal_datadir)
install_data('res/fractal.svg', install_dir : get_option('datadir') + '/icons')
install_data('res/org.gnome.Fractal.desktop', install_dir : get_option('datadir') + '/applications')
cargo = find_program('cargo')
cargo_release = custom_target('cargo-build',
output: ['fractal'],
install: false,
command: ['FRACTAL_RES=' + fractal_datadir, cargo, 'build', '--release'])
run_target('cargo', command: 'scripts/cargo.sh', depends: [cargo_release])
install_data('target/release/fractal', install_dir : fractal_bindir)

View file

Before

Width:  |  Height:  |  Size: 7 KiB

After

Width:  |  Height:  |  Size: 7 KiB

View file

@ -0,0 +1,11 @@
[Desktop Entry]
Name=Fractal
Comment=Fractal is a decentralized, secure messaging client for collaborative group communication.
GenericName=Fractal group messaging
Exec=fractal
Icon=fractal
Type=Application
StartupNotify=true
X-GNOME-UsesNotifications=true
Categories=GNOME;GTK;Network;Matrix.org;
Keywords=Matrix;matrix.org;

3
scripts/cargo.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
echo "build completed"

View file

@ -40,6 +40,9 @@ use widgets;
use cache;
include!(concat!(env!("OUT_DIR"), "/config.rs"));
#[derive(Debug)]
pub enum Error {
SecretServiceError,
@ -1218,7 +1221,7 @@ impl App {
let bk = Backend::new(tx);
let apptx = bk.run();
let gtk_builder = gtk::Builder::new_from_file("res/main_window.glade");
let gtk_builder = gtk::Builder::new_from_file(&config::datadir("main_window.glade"));
let op = Arc::new(Mutex::new(AppOp {
gtk_builder: gtk_builder.clone(),
load_more_btn: gtk::Button::new_with_label("Load more messages"),
@ -1373,7 +1376,7 @@ impl App {
.expect("Couldn't find main_window in ui file.");
window.set_title("Fractal");
let _ = window.set_icon_from_file("res/icon.svg");
let _ = window.set_icon_from_file(&config::datadir("fractal.svg"));
window.show_all();
let op = self.op.clone();
@ -1682,8 +1685,8 @@ impl App {
glib::set_prgname(Some("fractal"));
let provider = gtk::CssProvider::new();
let uri = "res/app.css";
if let Err(_) = provider.load_from_path(uri) {
let uri = config::datadir("app.css");
if let Err(_) = provider.load_from_path(&uri) {
println!("Error: Failed to add application style");
}
gtk::StyleContext::add_provider_for_screen(&gdk::Screen::get_default().unwrap(), &provider, 600);