Sam Leffler | af1f24f | 2022-05-11 21:16:47 +0000 | [diff] [blame] | 1 | #! /bin/bash |
Sam Leffler | 30b4cad | 2022-08-10 13:59:23 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2020 Google LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Sam Leffler | af1f24f | 2022-05-11 21:16:47 +0000 | [diff] [blame] | 16 | |
| 17 | # Script for running Shodan cargo outside the build; useful |
| 18 | # for doing things like kcargo tree or kcargo clippy. |
| 19 | |
| 20 | if [[ -z "${ROOTDIR}" ]]; then |
| 21 | echo "Source build/setup.sh first" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | # HACK: sel4-config needs a path to the kernel build which could be |
| 26 | # in debug or release |
June Tate-Gans | 548dde6 | 2022-11-22 11:06:31 -0600 | [diff] [blame] | 27 | export SEL4_OUT_DIR=${SEL4_OUT_DIR:-"$ROOTDIR/out/cantrip/riscv32-unknown-elf/debug/kernel/"} |
Sam Leffler | af1f24f | 2022-05-11 21:16:47 +0000 | [diff] [blame] | 28 | if [[ ! -d "${SEL4_OUT_DIR}/gen_config" ]]; then |
| 29 | echo "No kernel build found at ${SEL4_OUT_DIR}; build a kernel first" |
| 30 | exit 2 |
| 31 | fi |
| 32 | |
June Tate-Gans | 548dde6 | 2022-11-22 11:06:31 -0600 | [diff] [blame] | 33 | CARGO="${CARGO_HOME}/bin/cargo +${CANTRIP_RUST_VERSION}" |
Sam Leffler | af1f24f | 2022-05-11 21:16:47 +0000 | [diff] [blame] | 34 | CARGO_TARGET="--target riscv32imac-unknown-none-elf" |
Sam Leffler | dad38b9 | 2023-01-30 17:15:56 +0000 | [diff] [blame] | 35 | CARGO_TARGET="--target ${RUST_TARGET:-riscv32imac-unknown-none-elf} --features CONFIG_PLAT_SHODAN" |
Sam Leffler | af1f24f | 2022-05-11 21:16:47 +0000 | [diff] [blame] | 36 | CARGO_OPTS='-Z unstable-options -Z avoid-dev-deps' |
| 37 | |
| 38 | export RUSTFLAGS='-Z tls-model=local-exec' |
| 39 | |
| 40 | cmd=${1:-build} |
| 41 | case "$1" in |
| 42 | fmt) |
| 43 | ${CARGO} $*;; |
| 44 | ""|-*) |
| 45 | # TODO(sleffler): maybe set --target-dir to avoid polluting the src tree |
| 46 | ${CARGO} build ${CARGO_OPTS} ${CARGO_TARGET};; |
| 47 | *) |
| 48 | ${CARGO} $* ${CARGO_OPTS} ${CARGO_TARGET};; |
| 49 | esac |