|
1 | | -#!/usr/bin/env bash |
| 1 | +#!/bin/sh |
2 | 2 | # |
3 | 3 | # For details, see: |
4 | 4 | # `@rules_rust//crate_universe/src/metadata/cargo_tree_resolver.rs - TreeResolver::create_rustc_wrapper` |
5 | 5 |
|
6 | | -set -euo pipefail |
| 6 | +set -eu |
7 | 7 |
|
8 | 8 | # When cargo is detecting the host configuration, the host target needs to be |
9 | 9 | # injected into the command. |
10 | | -if [[ "$@" == *"rustc - --crate-name ___ "* && "$@" != *" --target "* ]]; then |
11 | | - exec "$@" --target "${HOST_TRIPLE}" |
12 | | -fi |
| 10 | +case "$*" in |
| 11 | + *"rustc - --crate-name ___ "*) |
| 12 | + case "$*" in |
| 13 | + *" --target "*) ;; |
| 14 | + *) |
| 15 | + exec "$@" --target "${HOST_TRIPLE}" |
| 16 | + ;; |
| 17 | + esac |
| 18 | + ;; |
| 19 | +esac |
13 | 20 |
|
14 | 21 | # When querying info about the compiler, ensure the triple is mocked out to be |
15 | 22 | # the desired target triple for the host. |
16 | | -if [[ "$@" == *"rustc -Vv" || "$@" == *"rustc -vV" ]]; then |
17 | | - set +e |
18 | | - _RUSTC_OUTPUT="$($@)" |
19 | | - _EXIT_CODE=$? |
20 | | - set -e |
| 23 | +case "$*" in |
| 24 | + *"rustc -Vv"*|*"rustc -vV"*) |
| 25 | + set +e |
| 26 | + _RUSTC_OUTPUT="$("$@")" |
| 27 | + _EXIT_CODE=$? |
| 28 | + set -e |
21 | 29 |
|
22 | | - # Loop through each line of the output |
23 | | - while IFS= read -r line; do |
24 | | - # If the line starts with "host:", replace it with the new host value |
25 | | - if [[ "${line}" == host:* ]]; then |
26 | | - echo "host: ${HOST_TRIPLE}" |
27 | | - else |
28 | | - # Print the other lines unchanged |
29 | | - echo "${line}" |
30 | | - fi |
31 | | - done <<<"${_RUSTC_OUTPUT}" |
| 30 | + # Loop through each line of the output |
| 31 | + while IFS= read -r line; do |
| 32 | + # If the line starts with "host:", replace it with the new host value |
| 33 | + case "${line}" in |
| 34 | + host:*) |
| 35 | + echo "host: ${HOST_TRIPLE}" |
| 36 | + ;; |
| 37 | + *) |
| 38 | + echo "${line}" |
| 39 | + ;; |
| 40 | + esac |
| 41 | + done <<EOF |
| 42 | +${_RUSTC_OUTPUT} |
| 43 | +EOF |
32 | 44 |
|
33 | | - exit ${_EXIT_CODE} |
34 | | -fi |
| 45 | + exit ${_EXIT_CODE} |
| 46 | + ;; |
| 47 | +esac |
35 | 48 |
|
36 | 49 | # If there is nothing special to do then simply forward the call |
37 | 50 | exec "$@" |
0 commit comments