From 853e475d292ee9857ca66007c58095efff880d0e Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Thu, 29 Feb 2024 06:07:27 +0000 Subject: [PATCH] Add rustfmt.toml for OSDK --- Makefile | 2 +- osdk/rustfmt.toml | 10 ++++++++++ osdk/src/commands/build/bin.rs | 3 +-- osdk/src/commands/new/mod.rs | 4 ++-- tools/format_all.sh | 12 ++++++++---- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 osdk/rustfmt.toml diff --git a/Makefile b/Makefile index 1c01bc81e..15197a573 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ OSDK_CRATES := \ kernel/comps/virtio \ kernel/libs/aster-util -.PHONY: all build tools run test docs check clean update_initramfs +.PHONY: all build tools run test docs check clean update_initramfs install_osdk all: build diff --git a/osdk/rustfmt.toml b/osdk/rustfmt.toml new file mode 100644 index 000000000..6ac76badc --- /dev/null +++ b/osdk/rustfmt.toml @@ -0,0 +1,10 @@ +# This file contains the same content as the rustfmt.toml in the root directory, +# but configurations that rely on nightly Rust are commented out. +# This is needed because unlike the rest of the project, +# OSDK is built with the stable Rust and thus cannot use unstable features. +# Once these rustfmt configurations become stable, +# the corresponding lines can be uncommented. + +# imports_granularity="Crate" +# group_imports="StdExternalCrate" +reorder_imports=true diff --git a/osdk/src/commands/build/bin.rs b/osdk/src/commands/build/bin.rs index 5e275adc5..43fda2dc0 100644 --- a/osdk/src/commands/build/bin.rs +++ b/osdk/src/commands/build/bin.rs @@ -154,8 +154,7 @@ fn install_setup_with_arch( cmd.arg("--force"); cmd.arg("--root").arg(install_dir.as_ref()); // TODO: Use the latest revision when modifications on the `osdk` branch is merged. - cmd.arg("--git") - .arg(crate::util::ASTER_GIT_LINK); + cmd.arg("--git").arg(crate::util::ASTER_GIT_LINK); cmd.arg("--rev").arg(crate::util::ASTER_GIT_REV); cmd.arg("--target").arg(match arch { SetupInstallArch::X86_64 => "x86_64-unknown-none", diff --git a/osdk/src/commands/new/mod.rs b/osdk/src/commands/new/mod.rs index d59331a4d..02e486ab5 100644 --- a/osdk/src/commands/new/mod.rs +++ b/osdk/src/commands/new/mod.rs @@ -12,7 +12,7 @@ use crate::{ cli::NewArgs, error::Errno, error_msg, - util::{cargo_new_lib, get_cargo_metadata, aster_crate_dep}, + util::{aster_crate_dep, cargo_new_lib, get_cargo_metadata}, }; pub fn execute_new_command(args: &NewArgs) { @@ -75,7 +75,7 @@ fn create_osdk_manifest(cargo_metadata: &serde_json::Value) { // The apt OVMF repo installs to `/usr/share/OVMF` fs::write( osdk_manifest_path, - r#"\ + r#" [boot] ovmf = "/usr/share/OVMF" [qemu] diff --git a/tools/format_all.sh b/tools/format_all.sh index 7a2d1615b..707c8c80c 100755 --- a/tools/format_all.sh +++ b/tools/format_all.sh @@ -6,7 +6,6 @@ WORKSPACE_ROOT="$(dirname "$(readlink -f "$0")")/.." EXCLUDED_CRATES=$(sed -n '/^\[workspace\]/,/^\[.*\]/{/exclude = \[/,/\]/p}' "$WORKSPACE_ROOT/Cargo.toml" | grep -v "exclude = \[" | tr -d '", \]') - CHECK_MODE=false if [ "$#" -eq 1 ]; then @@ -31,15 +30,20 @@ fi for CRATE in $EXCLUDED_CRATES; do CRATE_DIR="$WORKSPACE_ROOT/$CRATE" - # `cargo-component` crate currently is pinned to use Rust nightly-2023-02-05 version, - # and when using this script in the current Docker environment, it will - # additionally download this version of Rust. # Here temporarily skip processing this crate for now considering that this crate # is not currently in use or under development. case "$CRATE" in + # `cargo-component` crate currently is pinned to use Rust nightly-2023-02-05 version, + # and when using this script in the current Docker environment, it will + # additionally download this version of Rust. *cargo-component*) continue ;; + # `target/osdk/base` is generated by OSDK and does not need to be formatted. The directory + # does not exist before running `make build`. + *target/osdk/base*) + continue + ;; esac if [ -d "$CRATE_DIR" ]; then