Skip to content

Commit 24e624b

Browse files
committed
WIP: cxx-qt-build: include headers directory manually
1 parent ba76e47 commit 24e624b

File tree

15 files changed

+26
-93
lines changed

15 files changed

+26
-93
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ impl Interface {
139139
.expect("Failed to create header root for interface");
140140
for (header_dir, dest) in &self.exported_include_directories {
141141
let dest_dir = header_root_interface.join(dest);
142-
match dir::symlink_or_copy_directory(header_dir, &dest_dir) {
142+
// If the path is relative then use the CARGO_MANIFEST_DIR as the root
143+
let header_dir = if header_dir.is_relative() {
144+
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(header_dir)
145+
} else {
146+
PathBuf::from(header_dir)
147+
};
148+
match dir::symlink_or_copy_directory(&header_dir, &dest_dir) {
143149
Ok(true) => {},
144150
Ok(false) => panic!("Failed to create symlink folder for `{dest}`"),
145151
Err(e) => panic!(

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

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,8 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
use cxx_qt_build::CxxQtBuilder;
7-
use std::path::PathBuf;
8-
9-
fn header_dir() -> PathBuf {
10-
PathBuf::from(std::env::var("OUT_DIR").unwrap())
11-
.join("include")
12-
.join("cxx-qt-lib-extras")
13-
}
14-
15-
fn write_headers_in(subfolder: &str) {
16-
println!("cargo::rerun-if-changed=include/{subfolder}");
17-
18-
for entry in
19-
std::fs::read_dir(format!("include/{subfolder}")).expect("Failed to read include directory")
20-
{
21-
let entry = entry.expect("Failed to read header file!");
22-
let header_name = entry.file_name();
23-
println!(
24-
"cargo::rerun-if-changed=include/{subfolder}/{header_name}",
25-
header_name = header_name.to_string_lossy()
26-
);
27-
28-
// TODO: Do we want to add the headers into a subdirectory?
29-
std::fs::copy(entry.path(), header_dir().join(header_name))
30-
.expect("Failed to copy header file!");
31-
}
32-
}
33-
34-
fn write_headers() {
35-
println!("cargo::rerun-if-changed=include/");
36-
std::fs::create_dir_all(header_dir()).expect("Failed to create include directory");
37-
38-
write_headers_in("core");
39-
write_headers_in("gui");
40-
}
417

428
fn main() {
43-
write_headers();
44-
459
let mut builder = CxxQtBuilder::library()
4610
.qt_module("Gui")
4711
.qt_module("Widgets");
@@ -71,6 +35,10 @@ fn main() {
7135
}
7236
cc.file("src/qt_types.cpp");
7337
println!("cargo::rerun-if-changed=src/qt_types.cpp");
38+
39+
// TODO: automatically add any include/ dir like best_effort_copy_headers
40+
println!("cargo::rerun-if-changed=include/");
41+
cc.include("include");
7442
});
7543
println!("cargo::rerun-if-changed=src/assertion_utils.h");
7644

@@ -83,7 +51,7 @@ fn main() {
8351
// Disable exporting the standard include directory, as we are exporting custom header
8452
interface
8553
.export_include_prefixes([])
86-
.export_include_directory(header_dir(), "cxx-qt-lib-extras")
54+
.export_include_directory("include/cxx-qt-lib-extras", "cxx-qt-lib-extras")
8755
.reexport_dependency("cxx-qt-lib")
8856
.export();
8957
}

crates/cxx-qt-lib-extras/include/gui/qapplication.h renamed to crates/cxx-qt-lib-extras/include/cxx-qt-lib-extras/qapplication.h

File renamed without changes.

crates/cxx-qt-lib-extras/include/core/qcommandlineoption.h renamed to crates/cxx-qt-lib-extras/include/cxx-qt-lib-extras/qcommandlineoption.h

File renamed without changes.

crates/cxx-qt-lib-extras/include/core/qcommandlineparser.h renamed to crates/cxx-qt-lib-extras/include/cxx-qt-lib-extras/qcommandlineparser.h

File renamed without changes.

crates/cxx-qt-lib-extras/include/core/qelapsedtimer.h renamed to crates/cxx-qt-lib-extras/include/cxx-qt-lib-extras/qelapsedtimer.h

File renamed without changes.

crates/cxx-qt-lib/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ fn main() {
383383
}
384384
cc.file("src/qt_types.cpp");
385385
println!("cargo::rerun-if-changed=src/qt_types.cpp");
386+
387+
// With cxx-qt-lib we need to have generated headers in the include folder
388+
// so we copy them into the OUT_DIR and construct a folder
389+
//
390+
// TODO: can this be improved in anyway?
391+
// if we included the include folder from the source dir how do we combine
392+
// the generated headers into the export include dir?
393+
cc.include(header_dir().parent().expect("header_dir has a parent"));
386394
});
387395

388396
let interface = builder.build();

crates/cxx-qt/build.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,9 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6-
use std::path::PathBuf;
7-
86
use cxx_qt_build::CxxQtBuilder;
97

10-
fn header_dir() -> PathBuf {
11-
PathBuf::from(std::env::var("OUT_DIR").unwrap())
12-
.join("include")
13-
.join("cxx-qt")
14-
}
15-
16-
fn write_headers() {
17-
println!("cargo::rerun-if-changed=include/");
18-
std::fs::create_dir_all(header_dir()).expect("Failed to create include directory");
19-
20-
for file_path in [
21-
"connection.h",
22-
"casting.h",
23-
"signalhandler.h",
24-
"thread.h",
25-
"threading.h",
26-
"type.h",
27-
] {
28-
println!("cargo::rerun-if-changed=include/{file_path}");
29-
std::fs::copy(format!("include/{file_path}"), header_dir().join(file_path))
30-
.expect("Failed to copy header file!");
31-
}
32-
}
33-
348
fn main() {
35-
write_headers();
36-
379
let mut builder = CxxQtBuilder::library();
3810

3911
let cpp_files = ["src/connection.cpp"];
@@ -48,6 +20,10 @@ fn main() {
4820
cc.file(cpp_file);
4921
println!("cargo::rerun-if-changed={cpp_file}");
5022
}
23+
24+
// TODO: automatically add any include/ dir like best_effort_copy_headers
25+
println!("cargo::rerun-if-changed=include/");
26+
cc.include("include");
5127
});
5228
builder = builder.initializer(qt_build_utils::Initializer {
5329
file: Some("src/init.cpp".into()),
@@ -57,6 +33,7 @@ fn main() {
5733
let interface = builder.build();
5834
interface
5935
.export_include_prefixes([])
60-
.export_include_directory(header_dir(), "cxx-qt")
36+
// TODO: should we always export or is this fine?
37+
.export_include_directory("include/cxx-qt", "cxx-qt")
6138
.export();
6239
}

0 commit comments

Comments
 (0)