blob: 1de8fd460081054e9a0840036df94073c6e2b2dd [file] [log] [blame]
Sam Leffleraf1f24f2022-05-11 21:16:47 +00001#! /bin/bash
Sam Leffler30b4cad2022-08-10 13:59:23 -07002#
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 Leffleraf1f24f2022-05-11 21:16:47 +000016
17# Script for running Shodan cargo outside the build; useful
18# for doing things like kcargo tree or kcargo clippy.
19
20if [[ -z "${ROOTDIR}" ]]; then
21 echo "Source build/setup.sh first"
22 exit 1
23fi
24
25# HACK: sel4-config needs a path to the kernel build which could be
26# in debug or release
June Tate-Gans548dde62022-11-22 11:06:31 -060027export SEL4_OUT_DIR=${SEL4_OUT_DIR:-"$ROOTDIR/out/cantrip/riscv32-unknown-elf/debug/kernel/"}
Sam Leffleraf1f24f2022-05-11 21:16:47 +000028if [[ ! -d "${SEL4_OUT_DIR}/gen_config" ]]; then
29 echo "No kernel build found at ${SEL4_OUT_DIR}; build a kernel first"
30 exit 2
31fi
32
June Tate-Gans548dde62022-11-22 11:06:31 -060033CARGO="${CARGO_HOME}/bin/cargo +${CANTRIP_RUST_VERSION}"
Sam Leffleraf1f24f2022-05-11 21:16:47 +000034CARGO_TARGET="--target riscv32imac-unknown-none-elf"
Sam Lefflerdad38b92023-01-30 17:15:56 +000035CARGO_TARGET="--target ${RUST_TARGET:-riscv32imac-unknown-none-elf} --features CONFIG_PLAT_SHODAN"
Sam Leffleraf1f24f2022-05-11 21:16:47 +000036CARGO_OPTS='-Z unstable-options -Z avoid-dev-deps'
37
38export RUSTFLAGS='-Z tls-model=local-exec'
39
40cmd=${1:-build}
41case "$1" in
42fmt)
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};;
49esac