···1414 fi
1515 if [[ "$(ls -A target/lib)" ]]; then
1616 mkdir -p $lib/lib
1717- cp target/lib/* $lib/lib #*/
1717+ cp -r target/lib/* $lib/lib #*/
1818 for library in $lib/lib/*.so $lib/lib/*.dylib; do #*/
1919 ln -s $library $(echo $library | sed -e "s/-${metadata}//")
2020 done
···2626 if [[ -d target/bin ]]; then
2727 if [[ "$(ls -A target/bin)" ]]; then
2828 mkdir -p $out/bin
2929- cp -P target/bin/* $out/bin # */
2929+ cp -rP target/bin/* $out/bin # */
3030 fi
3131 fi
3232 runHook postInstall
+44-8
pkgs/build-support/rust/build-rust-crate/lib.sh
···11+echo_build_heading() {
22+ if (( $# == 1 )); then
33+ echo_colored "Building $1"
44+ else
55+ echo_colored "Building $1 ($2)"
66+ fi
77+}
88+19build_lib() {
210 lib_src=$1
311 echo_build_heading $lib_src ${libName}
···614 --crate-name $CRATE_NAME \
715 $lib_src \
816 --out-dir target/lib \
99- --emit=dep-info,link \
1017 -L dependency=target/deps \
1118 --cap-lints allow \
1219 $LIB_RUSTC_OPTS \
···3744 --crate-type bin \
3845 $BIN_RUSTC_OPTS \
3946 --out-dir target/bin \
4040- --emit=dep-info,link \
4147 -L dependency=target/deps \
4248 $LINK \
4349 $EXTRA_LIB \
···7177 build_bin_test "$derived_crate_name" "$file"
7278}
73798080+# Add additional link options that were provided by the build script.
7481setup_link_paths() {
7582 EXTRA_LIB=""
7683 if [[ -e target/link_ ]]; then
···96103 done
9710498105 if [[ -e target/link ]]; then
9999- sort -u target/link.final > target/link.final.sorted
100100- mv target/link.final.sorted target/link.final
101101- sort -u target/link > target/link.sorted
102102- mv target/link.sorted target/link
103103-104106 tr '\n' ' ' < target/link > target/link_
105107 LINK=$(cat target/link_)
106108 fi
···132134 done
133135134136 if [[ -z "$BIN_PATH" ]]; then
135135- echo "failed to find file for binary target: $BIN_NAME" >&2
137137+ echo_error "ERROR: failed to find file for binary target: $BIN_NAME" >&2
136138 exit 1
137139 fi
138140}
141141+142142+# Extracts cargo_toml_path of the matching crate.
143143+matching_cargo_toml_path() {
144144+ local manifest_path="$1"
145145+ local expected_crate_name="$2"
146146+147147+ # If the Cargo.toml is not a workspace root,
148148+ # it will only contain one package in ".packages"
149149+ # because "--no-deps" suppressed dependency resolution.
150150+ #
151151+ # But to make it more general, we search for a matching
152152+ # crate in all packages and use the manifest path that
153153+ # is referenced there.
154154+ cargo metadata --no-deps --format-version 1 \
155155+ --manifest-path "$manifest_path" \
156156+ | jq -r '.packages[]
157157+ | select( .name == "'$expected_crate_name'")
158158+ | .manifest_path'
159159+}
160160+161161+# Find a Cargo.toml in the current or any sub directory
162162+# with a matching crate name.
163163+matching_cargo_toml_dir() {
164164+ local expected_crate_name="$1"
165165+166166+ find -L -name Cargo.toml | sort | while read manifest_path; do
167167+ echo "...checking manifest_path $manifest_path" >&2
168168+ local matching_path="$(matching_cargo_toml_path "$manifest_path" "$expected_crate_name")"
169169+ if [ -n "${matching_path}" ]; then
170170+ echo "$(dirname $matching_path)"
171171+ break
172172+ fi
173173+ done
174174+}
+48-22
pkgs/build-support/rust/build-rust-crate/log.nix
···11{ lib }:
22-{
33- echo_build_heading = colors: ''
44- echo_build_heading() {
55- start=""
66- end=""
77- ${lib.optionalString (colors == "always") ''
88- start="$(printf '\033[0;1;32m')" #set bold, and set green.
99- end="$(printf '\033[0m')" #returns to "normal"
1010- ''}
1111- if (( $# == 1 )); then
1212- echo "$start""Building $1""$end"
1313- else
1414- echo "$start""Building $1 ($2)""$end"
1515- fi
22+33+let echo_colored_body = start_escape:
44+ # Body of a function that behaves like "echo" but
55+ # has the output colored by the given start_escape
66+ # sequence. E.g.
77+ #
88+ # * echo_x "Building ..."
99+ # * echo_x -n "Running "
1010+ #
1111+ # This is more complicated than apparent at first sight
1212+ # because:
1313+ # * The color markers and the text must be print
1414+ # in the same echo statement. Otherise, other
1515+ # intermingled text from concurrent builds will
1616+ # be colored as well.
1717+ # * We need to preserve the trailing newline of the
1818+ # echo if and only if it is present. Bash likes
1919+ # to strip those if we capture the output of echo
2020+ # in a variable.
2121+ # * Leading "-" will be interpreted by test as an
2222+ # option for itself. Therefore, we prefix it with
2323+ # an x in `[[ "x$1" =~ ^x- ]]`.
2424+ ''
2525+ local echo_args="";
2626+ while [[ "x$1" =~ ^x- ]]; do
2727+ echo_args+=" $1"
2828+ shift
2929+ done
3030+3131+ local start_escape="$(printf '${start_escape}')"
3232+ local reset="$(printf '\033[0m')"
3333+ echo $echo_args $start_escape"$@"$reset
3434+ '';
3535+ echo_conditional_colored_body = colors: start_escape:
3636+ if colors == "always"
3737+ then (echo_colored_body start_escape)
3838+ else ''echo "$@"'';
3939+in {
4040+ echo_colored = colors: ''
4141+ echo_colored() {
4242+ ${echo_conditional_colored_body colors ''\033[0;1;32m''}
1643 }
1717- '';
4444+4545+ echo_error() {
4646+ ${echo_conditional_colored_body colors ''\033[0;1;31m''}
4747+ }
4848+ '';
4949+1850 noisily = colors: verbose: ''
1951 noisily() {
2020- start=""
2121- end=""
2222- ${lib.optionalString (colors == "always") ''
2323- start="$(printf '\033[0;1;32m')" #set bold, and set green.
2424- end="$(printf '\033[0m')" #returns to "normal"
2525- ''}
2652 ${lib.optionalString verbose ''
2727- echo -n "$start"Running "$end"
5353+ echo_colored -n "Running "
2854 echo $@
2955 ''}
3056 $@