mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-29 21:42:23 +03:00
32ca849598
* Hook functions now will accept any relevant arguments and fall back to our default variables if they are not provided, potentially allowing them to be adapted externally (without needing more configuration knobs on our end)
27 lines
959 B
Bash
27 lines
959 B
Bash
configureCargoVendoredDepsHook() {
|
|
local vendoredDir="${1:-${cargoVendorDir:?not defined}}"
|
|
local cargoConfig="${2:-${CARGO_HOME:?not defined}/config.toml}"
|
|
|
|
echo setting source replacement config in ${cargoConfig} using vendored directory ${vendoredDir}
|
|
|
|
# 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!
|
|
cat >>"${cargoConfig}" <<EOF
|
|
[source.crates-io]
|
|
replace-with = "nix-sources"
|
|
|
|
[source.nix-sources]
|
|
directory = "${vendoredDir}"
|
|
EOF
|
|
}
|
|
|
|
if [ -n "${cargoVendorDir-}" ]; then
|
|
preConfigureHooks+=(configureCargoVendoredDepsHook)
|
|
else
|
|
echo "cargoVendorDir not set, will not automatically configure vendored sources"
|
|
fi
|