Skip to content
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
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exclude = [
libraries = [{ path = "dylints/*" }]

[workspace.package]
version = "2.5.12"
version = "2.5.13"
edition = "2021"
rust-version = "1.94.1"
license = "MIT OR Apache-2.0"
Expand Down
52 changes: 36 additions & 16 deletions crates/fbuild-library/src/library/library_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ fn fallback_runtime() -> Result<&'static Runtime> {
Ok(RT.get_or_init(|| rt))
}

/// Resolve a local dependency relative to its project and return a canonical
/// absolute root. Compiler invocations use a separate build directory as
/// their working directory, so preserving a relative `lib_deps` path here
/// would make its include directories resolve against the wrong directory.
fn resolve_local_library_dir(project_dir: &Path, local_path: &Path, name: &str) -> Result<PathBuf> {
let lib_dir = if local_path.is_absolute() {
local_path.to_path_buf()
} else {
project_dir.join(local_path)
};
if !lib_dir.is_dir() {
return Err(FbuildError::PackageError(format!(
"local library '{}' does not exist or is not a directory: {}",
name,
lib_dir.display()
)));
}
lib_dir
.canonicalize()
.map(|path| fbuild_core::path::strip_unc_prefix(&path))
.map_err(|e| {
FbuildError::PackageError(format!(
"failed to canonicalize local library '{}': {} ({})",
name,
lib_dir.display(),
e
))
})
}

/// Result of library resolution and compilation.
pub struct LibraryResult {
/// All include directories from all libraries (for compiler `-I` flags).
Expand Down Expand Up @@ -97,18 +127,7 @@ pub async fn ensure_libraries(
> = tokio::task::JoinSet::new();
for spec in &specs {
if let Some(local_path) = &spec.local_path {
let lib_dir = if local_path.is_absolute() {
local_path.clone()
} else {
project_dir.join(local_path)
};
if !lib_dir.is_dir() {
return Err(FbuildError::PackageError(format!(
"local library '{}' does not exist or is not a directory: {}",
spec.name,
lib_dir.display()
)));
}
let lib_dir = resolve_local_library_dir(project_dir, local_path, &spec.name)?;
let sanitized = spec.sanitized_name();
installed.push(InstalledLibrary::with_build_dir(
&lib_dir,
Expand Down Expand Up @@ -413,23 +432,24 @@ mod tests {
}

#[test]
fn test_named_local_symlink_adds_include_dir() {
fn test_named_relative_local_symlink_adds_include_dir() {
let tmp = tempfile::TempDir::new().unwrap();
let local = tmp.path().join("local");
let project = tmp.path().join("project");
let local = project.join("local");
let local_src = local.join("src");
std::fs::create_dir_all(&local_src).unwrap();
std::fs::write(local_src.join("Local.h"), "").unwrap();
let libs_dir = tmp.path().join("build").join("libs");
let result = ensure_libraries_sync(
&[format!("Local=symlink://{}", local.display())],
&["Local=symlink://local".to_string()],
&[],
Path::new("/gcc"),
Path::new("/g++"),
Path::new("/ar"),
&[],
&[],
&[],
tmp.path(),
&project,
&libs_dir,
false,
1,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "fbuild"
version = "2.5.12"
version = "2.5.13"
description = "PlatformIO-compatible embedded build tool (Rust implementation)"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
Loading