diff --git a/README.md b/README.md index 06df7fd3..0a505ccb 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,31 @@ Programming language that compiles to C - [Jenkins](https://jenkins.exokomodo.com/job/Daybreak) - [Language Cheat Sheet](https://docs.google.com/document/d/1VsP0L_J_NGatTqUZniUga4odmSZfCDRTvfQCVJQn9ac/edit?usp=sharing) +## Installation +To install daybreak locally, clone the Daybreak repo to your machine, and run `daybreak_install.sh` + +### (Recommended) Git Clone via SSH: +Cloning via SSH will allow for you to contribute to Daybreak and push commits +```bash +# Clone repository locally +git clone git@github.com:ExoKomodo/Daybreak.git +# Temporarily move into Daybreak repo +cd ./Daybreak +# Follow the instructions of the install script +bash ./daybreak_install.sh +``` + +### (Not recommended) Git clone via HTTPS: +Cloning via HTTPS will only allow for you to clone the repo and install Daybreak. You will not be able to push commits to Github with an HTTPS-cloned repository. +```bash +# Clone repository locally +git clone https://github.com/ExoKomodo/Daybreak.git +# Temporarily move into Daybreak repo +cd ./Daybreak +# Follow the instructions of the install script +bash ./daybreak_install.sh +``` + ## Suggested VSCode Extensions Reference [`devcontainer.json`](./.devcontainer/devcontainer.json)'s `extensions` array to see what VSCode extensions are recommended. @@ -134,18 +159,6 @@ sudo update-alternatives --install /usr/bin/cc cc $(which zig-wasi) 1 # Create / CC_COMPILER=zig-wasi sudo update-alternatives --set cc $(which $CC_COMPILER) ``` -###### WASM via Clang -Similar to configuring `zig`, an for clang is an easy way to compile WASM via wasi. Let's create an intercept compiler script called `clang-wasi`: -```bash -sudo echo "clang --target=wasm32-unknown-wasi --sysroot /absolute/path/to/daybreak/repo/deps/wasi-sysroot \$@" > /usr/bin/clang-wasi -sudo chmod +x /usr/bin/clang-wasi - -sudo update-alternatives --install /usr/bin/cc cc $(which wasm-clang) 1 # Create /usr/bin/cc binary if it does not exist, and links wasm-clang to cc -# If cc already exists, this may fail and you will need to increment the number at the end of the command to lower the priority. -# cc should then be explicitly set to the compiler you want -CC_COMPILER=wasm-clang -sudo update-alternatives --set cc $(which $CC_COMPILER) -``` #### Windows Install [MSYS2](https://www.msys2.org/) @@ -197,7 +210,7 @@ sudo chmod +x /usr/bin/zig sudo update-alternatives --install /usr/bin/cc cc $(which zig) 1 # Create /usr/bin/cc binary if it does not exist, and links zig to cc # If cc already exists, this may fail and you will need to increment the number at the end of the command to lower the priority. # cc should then be explicitly set to the compiler you want -export CC=zig +export CC_COMPILER=zig ``` ### Build diff --git a/daybreak_install.sh b/daybreak_install.sh new file mode 100755 index 00000000..6a0eee2b --- /dev/null +++ b/daybreak_install.sh @@ -0,0 +1,103 @@ +#! /bin/bash + +set -e + +COMPILER_BACKENDS="gcc clang zig" + +function _choose_compiler_backend() { + if [ $# -eq 0 ]; then + echo "Could not find a supported compiler backend!" + echo "Please install and make available on PATH one of the following:" + echo ${COMPILER_BACKENDS} + exit 1 + fi + + CC_COMPILER=$1 + shift + echo "Checking for compiler backend ${CC_COMPILER}" + if ! command -v ${CC_COMPILER} &> /dev/null; then + echo "Missing compiler backend ${CC_COMPILER}" + set_compiler $@ + fi +} + +function bootstrap_install() { + echo "Bootstrapping Daybreak for the local installation..." + DAYBREAK_BOOTSTRAP=${DAYBREAK_SOURCE_FOLDER}/bootstrap/${OS}/daybreak + DAYBREAK_OUTPUT=${DAYBREAK_HOME}/bin/daybreak + if [[ ${OS} = "windows" ]]; then + DAYBREAK_BOOTSTRAP=${DAYBREAK_BOOTSTRAP}.exe + DAYBREAK_OUTPUT=${DAYBREAK_OUTPUT}.exe + fi + C_INCLUDE_PATH=${DAYBREAK_SOURCE_FOLDER}/src/include + ${DAYBREAK_BOOTSTRAP} ${DAYBREAK_SOURCE_FOLDER}/src/main.day -o ${DAYBREAK_OUTPUT} >> /dev/null + echo "Successfully bootstrapped Daybreak!" +} + +function print_export_env() { + echo "" + echo "Identifying default shell and the associated rcfile..." + RC_FILE=${HOME}/.$(basename $(echo ${SHELL}))rc + echo "Identified:" + echo " shell -> ${SHELL}" + echo " rcfile -> ${RC_FILE}" + + echo "" + echo "##############" + echo "# Next Steps #" + echo "##############" + echo "Run all of the following commands in your terminal to finish the Daybreak installation" + echo "The first two commands persist the configuration chosen by this install script" + echo "The third command adds daybreak tools to your PATH for every login session and not just the current login session" + echo "" + echo "echo 'export CC_COMPILER=${CC_COMPILER}' >> ${RC_FILE}" + echo "echo 'export DAYBREAK_HOME=${DAYBREAK_HOME}' >> ${RC_FILE}" + echo 'echo '"'"'export PATH=${DAYBREAK_HOME}/bin:${PATH}'"'"''" >> ${RC_FILE}" + echo "" + echo "Daybreak should now be fully configured and available!" +} + +function set_default_env() { + echo "Checking environment variables and temporarily setting default values for unset env vars" + echo "" + echo "Identifying OS..." + case "$(uname -s)" in + Linux*) OS=linux;; + Darwin*) OS=osx;; + CYGWIN*) OS=windows;; + MINGW*) OS=windows;; + *) echo "Failed to identify OS"; exit 1;; + esac + echo "Identified OS as ${OS}" + echo "" + + if [ -z ${CC_COMPILER} ]; then + _choose_compiler_backend ${COMPILER_BACKENDS} + echo "CC_COMPILER set to default: ${CC_COMPILER} -> $(which ${CC_COMPILER})" + else + echo "CC_COMPILER already set to: ${CC_COMPILER} -> $(which ${CC_COMPILER})" + fi + + if [ -z ${DAYBREAK_HOME} ]; then + DAYBREAK_HOME=${HOME}/.daybreak + echo "DAYBREAK_HOME set to default: ${DAYBREAK_HOME}" + else + echo "DAYBREAK_HOME already set to: ${DAYBREAK_HOME}" + fi + + update-alternatives --set cc $(which ${CC_COMPILER}) + echo "" +} + +if [ $# -eq 0 ]; then + DAYBREAK_SOURCE_FOLDER=. +else + DAYBREAK_SOURCE_FOLDER=$1 + shift +fi + +set_default_env + +bootstrap_install + +print_export_env