Skip to content

Commit

Permalink
add support to cargo binaries
Browse files Browse the repository at this point in the history
Eselect looks to ${package}-${rust_target} if a package has been installed
with multiple target from the cargo eclass. This allows binaries that need
to be linked to the proper rustc library to work correctly.
  • Loading branch information
gibix committed Jul 24, 2018
1 parent c3622c0 commit 597c025
Showing 1 changed file with 61 additions and 18 deletions.
79 changes: 61 additions & 18 deletions src/modules/rust.eselect
Expand Up @@ -40,8 +40,33 @@ get_current_target() {
echo "NOT_SET"
}

#get symlinks list from file or the default value
get_symlinks_from_file() {
local filename=$1
local symlinks=()
local i
if [[ -e ${filename} ]]; then
for i in `cat "${filename}"`; do
symlinks+=($i)
done
fi

if [ ${#symlinks[@]} -eq 0 ]; then
echo /usr/bin/rustdoc
else
echo "${symlinks[@]}"
fi

}

#get last set symlinks
get_last_set_symlinks() {
local symlinks=( $(get_symlinks_from_file "${EROOT}/etc/env.d/rust/last-set") )
echo "${symlinks[@]}"
}

#get lists of symlinks
get_symlinks() {
get_provider_symlinks() {
local target=$1
if [ "${target}" == "NOT_SET" ]; then
echo /usr/bin/rustdoc
Expand All @@ -52,19 +77,25 @@ get_symlinks() {
target=${targets[target]}
fi

local symlinks=()
local i
for i in `cat "${EROOT}/etc/env.d/rust/provider-${target}"`; do
symlinks+=($i)
done
local symlinks=( $(get_symlinks_from_file "${EROOT}/etc/env.d/rust/provider-${target}") )
echo "${symlinks[@]}"
}

if [ ${#symlinks[@]} -eq 0 ]; then
echo /usr/bin/rustdoc
else
echo "${symlinks[@]}"
#get lists of symlinks for cargo binaries
get_binaries_symlinks() {
if is_number "${target}"; then
local targets=( $(find_targets) )
target=${targets[target]}
fi

local symlinks=()
for package in /etc/env.d/rust/*binaries-${target}; do
symlinks+=$(get_symlinks_from_file "${EROOT}${package}")
done
echo "${symlinks[@]}"
}


# remove symlink if exists
remove_symlink() {
local symlink=$1
Expand All @@ -83,6 +114,8 @@ set_symlink() {
local source=$1
local dest=$2

remove_symlink "${dest}"

if [[ -e ${source} ]]; then
mkdir -p "$(dirname ${dest})" || die -q "directory creation failed for $(dirname ${dest})"
ln -s "${source}" "${dest}" || die -q "${dest} symlink setting failed"
Expand All @@ -93,12 +126,13 @@ set_symlink() {

# unset the rust version
unset_version() {
local target=$(get_current_target)
local symlinks=( $(get_symlinks ${target}) )
local symlinks=( $(get_last_set_symlinks) )
for i in "${symlinks[@]}"; do
remove_symlink "${EROOT}${i}"
done
remove_symlink "${EROOT}/usr/bin/rustc"
rm -f "${EROOT}/etc/env.d/rust/last-set" \
|| die -q "rm -f ${EROOT}/etc/env.d/rust/last-set failed"
}

# set the rust version
Expand All @@ -122,13 +156,22 @@ set_version() {

unset_version

set_symlink "${EROOT}/usr/bin/rustc-${target_postfix}" "${EROOT}/usr/bin/rustc" \
|| die -q "rustc symlink setting failed"
set_symlink "${EROOT}/usr/bin/rustc-${target_postfix}" "${EROOT}/usr/bin/rustc"

local symlinks=( $(get_symlinks ${target}) )
for i in "${symlinks[@]}"; do
set_symlink "${EROOT}${i}-${target_postfix}" "${EROOT}${i}" \
|| die -q "${i} symlink setting failed"
local target_symlinks=( $(get_provider_symlinks ${target}) )
for i in "${target_symlinks[@]}"; do
set_symlink "${EROOT}${i}-${target_postfix}" "${EROOT}${i}"
done

cp "${EROOT}/etc/env.d/rust/provider-${target}" \
"${EROOT}/etc/env.d/rust/last-set" || \
die -q "symlink list copying failed"

local binaries_symlinks=( $(get_binaries_symlinks ${target}) )
for i in "${binaries_symlinks[@]}"; do
set_symlink "${EROOT}/usr/lib/rust-${target_postfix}/bin/$(basename ${i})" "${EROOT}${i}"
echo "${i}" >> "${EROOT}/etc/env.d/rust/last-set" || \
die -q "binary symlink list copying failed"
done
}

Expand Down

0 comments on commit 597c025

Please sign in to comment.