chore: Cleanup install script

main
Sean McBride 4 years ago
parent 0b115374a0
commit d5e1c8f73c

@ -6,14 +6,11 @@ build:
test -f ./${COMPILER}/wasmception/dist/bin/clang || make -C ${COMPILER}/wasmception
@cd ${COMPILER} && cargo build --release && cd ${ROOT}
# Sanity check that the aWsm compiler built and is in our PATH
.PHONY: build-validate
build-validate:
which awsm
awsm --version
cd ${COMPILER}
which awsm
awsm --version
cd ${ROOT}
.PHONY: build-dev
build-dev:
@ -44,6 +41,6 @@ runtime:
make -C runtime
.PHONY: install
install: build build-validate rtinit
install: build rtinit
@./install.sh wasmception

@ -1,17 +1,49 @@
#!/bin/sh
# Executing by the root Makefile, typically within the sledge-dev build container
#!/bin/bash
# This script is responsible for copying, linking, and aliasing all of our build tools such that they are
# in known paths that we can add to PATH and LD_LIBRARY_PATH. The binaries go into "${SYS_PREFIX}/bin" and
# the libraries go into "${SYS_PREFIX}/lib". By default, SYS_PREFIX is `/opt/sledge/`, which means that this
# script is assumed to be executed as root, as in our Docker build container. However, by by setting
# SYS_PREFIX to a directory that the user has access to, this can be avoided.
#
# For example, in the GitHub Actions workflow, SYS_PREFIX is set to the topmost project directory and the
# environment is updated as follows.
#
# SYS_PREFIX="$(pwd)" ./install.sh
# PATH="$(pwd)/bin:$PATH"
# LD_LIBRARY_PATH="$(pwd)/lib:$LD_LIBRARY_PATH"
#
# This is currently executed
# - Indirectly via `make install` in the root Makefile, typically when the sledge-dev build container is built
# - Directly by the GitHub workflow
#
# The script takes either wasmception or wasi as the first argument to install either wasmception or WASI-SDK
# If no argument is provided, wasmception is assumed
# If either wasmception or wasi is provided, an additional `-d` or `--dry-run` flag can be provided to view the commands
# and paths that would be generated. This is helpful for sanity checking when setting SYS_PREFIX and using in a new context
echo "Setting up toolchain environment"
# Get the path of this repo
# SYS_SRC_PREFIX could be externally set
# This is written assuming that install.sh might be in the project top level directory or a subdirectory,
# but that it is always called with a relative path from the project root
for last_arg in "$@"; do :; done
if [[ $last_arg == "-d" ]] || [[ $last_arg == "--dry-run" ]]; then
DRY_RUN=true
else
DRY_RUN=false
fi
if $DRY_RUN; then
DRY_RUN_PREFIX=echo
else
DRY_RUN_PREFIX=
fi
# Get the absolute path of the topmost project directly
# The use of dirname is particular. It seems unneccesary how this script is run
SYS_SRC_PREFIX=${SYS_SRC_PREFIX:-"$(
cd "$(dirname "$(dirname "${0}")")" || exit 1
pwd -P
)"}
echo SYS_SRC_PREFIX: "$SYS_SRC_PREFIX"
$DRY_RUN && echo SYS_SRC_PREFIX: "$SYS_SRC_PREFIX"
# And check for the presence of this script to make sure we got it right
if [ ! -x "${SYS_SRC_PREFIX}/install.sh" ]; then
@ -25,23 +57,23 @@ COMPILER_EXECUTABLE=$COMPILER
# /opt/sledge
SYS_PREFIX=${SYS_PREFIX:-"/opt/${SYS_NAME}"}
echo SYS_PREFIX: "$SYS_PREFIX"
$DRY_RUN && echo SYS_PREFIX: "$SYS_PREFIX"
# /sledge, where the sledge repo is mounted from the host
SYS_SRC_PREFIX=${SYS_SRC_PREFIX:-"/${SYS_NAME}"}
echo SYS_SRC_PREFIX: "$SYS_SRC_PREFIX"
$DRY_RUN && echo SYS_SRC_PREFIX: "$SYS_SRC_PREFIX"
# The release directory containing the binary of the aWsm compiler
SYS_COMPILER_REL_DIR=${SYS_COMPILER_REL_DIR:-"${SYS_SRC_PREFIX}/${COMPILER}/target/release"}
echo SYS_COMPILER_REL_DIR: "$SYS_COMPILER_REL_DIR"
$DRY_RUN && echo SYS_COMPILER_REL_DIR: "$SYS_COMPILER_REL_DIR"
# /opt/sledge/bin
SYS_BIN_DIR=${SYS_BIN_DIR:-"${SYS_PREFIX}/bin"}
echo SYS_BIN_DIR: "$SYS_BIN_DIR"
$DRY_RUN && echo SYS_BIN_DIR: "$SYS_BIN_DIR"
# /opt/sledge/lib
SYS_LIB_DIR=${SYS_LIB_DIR:-"${SYS_PREFIX}/lib"}
echo SYS_LIB_DIR: "$SYS_LIB_DIR"
$DRY_RUN && echo SYS_LIB_DIR: "$SYS_LIB_DIR"
# The first argument can be either wasi or wasmception. This determines the system interface used
# The default is wasmception
@ -53,7 +85,7 @@ if [ $# -eq 0 ] || [ "$1" = "wasmception" ]; then
WASM_SYSROOT=${WASM_SYSROOT:-"${WASM_PREFIX}/sysroot"}
WASM_TARGET=${WASM_TARGET:-"wasm32-unknown-unknown-wasm"}
WASM_BIN_PREFIX=${WASM_BIN_PREFIX:-"$WASM_TARGET"}
WASM_TOOLS=ar
WASM_TOOLS=(ar)
elif [ "$1" = "wasi" ]; then
echo "Setting up for wasi-sdk"
WASM_PREFIX=${WASM_PREFIX:-${WASM_SDK:-"/opt/wasi-sdk"}}
@ -61,27 +93,24 @@ elif [ "$1" = "wasi" ]; then
WASM_SYSROOT=${WASM_SYSROOT:-"${WASM_PREFIX}/share/sysroot"}
WASM_TARGET=${WASM_TARGET:-"wasm32-wasi"}
WASM_BIN_PREFIX=${WASM_BIN_PREFIX:-"$WASM_TARGET"}
WASM_TOOLS=ar dwarfdump nm ranlib size
WASM_TOOLS=(ar dwarfdump nm ranlib size)
fi
echo WASM_PREFIX: "$WASM_PREFIX"
echo WASM_BIN: "$WASM_BIN"
echo WASM_SYSROOT: "$WASM_SYSROOT"
echo WASM_TARGET: "$WASM_TARGET"
echo WASM_BIN_PREFIX: "$WASM_BIN_PREFIX"
echo WASM_TOOLS: "$WASM_TOOLS"
$DRY_RUN && echo WASM_PREFIX: "$WASM_PREFIX"
$DRY_RUN && echo WASM_BIN: "$WASM_BIN"
$DRY_RUN && echo WASM_SYSROOT: "$WASM_SYSROOT"
$DRY_RUN && echo WASM_TARGET: "$WASM_TARGET"
$DRY_RUN && echo WASM_BIN_PREFIX: "$WASM_BIN_PREFIX"
$DRY_RUN && echo WASM_TOOLS: "${WASM_TOOLS[@]}"
# Delete all existing installations of the binaries
echo rm -f "${SYS_BIN_DIR}"/*
rm -f "${SYS_BIN_DIR}"/*
$DRY_RUN_PREFIX rm -f "${SYS_BIN_DIR}"/*
# And reinstall
echo install -d -v "$SYS_BIN_DIR" || exit 1
install -d -v "$SYS_BIN_DIR" || exit 1
$DRY_RUN_PREFIX install -d -v "$SYS_BIN_DIR" || exit 1
# Symbolically link the Awsm compiler
# /sledge/awsm/target/release/silverfish /opt/sledge/bin/awsm
echo ln -sfv "${SYS_COMPILER_REL_DIR}/${COMPILER_EXECUTABLE}" "${SYS_BIN_DIR}/${COMPILER_EXECUTABLE}"
ln -sfv "${SYS_COMPILER_REL_DIR}/${COMPILER_EXECUTABLE}" "${SYS_BIN_DIR}/${COMPILER_EXECUTABLE}"
$DRY_RUN_PREFIX ln -sfv "${SYS_COMPILER_REL_DIR}/${COMPILER_EXECUTABLE}" "${SYS_BIN_DIR}/${COMPILER_EXECUTABLE}"
# Generate shell script stubs that act as aliases that automatically set the approproiate target and sysroot
# for either Wasmception or WASI-SDK
@ -95,29 +124,24 @@ for file in clang clang++; do
exec "${WASM_BIN}/${file}" --target="$WASM_TARGET" --sysroot="$WASM_SYSROOT" "\$@"
EOT
cat "$wrapper_file"
echo install -p -v "$wrapper_file" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
install -p -v "$wrapper_file" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
echo rm -f "$wrapper_file"
$DRY_RUN_PREFIX install -p -v "$wrapper_file" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
$DRY_RUN && echo rm -f "$wrapper_file"
rm -f "$wrapper_file"
done
exit
# Link the LLVM Tools with the proper prefix
for file in ${WASM_TOOLS}; do
echo ln -sfv "${WASM_BIN}/llvm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
ln -sfv "${WASM_BIN}/llvm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
for file in "${WASM_TOOLS[@]}"; do
$DRY_RUN_PREFIX ln -sfv "${WASM_BIN}/llvm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
done
# Link any other tools with the proper prefix
for file in ld; do
echo ln -sfv "${WASM_BIN}/wasm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
ln -sfv "${WASM_BIN}/wasm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
OTHER_TOOLS=(ld)
for file in "${OTHER_TOOLS[@]}"; do
$DRY_RUN_PREFIX ln -sfv "${WASM_BIN}/wasm-${file}" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-${file}"
done
# Link clang as gcc if needed
echo ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-gcc"
ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-gcc"
echo ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang++" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-g++"
ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang++" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-g++"
$DRY_RUN_PREFIX ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-gcc"
$DRY_RUN_PREFIX ln -svf "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-clang++" "${SYS_BIN_DIR}/${WASM_BIN_PREFIX}-g++"
echo "Done!"

Loading…
Cancel
Save