Repository: theseus-os/Theseus (language: rust)

Issue:
Update `rust-toolchain` file to new standard with `target` support
Now that #792 is merged, the new target `x86_64-unknown-uefi` is required to build Theseus for UEFI. We should leverage the features of the [new `rust-toolchain.toml`](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file) to let Rust handle adding the required targets for us, since we already rely on it to handle the toolchain installation.

Bonus: we can also use it to specify components, e.g., `rust-std`.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/check-clippy.yaml b/.github/workflows/check-clippy.yaml
index 6835255ebe..b4a8820d57 100644
--- a/.github/workflows/check-clippy.yaml
+++ b/.github/workflows/check-clippy.yaml
@@ -12,10 +12,6 @@ jobs:
           git submodule update --init --recursive
       - name: "Install nasm"
         run: sudo apt install nasm
-      - name: "Install Rust toolchain"
-        run: |
-          (echo "rustup toolchain install "; cat rust-toolchain; printf -- "-x86_64-unknown-linux-gnu;"; echo "rustup component add clippy rust-src --toolchain "; cat rust-toolchain; printf -- "-x86_64-unknown-linux-gnu;") | tr -d "\r" | tr -d "\n" > cmd.txt
-          bash cmd.txt;
       - name: "Run Clippy"
         env:
           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/Makefile b/Makefile
index df969cb2ba..5f10bef6f4 100644
--- a/Makefile
+++ b/Makefile
@@ -91,22 +91,6 @@ $(error Error: unsupported option "bootloader=$(bootloader)". Options are 'grub'
 endif
 
 
-###################################################################################################
-### For ensuring that the host computer has the proper version of the Rust compiler
-###################################################################################################
-RUSTC_VERSION := $(shell cat rust-toolchain)
-check-rustc:
-## Building Theseus requires the 'rust-src' component. If we can't install that, install the required rust toolchain and retry.
-## If it still doesn't work, issue an error, since 'rustup' is probably missing.
-	@rustup component add rust-src || (rustup toolchain install $(RUSTC_VERSION) && rustup component add rust-src) || \
-	(\
-		echo -e "\nError: 'rustup' isn't installed.";\
-		echo -e "Please install rustup and try again.\n";\
-		exit 1 \
-	)
-
-
-
 ###################################################################################################
 ### This section contains targets to actually build Theseus components and create an iso file.
 ###################################################################################################
@@ -147,7 +131,7 @@ APP_CRATE_NAMES += $(EXTRA_APP_CRATE_NAMES)
 ### PHONY is the list of targets that *always* get rebuilt regardless of dependent files' modification timestamps.
 ### Most targets are PHONY because cargo itself handles whether or not to rebuild the Rust code base.
 .PHONY: all full \
-		check-rustc check-usb \
+		check-usb \
 		clean clean-doc clean-old-build \
 		run run_pause iso build cargo copy_kernel $(bootloader) extra_files \
 		libtheseus \
@@ -304,7 +288,7 @@ endif
 
 ## This target invokes the actual Rust build process via `cargo`.
 cargo : export override FEATURES+=--features nano_core/$(boot_spec)
-cargo: check-rustc 
+cargo:
 	@mkdir -p $(BUILD_DIR)
 	@mkdir -p $(NANO_CORE_BUILD_DIR)
 	@mkdir -p $(OBJECT_FILES_BUILD_DIR)
@@ -592,7 +576,7 @@ docs: doc
 doc: export override RUSTDOCFLAGS += -A rustdoc::private_intra_doc_links
 doc : export override RUSTFLAGS=
 doc : export override CARGOFLAGS=
-doc: check-rustc
+doc:
 ## Build the docs for select library crates, namely those not hosted online.
 ## We do this first such that the main `cargo doc` invocation below can see and link to them.
 	@cargo doc --no-deps \
diff --git a/README.md b/README.md
index 2c35ac6ddc..96273f8c0a 100644
--- a/README.md
+++ b/README.md
@@ -136,7 +136,7 @@ Note: building and running Theseus within a Docker container may be slower than
 
 Notes on Docker usage:    
   * The docker-based workflow should only require you to re-run the `run_docker.sh` script multiple times when re-building or running Theseus after modifying its code. You shouldn't need to re-run `build_docker.sh` multiple times, though it won't hurt.
-  * KVM doesn't currently work in docker. To run Theseus in QEMU using KVM, you can build Theseus within docker, exit the container (via `Ctrl+D`), and then run `make orun host=yes` on your host machine.
+  * KVM doesn't currently work in docker. To run Theseus in QEMU using KVM, you can build Theseus within docker, exit the container (via <kbd>Ctrl</kbd> + <kbd>D</kbd>`), and then run `make orun host=yes` on your host machine.
 
 
 ## Building and Running
@@ -145,7 +145,7 @@ Build the default Theseus OS image and run it in QEMU:
 make run
 ```
 
-Build a full Theseus OS image with all features and crates enabled:
+Or, build a full Theseus OS image with all features and crates enabled:
 ```sh
 make full   ## or `make all`
 ```
@@ -240,22 +240,7 @@ For VS Code, recommended plugins are:
  * **rust-analyzer**, by matklad
  * **Better TOML**, by bungcip
  * **x86 and x86_64 Assembly**, by 13xforever
-
-### Fixing Rustup, Rust Toolchain, or RLS Problems
-Sometimes things just don't want to behave, especially if there were issues with the currently-chosen Rust nightly version.
-In that case, try the following steps to fix it:
- * Set your default Rust toolchain to the one version in the `rust-toolchain` file, for example:
-    ```sh
-    rustup default $(cat rust-toolchain)
-    ```
- * With your newly-set default toolchain, add the necessary components:    
-    ```
-    rustup component add rust-src
-    ```
- * In VS Code (or whatever IDE you're using), uninstall and reinstall the Rust-related extension(s), restarting the IDE each time.
- * Check your IDE's settings to make sure that no weird Rust settings have been selected; building Theseus doesn't require any special settings. 
- * If you're still having issues, remove all other Rust toolchain versions besides the default one and try again. You can see other installed toolchains with `rustup toolchain list`.
-
+ 
 
 ## Acknowledgements
 We would like to express our thanks to the [OS Dev wiki](https://wiki.osdev.org/) and its community and to Philipp Oppermann's [blog_os](https://os.phil-opp.com/) for serving as excellent starting points for Theseus. The early days of Theseus's development progress are indebted to these resources. 
diff --git a/docker/Dockerfile b/docker/Dockerfile
index bc417b1087..866465b3de 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -7,15 +7,12 @@ LABEL author=kevinaboos@gmail.com
 
 
 # These build args are required.
-# RUSTC_VERSION is the Rust version and build date, e.g., "nightly-2019-10-17"
 # USER is the current user's name: "kevin"
 # UID is that same user's id: "1000"
 # GID is that same user's group id: "1000"
-ARG RUSTC_VERSION
 ARG USER
 ARG UID
 ARG GID
-RUN test -n "$RUSTC_VERSION" || (echo "\nError: RUSTC_VERSION build arg not set\n" && false)
 RUN test -n "$USER" || (echo "\nError: USER build arg not set\n" && false)
 RUN test -n "$UID" || (echo "\nError: UID build arg not set\n" && false)
 RUN test -n "$GID" || (echo "\nError: GID build arg not set\n" && false)
@@ -60,6 +57,3 @@ ENV HOME="/home/${USER}"
 RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
 # To enable us to use Rust, add its binaries to our path.
 ENV PATH="$HOME/.cargo/bin:${PATH}"
-
-# Install the specific version of the Rust toolchain currently required by Theseus.
-RUN rustup toolchain install ${RUSTC_VERSION} && rustup component add rust-src
diff --git a/docker/build_docker.sh b/docker/build_docker.sh
index c4a7c50a68..b038463d91 100755
--- a/docker/build_docker.sh
+++ b/docker/build_docker.sh
@@ -17,12 +17,8 @@ THESEUS_BASE_DIR=$(readlink -f ${DOCKER_DIR}/.. )
 ### Always run this script with the `docker` directory as the working directory.
 cd ${DOCKER_DIR} 
 
-### Get the current required version of Rust from our rust-toolchain file
-RUSTC_VERSION=$(cat ${THESEUS_BASE_DIR}/rust-toolchain)
-
 ### Build the docker image
 docker build \
-    --build-arg RUSTC_VERSION=${RUSTC_VERSION} \
     --build-arg USER=$(id -un) \
     --build-arg UID=$(id -u) \
     --build-arg GID=$(id -g) \
diff --git a/rust-toolchain b/rust-toolchain
deleted file mode 100644
index 78c5fdbb6e..0000000000
--- a/rust-toolchain
+++ /dev/null
@@ -1,1 +0,0 @@
-nightly-2023-01-11
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 0000000000..e548fa8690
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,7 @@
+[toolchain]
+channel = "nightly-2023-01-11"
+components = [ "rust-src", "clippy" ]
+## Rustup always installs the host target by default, so we don't need to specify it here.
+## All we need to specify is the uefi target(s) used to build our `uefi-bootloader`.
+targets = [ "x86_64-unknown-uefi" ]
+profile = "default"


Test patch: