Skip to content

Commit 4fe8ce3

Browse files
committed
cxx-qt-build: consider the folders in rust path
Closes #855
1 parent 8b809e8 commit 4fe8ce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+80
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- File name is used for CXX bridges rather than module name to match upstream
3636
- `#[qobject]` attribute is now optional on types in `extern "RustQt"`
3737
- `#[qobject]` attribute is now required on types in `extern "C++Qt"`
38+
- Rust bridges which are in folders are now considered by `CxxQtBuilder`
3839

3940
### Fixed
4041

crates/cxx-qt-build/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ struct GeneratedCpp {
6161

6262
impl GeneratedCpp {
6363
/// Generate QObject and cxx header/source C++ file contents
64-
pub fn new(rust_file_path: impl AsRef<Path>) -> Result<Self, Diagnostic> {
64+
pub fn new(
65+
rust_file_path: impl AsRef<Path>,
66+
relative_path: impl AsRef<Path>,
67+
) -> Result<Self, Diagnostic> {
6568
let to_diagnostic = |err| Diagnostic::new(rust_file_path.as_ref().to_owned(), err);
6669

6770
let rust_file_path = rust_file_path.as_ref();
@@ -91,15 +94,16 @@ impl GeneratedCpp {
9194
rust_file_path.display());
9295
}
9396

94-
// Match upstream where they use the file name as the ident
95-
//
96-
// TODO: what happens if there are folders?
97+
// Match upstream where they use the file name and folders as the ident
9798
//
9899
// TODO: ideally CXX-Qt would also use the file name
99100
// https://github.com/KDAB/cxx-qt/pull/200/commits/4861c92e66c3a022d3f0dedd9f8fd20db064b42b
100-
file_ident = rust_file_path
101-
.file_stem()
102-
.unwrap()
101+
//
102+
// We need the relative path here as we want the folders
103+
file_ident = relative_path
104+
.as_ref()
105+
// Remove the .rs extension
106+
.with_extension("")
103107
.to_str()
104108
.unwrap()
105109
.to_owned();
@@ -210,6 +214,10 @@ impl GeneratedCpp {
210214
header_directory.display(),
211215
self.file_ident
212216
));
217+
if let Some(directory) = header_path.parent() {
218+
std::fs::create_dir_all(directory)
219+
.expect("Could not create directory to write cxx-qt generated header files");
220+
}
213221
let mut header = File::create(header_path).expect("Could not create cxx header file");
214222
header
215223
.write_all(&self.cxx.header)
@@ -220,6 +228,10 @@ impl GeneratedCpp {
220228
cpp_directory.display(),
221229
self.file_ident
222230
));
231+
if let Some(directory) = cpp_path.parent() {
232+
std::fs::create_dir_all(directory)
233+
.expect("Could not create directory to write cxx-qt generated source files");
234+
}
223235
let mut cpp = File::create(&cpp_path).expect("Could not create cxx source file");
224236
cpp.write_all(&self.cxx.implementation)
225237
.expect("Could not write cxx source file");
@@ -242,7 +254,7 @@ fn generate_cxxqt_cpp_files(
242254
let path = format!("{manifest_dir}/{}", rs_path.as_ref().display());
243255
println!("cargo:rerun-if-changed={path}");
244256

245-
let generated_code = match GeneratedCpp::new(&path) {
257+
let generated_code = match GeneratedCpp::new(&path, rs_path) {
246258
Ok(v) => v,
247259
Err(diagnostic) => {
248260
diagnostic.report();

crates/cxx-qt-gen/src/writer/cpp/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn write_cpp_header(generated: &GeneratedCppBlocks) -> String {
185185
{includes}
186186
187187
{forward_declare}
188-
#include "cxx-qt-gen/{cxx_file_stem}.cxx.h"
188+
#include "{cxx_file_stem}.cxx.h"
189189
190190
{extern_cxx_qt}
191191
{qobjects}

crates/cxx-qt-gen/src/writer/cpp/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn write_cpp_source(generated: &GeneratedCppBlocks) -> String {
6060
.join("\n");
6161

6262
formatdoc! {r#"
63-
#include "cxx-qt-gen/{cxx_file_stem}.cxxqt.h"
63+
#include "{cxx_file_stem}.cxxqt.h"
6464
6565
{extern_cxx_qt}
6666
{qobjects}

crates/cxx-qt-gen/test_outputs/inheritance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/inheritance.cxxqt.h"
1+
#include "inheritance.cxxqt.h"
22

33
QVariant
44
MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const

crates/cxx-qt-gen/test_outputs/inheritance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class MyObject;
88

9-
#include "cxx-qt-gen/inheritance.cxx.h"
9+
#include "inheritance.cxx.h"
1010

1111
class MyObject
1212
: public QAbstractItemModel

crates/cxx-qt-gen/test_outputs/invokables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/ffi.cxxqt.h"
1+
#include "ffi.cxxqt.h"
22

33
namespace cxx_qt::my_object {
44
void

crates/cxx-qt-gen/test_outputs/invokables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using MyObjectCxxQtThread = ::rust::cxxqt1::CxxQtThread<MyObject>;
1010

1111
} // namespace cxx_qt::my_object
1212

13-
#include "cxx-qt-gen/ffi.cxx.h"
13+
#include "ffi.cxx.h"
1414

1515
namespace cxx_qt::my_object {
1616
class MyObject

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/multi_object.cxxqt.h"
1+
#include "multi_object.cxxqt.h"
22

33
// Define namespace otherwise we hit a GCC bug
44
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ using ExternObjectCxxQtSignalHandlererrorOccurred =
5353
struct ExternObjectCxxQtSignalParamserrorOccurred*>;
5454
} // namespace mynamespace::rust::cxxqtgen1
5555

56-
#include "cxx-qt-gen/multi_object.cxx.h"
56+
#include "multi_object.cxx.h"
5757

5858
namespace rust::cxxqtgen1 {
5959
::QMetaObject::Connection

0 commit comments

Comments
 (0)