crane icon indicating copy to clipboard operation
crane copied to clipboard

`CARGO_TARGET_DIR` breaks `buildDepsOnly` cache

Open szlend opened this issue 1 year ago • 1 comments

Setting a custom CARGO_TARGET_DIR breaks buildDepsOnly caching.

For example if you build deps with CARGO_TARGET_DIR=target/foo, then inheritCargoArtifactsHook will extract artifacts to target/foo/foo so the artifacts will not be picked up. You can work around this issue, by setting CARGO_TARGET_DIR=target in buildPackage.

Example project here: https://github.com/szlend/crane-target-dir

The derivation includes a postBuild step that prints out the directory tree to demonstrate what happens.

szlend avatar Mar 03 '24 18:03 szlend

Hi @szlend thanks for the report!

At first glance I suspect we might need to handle decompressing existing artifacts here. Specifically the --strip-components=1 might not be taking the nested target/foo path properly: https://github.com/ipetkov/crane/blob/d90be2c7afd3d1234ea3278533513d10bc8c7a8e/lib/setupHooks/inheritCargoArtifactsHook.sh#L28

Will try to take a closer look at this sometime soon!

ipetkov avatar Mar 05 '24 03:03 ipetkov

Thanks again for reporting this! Should be fixed with https://github.com/ipetkov/crane/pull/561

ipetkov avatar Mar 22 '24 23:03 ipetkov