Skip to content

Commit

Permalink
rename profile.dev to profile.dev-opt
Browse files Browse the repository at this point in the history
Binary size is not critical for tools so we can only set optimizations for
debug build of `td-shim` and `td-payload`.

By renaming the `profile.dev`, we can use the `dev-opt` profile for required
packages and use the default `dev` profile for others.

Signed-off-by: Jiaqi Gao <[email protected]>
  • Loading branch information
gaojiaqi7 authored and jyao1 committed Sep 15, 2023
1 parent 815152a commit 5b682ca
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ kbuild = "build --target x86_64-custom.json -Zbuild-std=core -Zbuild-std-feature
kimage = "run --target x86_64-custom.json -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem -- --no-run"
krun = "run --target x86_64-custom.json -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem"
ktest = "xtest --target x86_64-custom.json"
xtask = "run -p xtask --release --"
xtask = "run -p xtask --"
image = "xtask image"
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ members = [
"xtask",
]

# the profile used for `cargo build`
[profile.dev]
# the profile used for debug build of `td-shim` and `td-payload`
[profile.dev-opt]
inherits = "dev"
panic = "abort" # disable stack unwinding on panic
opt-level = "z"
lto = true
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ cargo xbuild -p td-payload --target x86_64-unknown-none --release --bin example
cargo run -p td-shim-tools --bin td-shim-ld -- target/x86_64-unknown-none/release/ResetVector.bin target/x86_64-unknown-none/release/td-shim -t executable -p target/x86_64-unknown-none/release/example -o target/release/final-elf.bin
```

To build the debug TdShim, please use `dev-opt` profile to build `td-shim` binary. For example:

```
cargo xbuild -p td-shim --target x86_64-unknown-none --profile dev-opt --features=main,tdx
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/dev-opt/ResetVector.bin target/x86_64-unknown-none/dev-opt/td-shim -o target/debug/final.bin
```

## Run
REF: https://github.com/tianocore/edk2-staging/tree/TDVF

Expand Down
11 changes: 8 additions & 3 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lazy_static! {
Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
static ref SHIM_OUTPUT: PathBuf = PROJECT_ROOT.join("target/x86_64-unknown-none/");
static ref IMAGE_OUTPUT: PathBuf = PROJECT_ROOT.join("target/release/final.bin");
static ref IMAGE_OUTPUT_DEBUG: PathBuf = PROJECT_ROOT.join("target/debug/final.bin");
static ref METADATA: PathBuf = PROJECT_ROOT.join("td-shim-tools/etc/metadata.json");
}

Expand Down Expand Up @@ -227,15 +228,15 @@ impl BuildArgs {
if self.release {
"release"
} else {
"dev"
"dev-opt"
}
}

fn profile_path(&self) -> &str {
if self.release {
"release"
} else {
"debug"
"dev-opt"
}
}

Expand All @@ -255,7 +256,11 @@ impl BuildArgs {
}

fn output(&self) -> Result<PathBuf> {
let path = self.output.as_ref().unwrap_or(&IMAGE_OUTPUT);
let path = self.output.as_ref().unwrap_or(if self.release {
&IMAGE_OUTPUT
} else {
&IMAGE_OUTPUT_DEBUG
});

// Get the absolute path of the target file
let absolute = if path.is_absolute() {
Expand Down

0 comments on commit 5b682ca

Please sign in to comment.