2021-12-27 02:32:57 +03:00
|
|
|
configureCargoVendoredDepsHook() {
|
2022-01-01 04:43:56 +03:00
|
|
|
local vendoredDir="${1:-${cargoVendorDir:?not defined}}"
|
|
|
|
local cargoConfig="${2:-${CARGO_HOME:?not defined}/config.toml}"
|
|
|
|
|
2021-12-29 03:05:20 +03:00
|
|
|
# NB: we add this configuration to $CARGO_HOME/config.toml
|
|
|
|
# instead of .cargo/config.toml. This allows cargo to honor the
|
|
|
|
# project's configuration (if it exists) with greater specificity
|
|
|
|
# than the config we are adding. If the project knows what it is
|
|
|
|
# doing and has its own source replacement going on, it can happily
|
|
|
|
# ignore the changes we are trying to make!
|
2022-01-31 01:30:15 +03:00
|
|
|
if [[ -f "${vendoredDir}/config.toml" ]]; then
|
2022-02-07 04:17:47 +03:00
|
|
|
echo will append ${cargoConfig} with contents of ${vendoredDir}/config.toml
|
2022-01-31 01:30:15 +03:00
|
|
|
cat "${vendoredDir}/config.toml" >>"${cargoConfig}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo setting source replacement config in ${cargoConfig} using vendored directory ${vendoredDir}
|
2022-01-01 04:43:56 +03:00
|
|
|
cat >>"${cargoConfig}" <<EOF
|
2022-01-31 01:30:15 +03:00
|
|
|
|
2021-12-27 02:32:57 +03:00
|
|
|
[source.crates-io]
|
|
|
|
replace-with = "nix-sources"
|
|
|
|
[source.nix-sources]
|
2022-01-01 04:43:56 +03:00
|
|
|
directory = "${vendoredDir}"
|
2021-12-27 02:32:57 +03:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "${cargoVendorDir-}" ]; then
|
2021-12-27 03:18:22 +03:00
|
|
|
preConfigureHooks+=(configureCargoVendoredDepsHook)
|
|
|
|
else
|
2021-12-29 03:05:20 +03:00
|
|
|
echo "cargoVendorDir not set, will not automatically configure vendored sources"
|
2021-12-27 02:32:57 +03:00
|
|
|
fi
|