Commit c562310f authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui Committed by Christian Hergert

Meson Templates: Add Rust GNOME Application template

Currently, gtk-rs doesn't fully support subclassing which explains the various changes on window.ui
parent 026aaf97
......@@ -10,6 +10,7 @@
<file compressed="true">resources/src/hello-version.h.in</file>
<file compressed="true">resources/src/meson-clib.build</file>
<file compressed="true">resources/src/meson-js.build</file>
<file compressed="true">resources/src/meson-rs.build</file>
<file compressed="true">resources/src/hello.c</file>
<file compressed="true">resources/src/hello.h</file>
<file compressed="true">resources/src/__init__.py</file>
......@@ -25,13 +26,18 @@
<file compressed="true">resources/src/window.hpp</file>
<file compressed="true">resources/src/window.py</file>
<file compressed="true">resources/src/window.vala</file>
<file compressed="true">resources/src/config.rs.in</file>
<file compressed="true">resources/src/window.rs</file>
<file compressed="true">resources/src/main.vala</file>
<file compressed="true">resources/src/main-cli.vala</file>
<file compressed="true">resources/src/hello.py.in</file>
<file compressed="true">resources/src/main.py</file>
<file compressed="true">resources/src/main.rs</file>
<file compressed="true">resources/src/application.in</file>
<file compressed="true">resources/src/main.cs</file>
<file compressed="true">resources/src/Cargo.toml</file>
<file compressed="true">resources/src/meson-cs.build</file>
<file compressed="true">resources/build-aux/cargo.sh</file>
<file compressed="true">resources/build-aux/meson/postinstall.py</file>
<file compressed="true">resources/meson.build</file>
<file compressed="true">resources/src/meson-cli.build</file>
......
......@@ -102,7 +102,7 @@ class MesonTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
else:
self.language = 'c'
if self.language not in ('c', 'c♯', 'c++', 'javascript', 'python', 'vala'):
if self.language not in ('c', 'c♯', 'c++', 'javascript', 'python', 'vala', 'rust'):
task.return_error(GLib.Error('Language %s not supported' % self.language))
return
......@@ -249,7 +249,7 @@ class GnomeProjectTemplate(MesonTemplate):
_('GNOME Application'),
'pattern-gnome',
_('Create a new GNOME application'),
['C', 'C++', 'C♯', 'Python', 'JavaScript', 'Vala'],
['C', 'C++', 'C♯', 'Python', 'JavaScript', 'Vala', 'Rust'],
0
)
......@@ -301,6 +301,13 @@ class GnomeProjectTemplate(MesonTemplate):
files['resources/src/window.py'] = 'src/window.py'
files['resources/src/main.py'] = 'src/main.py'
meson_file = 'resources/src/meson-py.build'
elif self.language == 'rust':
files['resources/src/config.rs.in'] = 'src/config.rs.in'
files['resources/src/main.rs'] = 'src/main.rs'
files['resources/src/window.rs'] = 'src/window.rs'
files['resources/src/Cargo.toml'] = 'Cargo.toml'
files['resources/build-aux/cargo.sh'] = 'build-aux/cargo.sh'
meson_file = 'resources/src/meson-rs.build'
if resource_name:
files['resources/src/hello.gresource.xml'] = resource_name
......
#!/bin/sh
export MESON_BUILD_ROOT="$1"
export MESON_SOURCE_ROOT="$2"
export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target
export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home
export OUTPUT="$3"
export BUILDTYPE="$4"
export APP_BIN="$5"
if [[ $BUILDTYPE = "release" ]]
then
echo "RELEASE MODE"
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --release && \
cp "$CARGO_TARGET_DIR"/release/"$APP_BIN" "$OUTPUT"
else
echo "DEBUG MODE"
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --verbose && \
cp "$CARGO_TARGET_DIR"/debug/"$APP_BIN" "$OUTPUT"
fi
......@@ -3,6 +3,11 @@
"runtime": "org.gnome.Platform",
"runtime-version": "3.32",
"sdk": "org.gnome.Sdk",
{{if language == "rust"}}
"sdk-extensions" : [
"org.freedesktop.Sdk.Extension.rust-stable"
],
{{end}}
"command": "{{exec_name}}",
"finish-args": [
"--share=network",
......@@ -14,13 +19,20 @@
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
{{if language == "rust"}}
"build-options": {
"cflags": "-O2 -g",
"cxxflags": "-O2 -g",
"env": {
"V": "1"
"append-path" : "/usr/lib/sdk/rust-stable/bin",
"build-args" : [
"--share=network"
],
"env" : {
"RUSTFLAGS" : "--remap-path-prefix =../ --error-format=human",
"CARGO_HOME" : "/run/build/{{name}}/cargo",
"RUST_BACKTRACE" : "1",
"RUST_LOG" : "{{name}}=debug"
}
},
{{end}}
"cleanup": [
"/include",
"/lib/pkgconfig",
......
[package]
name = "{{name}}"
version = "0.1.0"
edition = "2018"
[dependencies]
gtk = { version = "0.7", features = ["v3_22"] }
glib = "0.8"
gio = { version = "0.7", features = ["v2_46"] }
gdk = "0.11"
gettext-rs= { version = "0.4", features = ["gettext-system"] }
pub static PKGDATADIR: &'static str = @pkgdatadir@;
pub static VERSION: &'static str = @VERSION@;
pub static LOCALEDIR: &'static str = @localedir@;
\ No newline at end of file
use gtk::prelude::*;
use gio::prelude::*;
use gettextrs::*;
use std::env;
mod config;
mod window;
use crate::window::Window;
fn main() {
gtk::init().unwrap_or_else(|_| panic!("Failed to initialize GTK."));
setlocale(LocaleCategory::LcAll, "");
bindtextdomain("{{name}}", config::LOCALEDIR);
textdomain("{{name}}");
let res = gio::Resource::load(config::PKGDATADIR.to_owned() + "/{{name}}.gresource")
.expect("Could not load resources");
gio::resources_register(&res);
let app = gtk::Application::new(Some("{{appid}}"), Default::default()).unwrap();
app.connect_activate(move |app| {
let window = Window::new();
window.widget.set_application(Some(app));
app.add_window(&window.widget);
window.widget.present();
});
let args: Vec<String> = env::args().collect();
app.run(&args);
}
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
gnome = import('gnome')
gnome.compile_resources('{{name}}',
'{{name}}.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
)
conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
conf.set_quoted('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set_quoted('pkgdatadir', pkgdatadir)
configure_file(
input: 'config.rs.in',
output: 'config.rs',
configuration: conf
)
# Copy the config.rs output to the source directory.
run_command(
'cp',
join_paths(meson.build_root(), 'src', 'config.rs'),
join_paths(meson.source_root(), 'src', 'config.rs'),
check: true
)
sources = files(
'config.rs',
'main.rs',
'window.rs',
)
cargo_script = find_program(join_paths(meson.source_root(), 'build-aux/cargo.sh'))
cargo_release = custom_target(
'cargo-build',
build_by_default: true,
input: sources,
output: meson.project_name(),
console: true,
install: true,
install_dir: get_option('bindir'),
command: [
cargo_script,
meson.build_root(),
meson.source_root(),
'@OUTPUT@',
get_option('buildtype'),
meson.project_name(),
]
)
use gtk::prelude::*;
pub struct Window {
pub widget: gtk::ApplicationWindow,
}
impl Window {
pub fn new() -> Self {
let builder = gtk::Builder::new_from_resource("{{appid_path}}/{{ui_file}}");
let widget: gtk::ApplicationWindow = builder.get_object("window").expect("Failed to find the window object");
Self {
widget,
}
}
}
......@@ -16,7 +16,11 @@
</attributes>
</object>
{{else}}
{{if language == "rust"}}
<object class="GtkApplicationWindow" id="window">
{{else}}
<template class="{{PreFix}}Window" parent="GtkApplicationWindow">
{{end}}
<property name="default-width">600</property>
<property name="default-height">300</property>
<child type="titlebar">
......@@ -40,6 +44,10 @@
</attributes>
</object>
</child>
{{if language == "rust"}}
</object>
{{else}}
</template>
{{end}}
{{end}}
</interface>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment