Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions platform-tools-sdk/cargo-build-sbf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct Config<'a> {
jobs: Option<String>,
arch: &'a str,
optimize_size: bool,
lto: bool,
}

impl Default for Config<'_> {
Expand Down Expand Up @@ -78,6 +79,7 @@ impl Default for Config<'_> {
jobs: None,
arch: "v0",
optimize_size: false,
lto: false,
Comment thread
illia-bobyr marked this conversation as resolved.
}
}
}
Expand Down Expand Up @@ -553,6 +555,12 @@ fn invoke_cargo(config: &Config) {
if config.optimize_size {
target_rustflags = Cow::Owned(format!("{} -C opt-level=s", &target_rustflags));
}
if config.lto {
target_rustflags = Cow::Owned(format!(
"{} -C embed-bitcode=yes -C lto=fat",
&target_rustflags
));
}
if config.debug {
// Replace with -Zsplit-debuginfo=packed when stabilized.
target_rustflags = Cow::Owned(format!("{} -g", &target_rustflags));
Expand Down Expand Up @@ -878,6 +886,14 @@ fn main() {
.takes_value(false)
.help("Optimize program for size. This option may reduce program size, potentially increasing CU consumption.")
)
.arg(
Arg::new("lto")
.long("lto")
.takes_value(false)
.help("Enable Link-Time Optimization (LTO) for all crates being built. \
This option may decrease program size and CU consumption. The default option is LTO \
disabled, as one may get mixed results with it.")
)
.get_matches_from(args);

let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk");
Expand Down Expand Up @@ -948,6 +964,7 @@ fn main() {
jobs: matches.value_of_t("jobs").ok(),
arch: matches.value_of("arch").unwrap(),
optimize_size: matches.is_present("optimize_size"),
lto: matches.is_present("lto"),
};
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
if config.verbose {
Expand Down
2 changes: 1 addition & 1 deletion platform-tools-sdk/cargo-build-sbf/tests/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn test_out_dir() {
#[serial]
fn test_target_dir() {
let target_dir = "./temp-target-dir";
run_cargo_build("noop", &["--", "--target-dir", target_dir], false);
run_cargo_build("noop", &["--lto", "--", "--target-dir", target_dir], false);
let cwd = env::current_dir().expect("Unable to get current working directory");
let normal_target_dir = cwd.join("tests").join("crates").join("noop").join("target");
assert!(!normal_target_dir.exists());
Expand Down
Loading