Add clean target for rust projects

master
Jos van den Oever 2017-08-12 14:03:11 +02:00
parent d1d0fc1277
commit b57ece2caf
6 changed files with 470 additions and 0 deletions

View File

@ -47,6 +47,7 @@ endif()
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/testinterface.rs"
"${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/testimplementation.rs"
"${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/types.rs"
COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json"
DEPENDS rust_qt_binding_generator bindings.json

View File

@ -0,0 +1,295 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
use std::ptr::null;
use testimplementation::*;
pub struct PersonQObject {}
#[derive (Clone)]
pub struct PersonEmitter {
qobject: Arc<Mutex<*const PersonQObject>>,
user_name_changed: fn(*const PersonQObject),
age_changed: fn(*const PersonQObject),
active_changed: fn(*const PersonQObject),
misc_changed: fn(*const PersonQObject),
icon_changed: fn(*const PersonQObject),
}
unsafe impl Send for PersonEmitter {}
impl PersonEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
pub fn user_name_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.user_name_changed)(ptr);
}
}
pub fn age_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.age_changed)(ptr);
}
}
pub fn active_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.active_changed)(ptr);
}
}
pub fn misc_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.misc_changed)(ptr);
}
}
pub fn icon_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.icon_changed)(ptr);
}
}
}
pub trait PersonTrait {
fn create(emit: PersonEmitter) -> Self;
fn emit(&self) -> &PersonEmitter;
fn get_user_name(&self) -> String;
fn set_user_name(&mut self, value: String);
fn get_age(&self) -> c_int;
fn get_active(&self) -> bool;
fn set_active(&mut self, value: bool);
fn get_misc(&self) -> Variant;
fn set_misc(&mut self, value: Variant);
fn get_icon(&self) -> Vec<u8>;
fn set_icon(&mut self, value: Vec<u8>);
}
#[no_mangle]
pub extern "C" fn person_new(qobject: *const PersonQObject,
user_name_changed: fn(*const PersonQObject),
age_changed: fn(*const PersonQObject),
active_changed: fn(*const PersonQObject),
misc_changed: fn(*const PersonQObject),
icon_changed: fn(*const PersonQObject))
-> *mut Person {
let emit = PersonEmitter {
qobject: Arc::new(Mutex::new(qobject)),
user_name_changed: user_name_changed,
age_changed: age_changed,
active_changed: active_changed,
misc_changed: misc_changed,
icon_changed: icon_changed,
};
let d = Person::create(emit);
Box::into_raw(Box::new(d))
}
#[no_mangle]
pub unsafe extern "C" fn person_free(ptr: *mut Person) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn person_user_name_get(ptr: *const Person,
p: *mut c_void,
set: fn(*mut c_void, QString)) {
let data = (&*ptr).get_user_name();
set(p, QString::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn person_user_name_set(ptr: *mut Person, v: QStringIn) {
(&mut *ptr).set_user_name(v.convert());
}
#[no_mangle]
pub unsafe extern "C" fn person_age_get(ptr: *const Person) -> c_int {
(&*ptr).get_age()
}
#[no_mangle]
pub unsafe extern "C" fn person_active_get(ptr: *const Person) -> bool {
(&*ptr).get_active()
}
#[no_mangle]
pub unsafe extern "C" fn person_active_set(ptr: *mut Person, v: bool) {
(&mut *ptr).set_active(v);
}
#[no_mangle]
pub unsafe extern "C" fn person_misc_get(ptr: *const Person,
p: *mut c_void,
set: fn(*mut c_void, QVariant)) {
let data = (&*ptr).get_misc();
set(p, QVariant::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn person_misc_set(ptr: *mut Person, v: QVariant) {
(&mut *ptr).set_misc(v.convert());
}
#[no_mangle]
pub unsafe extern "C" fn person_icon_get(ptr: *const Person,
p: *mut c_void,
set: fn(*mut c_void, QByteArray)) {
let data = (&*ptr).get_icon();
set(p, QByteArray::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn person_icon_set(ptr: *mut Person, v: QByteArray) {
(&mut *ptr).set_icon(v.convert());
}
pub struct DirectoryQObject {}
#[derive (Clone)]
pub struct DirectoryEmitter {
qobject: Arc<Mutex<*const DirectoryQObject>>,
path_changed: fn(*const DirectoryQObject),
}
unsafe impl Send for DirectoryEmitter {}
impl DirectoryEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
pub fn path_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.path_changed)(ptr);
}
}
}
pub struct DirectoryList {
qobject: *const DirectoryQObject,
directory_begin_insert_rows: fn(*const DirectoryQObject, c_int, c_int),
directory_end_insert_rows: fn(*const DirectoryQObject),
directory_begin_remove_rows: fn(*const DirectoryQObject, c_int, c_int),
directory_end_remove_rows: fn(*const DirectoryQObject),
}
impl DirectoryList {
pub fn directory_begin_insert_rows(&self, first: c_int, last: c_int) {
(self.directory_begin_insert_rows)(self.qobject, first, last);
}
pub fn directory_end_insert_rows(&self) {
(self.directory_end_insert_rows)(self.qobject);
}
pub fn directory_begin_remove_rows(&self, first: c_int, last: c_int) {
(self.directory_begin_remove_rows)(self.qobject, first, last);
}
pub fn directory_end_remove_rows(&self) {
(self.directory_end_remove_rows)(self.qobject);
}
}
pub trait DirectoryTrait {
fn create(emit: DirectoryEmitter, model: DirectoryList) -> Self;
fn emit(&self) -> &DirectoryEmitter;
fn get_path(&self) -> String;
fn set_path(&mut self, value: String);
fn row_count(&self) -> c_int;
fn file_icon(&self, row: c_int) -> Variant;
fn file_path(&self, row: c_int) -> Variant;
fn file_name(&self, row: c_int) -> Variant;
fn file_permissions(&self, row: c_int) -> Variant;
}
#[no_mangle]
pub extern "C" fn directory_new(qobject: *const DirectoryQObject,
path_changed: fn(*const DirectoryQObject),
directory_begin_insert_rows: fn(*const DirectoryQObject,
c_int,
c_int),
directory_end_insert_rows: fn(*const DirectoryQObject),
directory_begin_remove_rows: fn(*const DirectoryQObject,
c_int,
c_int),
directory_end_remove_rows: fn(*const DirectoryQObject))
-> *mut Directory {
let emit = DirectoryEmitter {
qobject: Arc::new(Mutex::new(qobject)),
path_changed: path_changed,
};
let model = DirectoryList {
qobject: qobject,
directory_begin_insert_rows: directory_begin_insert_rows,
directory_end_insert_rows: directory_end_insert_rows,
directory_begin_remove_rows: directory_begin_remove_rows,
directory_end_remove_rows: directory_end_remove_rows,
};
let d = Directory::create(emit, model);
Box::into_raw(Box::new(d))
}
#[no_mangle]
pub unsafe extern "C" fn directory_free(ptr: *mut Directory) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn directory_path_get(ptr: *const Directory,
p: *mut c_void,
set: fn(*mut c_void, QString)) {
let data = (&*ptr).get_path();
set(p, QString::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn directory_path_set(ptr: *mut Directory, v: QStringIn) {
(&mut *ptr).set_path(v.convert());
}
#[no_mangle]
pub unsafe extern "C" fn directory_row_count(ptr: *const Directory) -> c_int {
(&*ptr).row_count()
}
#[no_mangle]
pub unsafe extern "C" fn directory_data_file_icon(ptr: *const Directory,
row: c_int,
d: *mut c_void,
set: fn(*mut c_void, &QVariant)) {
let data = (& *ptr).file_icon(row);
set(d, &QVariant::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn directory_data_file_path(ptr: *const Directory,
row: c_int,
d: *mut c_void,
set: fn(*mut c_void, &QVariant)) {
let data = (& *ptr).file_path(row);
set(d, &QVariant::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn directory_data_file_name(ptr: *const Directory,
row: c_int,
d: *mut c_void,
set: fn(*mut c_void, &QVariant)) {
let data = (& *ptr).file_name(row);
set(d, &QVariant::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn directory_data_file_permissions(ptr: *const Directory,
row: c_int,
d: *mut c_void,
set: fn(*mut c_void, &QVariant)) {
let data = (& *ptr).file_permissions(row);
set(d, &QVariant::from(&data));
}

View File

@ -2,6 +2,8 @@ enable_testing()
SET(GENERATOR "${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator")
add_custom_target("clean-rust")
function(rust_test NAME DIRECTORY)
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}")
set(DIR "${SRC}/${DIRECTORY}")
@ -46,6 +48,15 @@ function(rust_test NAME DIRECTORY)
add_test("${NAME}" "${NAME}")
set_tests_properties("${NAME}" PROPERTIES DEPENDS "build_${NAME}")
add_custom_command(
OUTPUT "clean_${NAME}"
COMMAND cargo clean
WORKING_DIRECTORY "${DIR}"
)
add_custom_target("clean-${NAME}" DEPENDS "clean_${NAME}")
add_dependencies("clean-rust" "clean-${NAME}")
endfunction(rust_test)
rust_test(test_object rust_object)

View File

@ -0,0 +1,68 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
use std::ptr::null;
use implementation::*;
pub struct PersonQObject {}
#[derive (Clone)]
pub struct PersonEmitter {
qobject: Arc<Mutex<*const PersonQObject>>,
user_name_changed: fn(*const PersonQObject),
}
unsafe impl Send for PersonEmitter {}
impl PersonEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
pub fn user_name_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.user_name_changed)(ptr);
}
}
}
pub trait PersonTrait {
fn create(emit: PersonEmitter) -> Self;
fn emit(&self) -> &PersonEmitter;
fn get_user_name(&self) -> String;
fn set_user_name(&mut self, value: String);
}
#[no_mangle]
pub extern "C" fn person_new(qobject: *const PersonQObject,
user_name_changed: fn(*const PersonQObject))
-> *mut Person {
let emit = PersonEmitter {
qobject: Arc::new(Mutex::new(qobject)),
user_name_changed: user_name_changed,
};
let d = Person::create(emit);
Box::into_raw(Box::new(d))
}
#[no_mangle]
pub unsafe extern "C" fn person_free(ptr: *mut Person) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn person_user_name_get(ptr: *const Person,
p: *mut c_void,
set: fn(*mut c_void, QString)) {
let data = (&*ptr).get_user_name();
set(p, QString::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn person_user_name_set(ptr: *mut Person, v: QStringIn) {
(&mut *ptr).set_user_name(v.convert());
}

View File

@ -0,0 +1,27 @@
use libc::c_int;
use types::*;
use interface::*;
pub struct Object {
emit: ObjectEmitter,
value: Variant,
}
impl ObjectTrait for Object {
fn create(emit: ObjectEmitter) -> Object {
Object {
emit: emit,
value: Variant::None,
}
}
fn emit(&self) -> &ObjectEmitter {
&self.emit
}
fn get_value(&self) -> Variant {
self.value.clone()
}
fn set_value(&mut self, value: Variant) {
self.value = value;
self.emit.value_changed();
}
}

View File

@ -0,0 +1,68 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
use std::ptr::null;
use implementation::*;
pub struct ObjectQObject {}
#[derive (Clone)]
pub struct ObjectEmitter {
qobject: Arc<Mutex<*const ObjectQObject>>,
value_changed: fn(*const ObjectQObject),
}
unsafe impl Send for ObjectEmitter {}
impl ObjectEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
pub fn value_changed(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.value_changed)(ptr);
}
}
}
pub trait ObjectTrait {
fn create(emit: ObjectEmitter) -> Self;
fn emit(&self) -> &ObjectEmitter;
fn get_value(&self) -> Variant;
fn set_value(&mut self, value: Variant);
}
#[no_mangle]
pub extern "C" fn object_new(qobject: *const ObjectQObject,
value_changed: fn(*const ObjectQObject))
-> *mut Object {
let emit = ObjectEmitter {
qobject: Arc::new(Mutex::new(qobject)),
value_changed: value_changed,
};
let d = Object::create(emit);
Box::into_raw(Box::new(d))
}
#[no_mangle]
pub unsafe extern "C" fn object_free(ptr: *mut Object) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn object_value_get(ptr: *const Object,
p: *mut c_void,
set: fn(*mut c_void, QVariant)) {
let data = (&*ptr).get_value();
set(p, QVariant::from(&data));
}
#[no_mangle]
pub unsafe extern "C" fn object_value_set(ptr: *mut Object, v: QVariant) {
(&mut *ptr).set_value(v.convert());
}