Skip to content

Commit

Permalink
Add initial Rust infrastructure files
Browse files Browse the repository at this point in the history
Adds workspace level files to build Rust in the repo.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Aug 25, 2023
1 parent 0a6bebd commit cb212da
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags/
.vscode/
*.bak
BuildConfig.conf
Cargo.lock

# Repo-specific
_TEMP_*/
Expand All @@ -16,3 +17,6 @@ _TEMP_*/
/Common
/Silicon
/MU_BASECORE

# Ignore Rust build output
/target
49 changes: 49 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[config]
default_to_workspace = false

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
RUSTC_BOOTSTRAP = 1
ARCH = "X64"
TARGET_TRIPLE = { source = "${ARCH}", mapping = { "X64" = "x86_64-unknown-uefi", "IA32" = "i686-unknown-uefi", "AARCH64" = "aarch64-unknown-uefi", "LOCAL" = "${CARGO_MAKE_RUST_TARGET_TRIPLE}" }, condition = { env_not_set = [ "TARGET_TRIPLE" ] } }
PACKAGE_TARGET = {value = "-p ${CARGO_MAKE_TASK_ARGS}",condition = { env_true = [ "CARGO_MAKE_TASK_ARGS", ] } }

BUILD_FLAGS = "--profile ${RUSTC_PROFILE} --target ${TARGET_TRIPLE} -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem -Zunstable-options --timings=html"
TEST_FLAGS = { value = "", condition = { env_not_set = ["TEST_FLAGS"] } }
COV_FLAGS = { value = "--out Html --exclude-files **/tests/*", condition = { env_not_set = ["COV_FLAGS"] } }

[env.development]
RUSTC_PROFILE = "dev"
RUSTC_TARGET = "debug"

[env.release]
RUSTC_PROFILE = "release"
RUSTC_TARGET = "release"

[tasks.build]
description = """Builds a single rust package.
Customizations:
-p [development|release]: Builds in debug or release. Default: development
-e ARCH=[IA32|X64|AARCH64|LOCAL]: Builds with specifed arch. Default: X64
Example:
`cargo make build RustModule`
`cargo make -p release build RustModule`
`cargo make -e ARCH=IA32 build RustLib`
"""
clear = true
command = "cargo"
args = ["build", "@@split(PACKAGE_TARGET, )", "@@split(BUILD_FLAGS, )"]

[tasks.test]
description = "Builds all rust tests in the workspace. Example `cargo make test`"
clear = true
command = "cargo"
args = ["test", "@@split(PACKAGE_TARGET, )", "@@split(TEST_FLAGS, )"]

[tasks.coverage]
description = "Build and run all tests and calculate coverage."
clear = true
command = "cargo"
args = ["tarpaulin", "@@split(PACKAGE_TARGET, )", "@@split(COV_FLAGS, )", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target"]
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.71.1"
21 changes: 21 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# rustfmt (and cargo fmt) will automatically pick up this config when run in the workspace.

# Note that some items are included here set to their default values. This is to explicitly
# reveal settings for more common options.

# Keep these options sorted in ascending order to ease lookup with rustfmt documentation.

edition = "2021" # This would normally be picked up from Cargo.toml if not specified here
force_explicit_abi = true # Always print the ABI for extern items (e.g. extern {... will become extern "C" {...)
hard_tabs = false # Always uses spaces for indentation and alignment
max_width = 120 # The maximum width of each line
merge_derives = false # Do not merge derives into a single line (leave to author discretion).
imports_granularity = "Crate" # Merge imports from a single crate into separate statements.
newline_style = "Windows" # Always use Windows line endings '\r\n'
reorder_impl_items = false # Do not force where type and const before macros and methods in impl blocks.
reorder_imports = true # Do reorder import and extern crate statements alphabetically for readability.
reorder_modules = true # Do reorder mod declarations alphabetically for readability.
tab_spaces = 2 # Use 2 spaces for indentation (Rust default is 4).
unstable_features = false # Do not use unstable rustfmt features.
use_small_heuristics = "Max" # Set all granular width settings to the same as max_width (do not use heuristics)
wrap_comments = false # Leave comment formatting to author's discretion

0 comments on commit cb212da

Please sign in to comment.