|
2 | 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 | 3 | # SPDX-License-Identifier: Apache-2.0 OR MIT
|
4 | 4 |
|
| 5 | + |
5 | 6 | # Usage:
|
6 |
| -# rmc-rustc (--rmc-flags | --rmc-path) |
7 |
| -# - This will print the configurations used to run rmc version of rustc. |
8 |
| -# rmc-rustc RUSTC_OPTIONS |
9 |
| -# - This will run RUSTC with RMC flags + the given RUSTC_OPTIONS |
| 7 | +# RMCFLAGS="[<RMC_OPTIONS>]*" rmc-rustc --rmc-flags [<RUSTC_OPTIONS>]* |
| 8 | +# - This will run rmc-compiler with RMC options provided via RMCFLAGS |
| 9 | +# environment variable + the given RUSTC_OPTIONS. |
| 10 | +# rmc-rustc [<RMC_OPTIONS>]* [<RUSTC_OPTIONS>]* |
| 11 | +# - This will run rmc-compiler with RMC options + the given RUSTC_OPTIONS |
10 | 12 | set -eu
|
11 | 13 |
|
12 | 14 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
13 | 15 | REPO_DIR="$(dirname $SCRIPT_DIR)"
|
14 | 16 |
|
15 | 17 | RMC_PATH=${RMC_PATH:-""}
|
16 |
| -RMC_LIB_PATH=${RMC_LIB_PATH:-""} |
17 | 18 |
|
18 | 19 | shopt -s nullglob
|
19 |
| -set_rmc_path() { |
20 |
| - local RMC_CANDIDATES=("$REPO_DIR"/build/*/stage1/bin/rustc) |
| 20 | +set_paths() { |
| 21 | + # TODO: We should build into a specific folder. |
| 22 | + local RMC_CANDIDATES=("$REPO_DIR"/target/*/rmc-compiler) |
21 | 23 |
|
22 | 24 | if [ -z "${RMC_PATH}" ]
|
23 | 25 | then
|
24 | 26 | if [[ -z ${RMC_CANDIDATES:-""} ]] || [[ ${#RMC_CANDIDATES[@]} -ne 1 ]]
|
25 | 27 | then
|
26 | 28 | echo "ERROR: Could not find RMC binary."
|
27 |
| - echo "Looked for: $REPO_DIR/build/*/stage1/bin/rustc" |
| 29 | + echo "Looked for: '$REPO_DIR/target/*/rmc-compiler'" |
28 | 30 | echo "Was RMC successfully built first?"
|
29 | 31 | exit 1
|
30 | 32 | fi
|
31 | 33 | RMC_PATH=${RMC_CANDIDATES[0]}
|
32 | 34 | fi
|
33 | 35 | }
|
34 | 36 |
|
35 |
| -set_rmc_lib_path() { |
36 |
| - if [ -z "${RMC_LIB_PATH}" ] |
37 |
| - then |
38 |
| - local RMC_LIB_CANDIDATES=("$REPO_DIR"/target/*/librmc.rlib) |
39 |
| - if [[ -z ${RMC_LIB_CANDIDATES:-""} ]] || [[ ${#RMC_LIB_CANDIDATES[@]} -ne 1 ]] |
40 |
| - then |
41 |
| - echo "ERROR: Could not find RMC library." |
42 |
| - echo "Looked for: \"$REPO_DIR/target/*/librmc.rlib\"" |
43 |
| - echo "Try running <RMC_ROOT>/scripts/setup/build_rmc_lib.sh" |
44 |
| - exit 1 |
45 |
| - fi |
46 |
| - RMC_LIB_PATH=$(dirname ${RMC_LIB_CANDIDATES[0]}) |
47 |
| - fi |
48 |
| - # Having set RMC_LIB_PATH, find RMC_MACRO_LIB_PATH |
49 |
| - local MACRO_LIB_CANDIDATE=(${RMC_LIB_PATH}/deps/librmc_macros-*) |
50 |
| - if [[ ${#MACRO_LIB_CANDIDATE[@]} -ne 1 ]] |
51 |
| - then |
52 |
| - echo "ERROR: Could not find RMC library." |
53 |
| - echo "Looked for: \"${RMC_LIB_PATH}/deps/librmc_macros-*\"" |
54 |
| - echo "Try running <RMC_ROOT>/scripts/setup/build_rmc_lib.sh" |
55 |
| - exit 1 |
56 |
| - fi |
57 |
| - RMC_MACRO_LIB_PATH="${MACRO_LIB_CANDIDATE[0]}" |
58 |
| -} |
| 37 | +set_paths |
59 | 38 |
|
60 |
| -set_rmc_path |
61 |
| -if [ "${1:-''}" == "--rmc-path" ] |
| 39 | +# Hack to enable cargo rmc |
| 40 | +# |
| 41 | +# The rmc-compiler requires the flags related to the rmc libraries to be |
| 42 | +# in front of the ones that control rustc. |
| 43 | +# |
| 44 | +# For cargo rmc, cargo sometimes adds flags before the custom RUSTFLAGS, hence, |
| 45 | +# we use a special environment variable to set RMC specific flags. These flags |
| 46 | +# should only be enabled if --rmc-flags is present. |
| 47 | +args="${*#--rmc-flags}" |
| 48 | +if [ "$args" != "$*" ] |
62 | 49 | then
|
63 |
| - echo ${RMC_PATH} |
| 50 | + FLAGS=("${RMCFLAGS} $args") |
64 | 51 | else
|
65 |
| - set_rmc_lib_path |
66 |
| - RMC_FLAGS="-Z codegen-backend=gotoc \ |
67 |
| - -C overflow-checks=on \ |
68 |
| - -C panic=abort \ |
69 |
| - -Z panic_abort_tests=yes \ |
70 |
| - -Z trim-diagnostic-paths=no \ |
71 |
| - -Z human_readable_cgu_names \ |
72 |
| - --cfg=rmc \ |
73 |
| - -Zcrate-attr=feature(register_tool) \ |
74 |
| - -Zcrate-attr=register_tool(rmctool) \ |
75 |
| - -L ${RMC_LIB_PATH} \ |
76 |
| - --extern rmc \ |
77 |
| - -L ${RMC_LIB_PATH}/deps \ |
78 |
| - --extern librmc_macros=${RMC_MACRO_LIB_PATH} \ |
79 |
| - " |
80 |
| - if [ "${1:-''}" == "--rmc-flags" ] |
81 |
| - then |
82 |
| - echo ${RMC_FLAGS} |
83 |
| - else |
84 |
| - # Execute rmc |
85 |
| - "${RMC_PATH}" ${RMC_FLAGS} "$@" |
86 |
| - fi |
| 52 | + FLAGS=("$args") |
87 | 53 | fi
|
| 54 | + |
| 55 | +"${RMC_PATH}" ${FLAGS} |
0 commit comments