Skip to content

Commit

Permalink
Merge branch 'main' into implement_as_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel authored Apr 15, 2024
2 parents a3d74b8 + b13a87a commit 2dd03c8
Show file tree
Hide file tree
Showing 45 changed files with 1,341 additions and 422 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileContributor: Andrew Hayzen <[email protected]>
#
# SPDX-License-Identifier: MIT OR Apache-2.0

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
12 changes: 6 additions & 6 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y clang-format-12
- run: ./clang_format_check.sh .
- run: ./scripts/clang_format_check.sh .

license_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v2
uses: fsfe/reuse-action@v3

rust_format_check:
runs-on: ubuntu-latest
Expand All @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v14
- uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: '**/*.md'

Expand Down Expand Up @@ -229,7 +229,7 @@ jobs:
# key: ${{ matrix.name }}_compiler_cache
- name: "Restore Compiler Cache"
id: compiler-cache-restore
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: ${{ matrix.compiler_cache_path }}
key: ${{ matrix.name }}_compiler_cache
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
# Required for CMake to find Ninja
- name: "[Windows] Set up MSVC Developer Command Prompt"
if: runner.os == 'Windows'
uses: seanmiddleditch/gha-setup-vsdevenv@v3
uses: seanmiddleditch/gha-setup-vsdevenv@v4

# Ninja is required on Windows for CMAKE_CXX_COMPILER_LAUNCHER to work for using sccache.
#
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
# Updating th cache doesn't work from forks
# So update it once it's merged into the repo
if: ${{ github.event_name == 'push' }}
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
path: ${{ matrix.compiler_cache_path }}
key: ${{ matrix.name }}_compiler_cache
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `internal_pointer_mut()` function on `QModelIndex`
- `c_void` in CXX-Qt-lib for easy access to `void *`
- `CxxQtThread` is now marked as `Sync` so that it can be used by reference
- Add cxx-qt-lib-extras crate which contains: `QCommandLineOption`, `QCommandLineParser`, `QElapsedTimer`

### Changed

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ endif()
find_program(MEMORYCHECK_COMMAND valgrind)
if(NOT "${MEMORYCHECK_COMMAND}" STREQUAL "MEMORYCHECK_COMMAND-NOTFOUND")
if (NOT WIN32)
MESSAGE(STATUS "Valgrind found! Tests based on valgrind must be executed.")
MESSAGE(STATUS "Valgrind found! Tests based on valgrind must be executed.")
endif()
endif()

Expand Down Expand Up @@ -242,7 +242,7 @@ add_test(NAME cxx_qt_gen_test_inputs_gen COMMAND rustfmt --check ${CXX_QT_GEN_TE
add_test(NAME cxx_qt_gen_test_outputs_gen COMMAND rustfmt --check ${CXX_QT_GEN_TEST_OUTPUTS})

# Add test which checks that a build rerun doesn't recompile and uses caches instead
add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}")
add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}")

# Ensure that cargo_build_rerun doesn't run while we are already building
set_tests_properties(cargo_build_rerun PROPERTIES RUN_SERIAL TRUE)
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ members = [
"crates/cxx-qt-lib",
"crates/cxx-qt-lib-headers",
"crates/qt-build-utils",
"crates/cxx-qt-lib-extras-headers",
"crates/cxx-qt-lib-extras",

"examples/cargo_without_cmake",
"examples/demo_threading/rust",
Expand Down Expand Up @@ -39,6 +41,8 @@ cxx-qt-gen = { path = "crates/cxx-qt-gen", version = "0.6.0" }
cxx-qt-lib = { path = "crates/cxx-qt-lib", version = "0.6.0" }
cxx-qt-lib-headers = { path = "crates/cxx-qt-lib-headers", version = "0.6.0" }
qt-build-utils = { path = "crates/qt-build-utils", version = "0.6.0" }
cxx-qt-lib-extras-headers = { path = "crates/cxx-qt-lib-extras-headers", version = "0.6.0" }
cxx-qt-lib-extras = { path = "crates/cxx-qt-lib-extras", version = "0.6.0" }

cc = { version = "1.0.86", features = ["parallel"] }
# Ensure that the example comments are kept in sync
Expand Down
4 changes: 1 addition & 3 deletions crates/cxx-qt-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,11 @@ impl CxxQtBuilder {
for builder in [&mut self.cc_builder, &mut cc_builder_whole_archive] {
// Note, ensure our settings stay in sync across cxx-qt, cxx-qt-build, and cxx-qt-lib
builder.cpp(true);
builder.std("c++17");
// MSVC
builder.flag_if_supported("/std:c++17");
builder.flag_if_supported("/Zc:__cplusplus");
builder.flag_if_supported("/permissive-");
builder.flag_if_supported("/bigobj");
// GCC + Clang
builder.flag_if_supported("-std=c++17");
// MinGW requires big-obj otherwise debug builds fail
builder.flag_if_supported("-Wa,-mbig-obj");

Expand Down
72 changes: 38 additions & 34 deletions crates/cxx-qt-gen/src/generator/rust/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn generate(

let qobject_name = &qobject_idents.cpp_class.cpp;
let qobject_name_rust = &qobject_idents.cpp_class.rust;
let qobject_name_rust_qualified = type_names.rust_qualified(qobject_name_rust);
let qobject_name_rust_qualified = type_names.rust_qualified(qobject_name_rust)?;
let qobject_name_snake = qobject_name.to_string().to_case(Case::Snake);

let rust_struct_name_rust = &qobject_idents.rust_struct.rust;
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn generate(
.arguments
.iter()
.map(|arg| syn_type_cxx_bridge_to_qualified(arg, type_names))
.collect();
.collect::<Result<_>>()?;

let route_arguments_parameters: Vec<FnArg> = constructor
.arguments
Expand All @@ -272,13 +272,13 @@ pub fn generate(
let route_arguments_parameter_qualified: Vec<FnArg> = route_arguments_parameters
.iter()
.cloned()
.map(|mut parameter| {
.map(|mut parameter| -> Result<_> {
if let FnArg::Typed(pat_type) = &mut parameter {
*pat_type.ty = syn_type_cxx_bridge_to_qualified(&pat_type.ty, type_names);
*pat_type.ty = syn_type_cxx_bridge_to_qualified(&pat_type.ty, type_names)?;
}
parameter
Ok(parameter)
})
.collect();
.collect::<Result<_>>()?;

// As the function implementations cast to `Constructor<(Args)>`, these `Args` may
// include the lifetime.
Expand Down Expand Up @@ -461,16 +461,20 @@ mod tests {
}

fn mock_namespace() -> NamespaceName {
NamespaceName::from_pair_str("ffi", &format_ident!("MyObject"))
NamespaceName::from_pair_str("qobject", &format_ident!("MyObject"))
}

fn generate_mocked(constructors: &[Constructor]) -> GeneratedRustFragment {
let mut type_names = TypeNames::mock();

type_names.insert("QString", None, None, None);
type_names.insert("QObject", None, None, None);
generate(
constructors,
&mock_name(),
&mock_namespace(),
&TypeNames::default(),
&format_ident!("ffi"),
&type_names,
&format_ident!("qobject"),
)
.unwrap()
}
Expand All @@ -487,7 +491,7 @@ mod tests {
quote! {
extern "Rust" {
#[cxx_name="createRs"]
#[namespace="ffi::cxx_qt_my_object"]
#[namespace="qobject::cxx_qt_my_object"]
fn create_rs_my_object_rust() -> Box<MyObjectRust>;
}
},
Expand All @@ -513,7 +517,7 @@ mod tests {
assert_tokens_eq(
tokens,
quote! {
#[namespace = "ffi::cxx_qt_my_object"]
#[namespace = "qobject::cxx_qt_my_object"]
#[cxx_name = #cxx_name]
#[doc(hidden)]
struct #rust_name {
Expand Down Expand Up @@ -583,17 +587,17 @@ mod tests {
&blocks.cxx_qt_mod_contents[0],
quote! {
#[doc(hidden)]
pub fn route_arguments_my_object_0() -> ffi::CxxQtConstructorArgumentsMyObject0
pub fn route_arguments_my_object_0() -> qobject::CxxQtConstructorArgumentsMyObject0
{
#[allow(unused_variables)]
#[allow(clippy::let_unit_value)]
let (new_arguments, base_arguments, initialize_arguments) =
<MyObject as cxx_qt::Constructor<()> >::route_arguments(());
<qobject::MyObject as cxx_qt::Constructor<()> >::route_arguments(());

ffi::CxxQtConstructorArgumentsMyObject0 {
base: ffi::CxxQtConstructorBaseArgumentsMyObject0 { not_empty: 0 },
initialize: ffi::CxxQtConstructorInitializeArgumentsMyObject0 { not_empty: 0 },
new: ffi::CxxQtConstructorNewArgumentsMyObject0 { not_empty : 0 },
qobject::CxxQtConstructorArgumentsMyObject0 {
base: qobject::CxxQtConstructorBaseArgumentsMyObject0 { not_empty: 0 },
initialize: qobject::CxxQtConstructorInitializeArgumentsMyObject0 { not_empty: 0 },
new: qobject::CxxQtConstructorNewArgumentsMyObject0 { not_empty : 0 },
}
}
},
Expand All @@ -604,9 +608,9 @@ mod tests {
#[doc(hidden)]
#[allow(unused_variables)]
#[allow(clippy::extra_unused_lifetimes)]
pub fn new_rs_my_object_0(new_arguments: ffi::CxxQtConstructorNewArgumentsMyObject0) -> std::boxed::Box<MyObjectRust> {
pub fn new_rs_my_object_0(new_arguments: qobject::CxxQtConstructorNewArgumentsMyObject0) -> std::boxed::Box<MyObjectRust> {
std::boxed::Box::new(
<MyObject as cxx_qt::Constructor<()> >::new(())
<qobject::MyObject as cxx_qt::Constructor<()> >::new(())
)
}
},
Expand All @@ -618,10 +622,10 @@ mod tests {
#[allow(unused_variables)]
#[allow(clippy::extra_unused_lifetimes)]
pub fn initialize_my_object_0(
qobject: core::pin::Pin<&mut MyObject>,
initialize_arguments: ffi::CxxQtConstructorInitializeArgumentsMyObject0)
qobject: core::pin::Pin<&mut qobject::MyObject>,
initialize_arguments: qobject::CxxQtConstructorInitializeArgumentsMyObject0)
{
<MyObject as cxx_qt::Constructor<()> >::initialize(qobject, ());
<qobject::MyObject as cxx_qt::Constructor<()> >::initialize(qobject, ());
}
},
);
Expand Down Expand Up @@ -707,24 +711,24 @@ mod tests {
&blocks.cxx_qt_mod_contents[3],
quote! {
#[doc(hidden)]
pub fn route_arguments_my_object_1<'lifetime>(arg0: *const QObject) -> ffi::CxxQtConstructorArgumentsMyObject1<'lifetime>
pub fn route_arguments_my_object_1<'lifetime>(arg0: *const QObject) -> qobject::CxxQtConstructorArgumentsMyObject1<'lifetime>
{
#[allow(unused_variables)]
#[allow(clippy::let_unit_value)]
let (new_arguments, base_arguments, initialize_arguments) =
<MyObject as cxx_qt::Constructor<(*const QObject,)> >::route_arguments((arg0,));
<qobject::MyObject as cxx_qt::Constructor<(*const QObject,)> >::route_arguments((arg0,));

ffi::CxxQtConstructorArgumentsMyObject1 {
base: ffi::CxxQtConstructorBaseArgumentsMyObject1 {
qobject::CxxQtConstructorArgumentsMyObject1 {
base: qobject::CxxQtConstructorBaseArgumentsMyObject1 {
arg0: base_arguments.0,
arg1: base_arguments.1,
arg2: base_arguments.2,
},
initialize: ffi::CxxQtConstructorInitializeArgumentsMyObject1 {
initialize: qobject::CxxQtConstructorInitializeArgumentsMyObject1 {
arg0: initialize_arguments.0,
arg1: initialize_arguments.1,
},
new: ffi::CxxQtConstructorNewArgumentsMyObject1 {
new: qobject::CxxQtConstructorNewArgumentsMyObject1 {
arg0: new_arguments.0,
},
}
Expand All @@ -737,9 +741,9 @@ mod tests {
#[doc(hidden)]
#[allow(unused_variables)]
#[allow(clippy::extra_unused_lifetimes)]
pub fn new_rs_my_object_1(new_arguments: ffi::CxxQtConstructorNewArgumentsMyObject1) -> std::boxed::Box<MyObjectRust> {
pub fn new_rs_my_object_1(new_arguments: qobject::CxxQtConstructorNewArgumentsMyObject1) -> std::boxed::Box<MyObjectRust> {
std::boxed::Box::new(
<MyObject as cxx_qt::Constructor<(*const QObject,)> >::new(
<qobject::MyObject as cxx_qt::Constructor<(*const QObject,)> >::new(
(new_arguments.arg0,)))
}
},
Expand All @@ -751,10 +755,10 @@ mod tests {
#[allow(unused_variables)]
#[allow(clippy::extra_unused_lifetimes)]
pub fn initialize_my_object_1<'lifetime>(
qobject: core::pin::Pin<&mut MyObject>,
initialize_arguments: ffi::CxxQtConstructorInitializeArgumentsMyObject1<'lifetime>)
qobject: core::pin::Pin<&mut qobject::MyObject>,
initialize_arguments: qobject::CxxQtConstructorInitializeArgumentsMyObject1<'lifetime>)
{
<MyObject as cxx_qt::Constructor<(*const QObject,)> >::initialize(
<qobject::MyObject as cxx_qt::Constructor<(*const QObject,)> >::initialize(
qobject,
(initialize_arguments.arg0, initialize_arguments.arg1,));
}
Expand Down Expand Up @@ -787,7 +791,7 @@ mod tests {
assert_eq!(blocks.cxx_qt_mod_contents.len(), 6);

let namespace_attr = quote! {
#[namespace = "ffi::cxx_qt_my_object"]
#[namespace = "qobject::cxx_qt_my_object"]
};

assert_empty_constructor_blocks(&blocks, &namespace_attr);
Expand Down
8 changes: 4 additions & 4 deletions crates/cxx-qt-gen/src/generator/rust/cxxqttype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn generate(

let cpp_struct_ident = &qobject_ident.cpp_class.rust;
let rust_struct_ident = &qobject_ident.rust_struct.rust;
let qualified_impl = type_names.rust_qualified(cpp_struct_ident);
let qualified_impl = type_names.rust_qualified(cpp_struct_ident)?;

let fragment = RustFragmentPair {
cxx_bridge: vec![
Expand Down Expand Up @@ -88,7 +88,7 @@ mod tests {
let qobject = create_parsed_qobject();
let qobject_idents = QObjectName::from(&qobject);

let generated = generate(&qobject_idents, &TypeNames::default()).unwrap();
let generated = generate(&qobject_idents, &TypeNames::mock()).unwrap();

assert_eq!(generated.cxx_mod_contents.len(), 2);
assert_eq!(generated.cxx_qt_mod_contents.len(), 2);
Expand Down Expand Up @@ -120,7 +120,7 @@ mod tests {
assert_tokens_eq(
&generated.cxx_qt_mod_contents[0],
quote! {
impl core::ops::Deref for MyObject {
impl core::ops::Deref for qobject::MyObject {
type Target = MyObjectRust;

fn deref(&self) -> &Self::Target {
Expand All @@ -132,7 +132,7 @@ mod tests {
assert_tokens_eq(
&generated.cxx_qt_mod_contents[1],
quote! {
impl cxx_qt::CxxQtType for MyObject {
impl cxx_qt::CxxQtType for qobject::MyObject {
type Rust = MyObjectRust;

fn rust(&self) -> &Self::Rust {
Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/src/generator/rust/property/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ use crate::{
naming::TypeNames,
};
use quote::quote;
use syn::Type;
use syn::{Result, Type};

pub fn generate(
idents: &QPropertyName,
qobject_idents: &QObjectName,
cxx_ty: &Type,
type_names: &TypeNames,
) -> RustFragmentPair {
) -> Result<RustFragmentPair> {
let cpp_class_name_rust = &qobject_idents.cpp_class.rust;
let getter_wrapper_cpp = idents.getter_wrapper.cpp.to_string();
let getter_rust = &idents.getter.rust;
let ident = &idents.name.rust;
let ident_str = ident.to_string();
let qualified_ty = syn_type_cxx_bridge_to_qualified(cxx_ty, type_names);
let qualified_impl = type_names.rust_qualified(cpp_class_name_rust);
let qualified_ty = syn_type_cxx_bridge_to_qualified(cxx_ty, type_names)?;
let qualified_impl = type_names.rust_qualified(cpp_class_name_rust)?;

RustFragmentPair {
Ok(RustFragmentPair {
cxx_bridge: vec![quote! {
extern "Rust" {
#[cxx_name = #getter_wrapper_cpp]
Expand All @@ -44,5 +44,5 @@ pub fn generate(
}
}
}],
}
})
}
Loading

0 comments on commit 2dd03c8

Please sign in to comment.