diff --git a/rust/.gitignore b/rust/.gitignore index 03314f77b..331245bec 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -1 +1,2 @@ Cargo.lock +.cargo/ diff --git a/rust/CMakeLists.txt b/rust/CMakeLists.txt index 808fb4391..986ae5987 100644 --- a/rust/CMakeLists.txt +++ b/rust/CMakeLists.txt @@ -1,5 +1,12 @@ file(WRITE CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}\n") +execute_process( + COMMAND /usr/bin/env "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" "/bin/bash" "${CMAKE_CURRENT_LIST_DIR}/scripts/setup.sh" + WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" + RESULT_VARIABLE CARGO_RESULT + OUTPUT_VARIABLE CARGO_CONFIG_OUT + ERROR_VARIABLE CARGO_CONFIG_OUT) + if(HAVE_RUST) add_subdirectory(ccommon_rs) endif() diff --git a/rust/scripts/setup.sh b/rust/scripts/setup.sh new file mode 100755 index 000000000..259c2a06b --- /dev/null +++ b/rust/scripts/setup.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# utility script run by cmake for writing a .cargo/config that points +# to the common 'target' directory under the CMAKE_BINARY_DIR. This +# allows automated tools (such as the intellij rust plugin or vcode +# rust integration) to share output and avoid recompiling between +# the command line and the IDE. +# +# it is assumed that this script is run with the CWD being the +# place where the .cargo dir should be created. + +set -euo pipefail +IFS=$'\n\t' + +die() { echo "fatal: $*" >&2; exit 1; } + +if [[ -z "${CMAKE_BINARY_DIR:-}" ]]; then + die "CMAKE_BINARY_DIR must be set!" +fi + +mkdir -p .cargo + +cleanup() { + [[ -n "${TEMPFILE:-}" ]] && rm -rf "$TEMPFILE" +} +trap cleanup EXIT + +TEMPFILE="$(mktemp '.cargo/config.XXXXXXXX')" || die "could not create tempfile" + +cat > "$TEMPFILE" <