nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
382 stars 89 forks source link

fix(template): run tests in `/build/source` instead `/build` #328

Closed RaitoBezarius closed 9 months ago

RaitoBezarius commented 10 months ago

Previously, the source tree was located inline in /build during tests, this was a mistake because the crates more than often are built in /build/source as per the sourceRoot system.

This can cause issues with test binaries hardcoding /build/source/... as their choice for doing things, causing them to be confused in the test phase which is relocated without rewriting the paths inside test binaries.

We fix that by relocating ourselves in the right hierarchy.

This is a "simple" fix in the sense that more edge cases could exist but they are hard to reason about because they would be crates using custom sourceRoot, i.e. having crate.sourceRoot set and then it becomes a bit hard to reproduce the hierarchy, you need to analyze whether the path is absolute or relative,

If it's relative, you can just reuse it and reproduce that specific hierarchy. If it's absolute, you need to cut the "absolute" meaningless part, e.g. $NIX_BUILD_TOP/ and proceed like it's a relative path IMHO.

Fixes #327.

flokli commented 10 months ago

Added this to our crate2nix package, and building with the newly-generated Cargo.nix does indeed fix the problem!

flokli commented 10 months ago

@kolloch this is running fine. Any reservations against merging it?