Skip to content

Use shorter paths in the OUT_DIR #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/cxx-qt-build/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> Result<()> {
let result = std::fs::remove_dir_all(&path);
Expand All @@ -37,14 +42,26 @@ pub(crate) fn clean(path: impl AsRef<Path>) -> 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))
})
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn generate_cxxqt_cpp_files(
header_dir: impl AsRef<Path>,
include_prefix: &str,
) -> Vec<GeneratedCppFilePaths> {
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("");

Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-lib-extras/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 3 additions & 1 deletion crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading