diff --git a/crates/cxx-qt-build/src/dir.rs b/crates/cxx-qt-build/src/dir.rs index 6890b202e..fc173821b 100644 --- a/crates/cxx-qt-build/src/dir.rs +++ b/crates/cxx-qt-build/src/dir.rs @@ -21,6 +21,11 @@ pub(crate) const INCLUDE_VERB: &str = "create symlink"; #[cfg(not(unix))] pub(crate) const INCLUDE_VERB: &str = "deep copy files"; +pub(crate) fn gen() -> PathBuf { + // Use a short name due to the Windows file path limit! + out().join("cxxqtgen") +} + // Clean a directory by removing it and recreating it. pub(crate) fn clean(path: impl AsRef) -> Result<()> { let result = std::fs::remove_dir_all(&path); @@ -37,14 +42,26 @@ pub(crate) fn clean(path: impl AsRef) -> Result<()> { /// The target directory, namespaced by crate pub(crate) fn crate_target() -> PathBuf { - target().join("crates").join(crate_name()) + let path = target(); + if is_exporting_crate() { + path.join("crates").join(crate_name()) + } else { + // If we're not exporting, use a shortened path + // The paths for files in the OUT_DIR can get pretty long, especially if combined with + // Corrosion/CMake. + // This is an issue, as Windows has a maximum path length of 260 characters. + // The OUT_DIR is already namespaced by crate name, so we don't need to prefix again. + // See also: https://github.com/KDAB/cxx-qt/issues/1237 + path + } } /// The target directory, namespaced by QML module pub(crate) fn module_target(module_uri: &str) -> PathBuf { module_export(module_uri).unwrap_or_else(|| { out() - .join("qml_modules") + // Use a short name due to the Windows file path limit! + .join("cxxqtqml") .join(module_name_from_uri(module_uri)) }) } @@ -75,7 +92,8 @@ pub(crate) fn target() -> PathBuf { return export; } - out().join("cxx-qt-build").join("target") + // Use a short name due to the Windows file path limit! + out().join("cxxqtbuild") } /// The export directory, if one was specified through the environment. diff --git a/crates/cxx-qt-build/src/lib.rs b/crates/cxx-qt-build/src/lib.rs index fd5d35093..4cc23ce37 100644 --- a/crates/cxx-qt-build/src/lib.rs +++ b/crates/cxx-qt-build/src/lib.rs @@ -264,7 +264,7 @@ fn generate_cxxqt_cpp_files( header_dir: impl AsRef, include_prefix: &str, ) -> Vec { - let cxx_qt_dir = dir::out().join("cxx-qt-gen"); + let cxx_qt_dir = dir::gen(); std::fs::create_dir_all(&cxx_qt_dir).expect("Failed to create cxx-qt-gen directory!"); std::fs::write(cxx_qt_dir.join("include-prefix.txt"), include_prefix).expect(""); diff --git a/crates/cxx-qt-lib-extras/build.rs b/crates/cxx-qt-lib-extras/build.rs index b6beb8cec..8e6b5c125 100644 --- a/crates/cxx-qt-lib-extras/build.rs +++ b/crates/cxx-qt-lib-extras/build.rs @@ -80,7 +80,7 @@ fn main() { }); println!("cargo::rerun-if-changed=src/assertion_utils.h"); - builder - .include_prefix("cxx-qt-lib-extras-internals") - .build(); + // Use a short name due to the Windows file path limit! + // We don't re-export these headers anyway. + builder.include_prefix("private").build(); } diff --git a/crates/cxx-qt-lib/build.rs b/crates/cxx-qt-lib/build.rs index 62749cdf6..99932b43c 100644 --- a/crates/cxx-qt-lib/build.rs +++ b/crates/cxx-qt-lib/build.rs @@ -352,7 +352,9 @@ fn main() { .reexport_dependency("cxx-qt"); let mut builder = CxxQtBuilder::library(interface) - .include_prefix("cxx-qt-lib-internals") + // Use a short name due to the Windows file path limit! + // We don't re-export these headers anyway + .include_prefix("private") .initializer(qt_build_utils::Initializer { file: Some("src/core/init.cpp".into()), ..qt_build_utils::Initializer::default_signature("init_cxx_qt_lib_core")