Skip to content

Commit 3856a57

Browse files
Use shorter paths in the OUT_DIR
As described in KDAB#1237, on Windows we're sometimes hitting the 260 character limit for filepaths. This is mostly due to a lot of nesting by Qt Creator, Corrosion and Cargo who all include the target triple and other configuration information in the build path. However, we can at least reduce the character count a little bit on our part. For example, for qqmlengine.cxxqt.h, the path length is now reduced by ~40 characters from: out/cxx-qt-build/target/crates/cxx-qt-lib/include/cxx-qt-lib-internals/src/qml/qqmlengine.cxxqt.h to now: out/cxxqtbuild/include/private/src/qml/qqmlengine.cxxqt.h
1 parent 88171ba commit 3856a57

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

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

+21-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ pub(crate) const INCLUDE_VERB: &str = "create symlink";
2121
#[cfg(not(unix))]
2222
pub(crate) const INCLUDE_VERB: &str = "deep copy files";
2323

24+
pub(crate) fn gen() -> PathBuf {
25+
// Use a short name due to the Windows file path limit!
26+
out().join("cxxqtgen")
27+
}
28+
2429
// Clean a directory by removing it and recreating it.
2530
pub(crate) fn clean(path: impl AsRef<Path>) -> Result<()> {
2631
let result = std::fs::remove_dir_all(&path);
@@ -37,14 +42,26 @@ pub(crate) fn clean(path: impl AsRef<Path>) -> Result<()> {
3742

3843
/// The target directory, namespaced by crate
3944
pub(crate) fn crate_target() -> PathBuf {
40-
target().join("crates").join(crate_name())
45+
let path = target();
46+
if is_exporting_crate() {
47+
path.join("crates").join(crate_name())
48+
} else {
49+
// If we're not exporting, use a shortened path
50+
// The paths for files in the OUT_DIR can get pretty long, especially if combined with
51+
// Corrosion/CMake.
52+
// This is an issue, as Windows has a maximum path length of 260 characters.
53+
// The OUT_DIR is already namespaced by crate name, so we don't need to prefix again.
54+
// See also: https://github.com/KDAB/cxx-qt/issues/1237
55+
path
56+
}
4157
}
4258

4359
/// The target directory, namespaced by QML module
4460
pub(crate) fn module_target(module_uri: &str) -> PathBuf {
4561
module_export(module_uri).unwrap_or_else(|| {
4662
out()
47-
.join("qml_modules")
63+
// Use a short name due to the Windows file path limit!
64+
.join("cxxqtqml")
4865
.join(module_name_from_uri(module_uri))
4966
})
5067
}
@@ -75,7 +92,8 @@ pub(crate) fn target() -> PathBuf {
7592
return export;
7693
}
7794

78-
out().join("cxx-qt-build").join("target")
95+
// Use a short name due to the Windows file path limit!
96+
out().join("cxxqtbuild")
7997
}
8098

8199
/// The export directory, if one was specified through the environment.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn generate_cxxqt_cpp_files(
264264
header_dir: impl AsRef<Path>,
265265
include_prefix: &str,
266266
) -> Vec<GeneratedCppFilePaths> {
267-
let cxx_qt_dir = dir::out().join("cxx-qt-gen");
267+
let cxx_qt_dir = dir::gen();
268268
std::fs::create_dir_all(&cxx_qt_dir).expect("Failed to create cxx-qt-gen directory!");
269269
std::fs::write(cxx_qt_dir.join("include-prefix.txt"), include_prefix).expect("");
270270

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() {
8080
});
8181
println!("cargo::rerun-if-changed=src/assertion_utils.h");
8282

83-
builder
84-
.include_prefix("cxx-qt-lib-extras-internals")
85-
.build();
83+
// Use a short name due to the Windows file path limit!
84+
// We don't re-export these headers anyway.
85+
builder.include_prefix("private").build();
8686
}

crates/cxx-qt-lib/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ fn main() {
352352
.reexport_dependency("cxx-qt");
353353

354354
let mut builder = CxxQtBuilder::library(interface)
355-
.include_prefix("cxx-qt-lib-internals")
355+
// Use a short name due to the Windows file path limit!
356+
// We don't re-export these headers anyway
357+
.include_prefix("private")
356358
.initializer(qt_build_utils::Initializer {
357359
file: Some("src/core/init.cpp".into()),
358360
..qt_build_utils::Initializer::default_signature("init_cxx_qt_lib_core")

0 commit comments

Comments
 (0)