Skip to content

Make manifest path absolute without resolving symlinks - #808

Merged
Shnatsel merged 2 commits into
CycloneDX:mainfrom
sivizius:absolute-without-resolving-symlinks
Mar 13, 2026
Merged

Make manifest path absolute without resolving symlinks#808
Shnatsel merged 2 commits into
CycloneDX:mainfrom
sivizius:absolute-without-resolving-symlinks

Conversation

@sivizius

@sivizius sivizius commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

Cargo expects the file path to be absolute. However, symbolic links are allowed. It’s thus enough to call https://doc.rust-lang.org/std/path/fn.absolute.html instead of https://doc.rust-lang.org/std/path/struct.Path.html#method.canonicalize.

We have a large workspace with various crates and are using Nix/crane to build various binaries. To avoid rebuilding all components when unrelated code of a crate was altered, we want to graft a directory with symbolic links to generated workspace members (dummies, library-only, binary-only, library-with-tests, full, …). These directories are read-only.

  1. By using canonicalize, cargo cyclonedx tries to find the Cargo.lock in /nix/store/ instead of /build/, where the generated Cargo.toml is located.
  2. Even if the links point to /nix/store/<hash>-source/<member>/, with a lock file in /nix/store/<hash>-source/, running cargo cyclonedx fails because it tries to output the SBOM to e.g. /nix/store/<hash>-source/<member>/….cdx.json, which is a read-only directory.

This works just fine for cargo build, etc., just not for cargo cyclonedx.

If this is PR is a breaking change because resolving symbolic links is expected now, perhaps some CLI flags should be implemented:

  • to enable/disable symlink resolution,
  • to specify the output directory (--output-dir, see e.g. cargo tarpaulin),
  • to specify the path to Cargo.lock (--lockfile-path, see e.g. cargo build),

However, I doubt resolving symbolic links is expected, as this differs from the behaviour of default cargo tools. On the other side: Even with my proposed change, these CLI options might be useful.

@sivizius
sivizius requested a review from a team as a code owner December 5, 2025 16:46
@sivizius
sivizius force-pushed the absolute-without-resolving-symlinks branch from 5cf6f40 to 18bcda0 Compare December 5, 2025 17:26
@Shnatsel

Shnatsel commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Sounds good, thank you!

Since path::absolute was added in Rust 1.79, please bump rust-version both in Cargo.toml and in the Github Actions files. Once that's done I can merge.

@sivizius
sivizius force-pushed the absolute-without-resolving-symlinks branch from 18bcda0 to 7cdae60 Compare March 11, 2026 12:46
@sivizius

Copy link
Copy Markdown
Contributor Author

Since path::absolute was added in Rust 1.79, please bump rust-version both in Cargo.toml and in the Github Actions files. Once that's done I can merge.

Done, sorry for the late response.

Signed-off-by: Sebastian Walz <sebastian.walz@secunet.com>
@sivizius
sivizius force-pushed the absolute-without-resolving-symlinks branch from 7cdae60 to 39bc00f Compare March 11, 2026 12:47
Signed-off-by: Sergey "Shnatsel" Davidoff <shnatsel@gmail.com>
@Shnatsel

Copy link
Copy Markdown
Contributor

Matching Cargo behavior seems important enough for an MSRV bump. Thanks for the PR and sorry it took a while!

@Shnatsel
Shnatsel merged commit c9a1fae into CycloneDX:main Mar 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants