2024-05-02 00:46:19 +00:00
{ stdenv }:
crateName : metadata : buildTests :
2024-06-30 08:12:46 +00:00
if ! buildTests then
''
runHook preInstall
# always create $out even if we do not have binaries. We are detecting binary targets during compilation, if those are missing there is no way to only have $lib
mkdir $ out
if [ [ - s target/env ] ] ; then
mkdir - p $ lib
cp target/env $ lib/env
2024-05-02 00:46:19 +00:00
fi
2024-06-30 08:12:46 +00:00
if [ [ - s target/link.final ] ] ; then
mkdir - p $ lib/lib
cp target/link.final $ lib/lib/link
fi
if [ [ " $ ( l s - A t a r g e t / l i b ) " ] ] ; then
mkdir - p $ lib/lib
cp - r target/lib /* $ l i b / l i b # */
for library in $ lib/lib /* . s o $ l i b / l i b / * . d y l i b ; d o # */
ln - s $ library $ ( echo $ library | sed - e " s / - ${ metadata } / / " )
done
fi
if [ [ " $ ( l s - A t a r g e t / b u i l d ) " ] ] ; then # */
mkdir - p $ lib/lib
cp - r target/build /* $ l i b / l i b # */
fi
if [ [ - d target/bin ] ] ; then
if [ [ " $ ( l s - A t a r g e t / b i n ) " ] ] ; then
mkdir - p $ out/bin
cp - rP target/bin /* $ o u t / b i n # */
fi
fi
runHook postInstall
''
else
# for tests we just put them all in the output. No execution.
''
runHook preInstall
2024-05-02 00:46:19 +00:00
2024-06-30 08:12:46 +00:00
mkdir - p $ out/tests
if [ - e target/bin ] ; then
find target/bin / - type f - executable - exec cp { } $ out/tests \ ;
fi
if [ - e target/lib ] ; then
find target/lib / - type f \ ! - name ' * . rlib' \
- a \ ! - name ' * $ { stdenv . hostPlatform . extensions . sharedLibrary } ' \
- a \ ! - name ' * . d' \
- executable \
- print0 | xargs - - no-run-if-empty - - null install - - target $ out/tests ;
fi
2024-05-02 00:46:19 +00:00
2024-06-30 08:12:46 +00:00
runHook postInstall
''